无法让系统在重启时运行 rc.local

无法让系统在重启时运行 rc.local

我已经在 AWS EC2 上运行了 Ubuntu Server 16.0.4 实例,我想确保每次重新启动实例或重新启动 ubuntu 时都会执行脚本。我在网上搜索了一下,似乎很容易 - 只需更改/etc/rc.local就可以了。我已经这样做了,但不行。

/etc/rc.local文件 - 删除了 -e#!/bin/sh并且只有一行执行脚本(编辑)

    #!/bin/sh
    #
    # rc.local
    #
    # This script is executed at the end of each multiuser runlevel.
    # Make sure that the script will "exit 0" on success or any other
    # value on error.
    #
    # In order to enable or disable this script just change the execution
    # bits.
    #
    # By default this script does nothing.

    echo RC_LOCAL
    sh /home/ubuntu/scripts/boot.sh

    exit 0

权限:-rwxr-xr-x 1 root root 339 Nov 7 10:04 rc.local

和我的boot.sh文件:

#!/bin/sh

echo SYSTEM_BOOT

~/xxx/xxx/xxx console &
sudo ./xxx/xxx/xxx.sh

权限:-rwxrwxr-x 1 ubuntu ubuntu 92 Nov 7 09:17 boot.sh

奇怪的是,我可以运行/etc/rc.local并被boot.sh调用,一切都像我想要的那样,但是当我sudo reboot下次运行并通过 SSH 连接到 AWS 时它并没有执行。

编辑:sudo reboot使用 ssh 连接后, 我得到:➜ AWS ssh -i key.pem [email protected]

`Welcome to Ubuntu 16.04.2 LTS (GNU/Linux 4.4.0-1039-aws x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  Get cloud support with Ubuntu Advantage Cloud Guest:
    http://www.ubuntu.com/business/services/cloud

62 packages can be updated.
0 updates are security updates.


Last login: Tue Nov  7 10:22:38 2017 from 157.25.99.66`

ubuntu@ip-xx-xx-xx-xx:~$ 

相关内容