【问题标题】:Start process automatically at reboot on EC2 linux (CentOS)在 EC2 linux (CentOS) 上重新启动时自动启动进程
【发布时间】:2017-06-01 06:53:44
【问题描述】:

我想确保 Web 服务在我的 AWS EC2 Linux 机器重新启动时自动启动。

要手动启动该过程,我需要输入以下命令:

sudo su
cd /root/notebooks
nohup jupyter notebook &

我按照下面的方法编辑了 /etc/rc.local,但是这个过程永远不会开始。有什么想法吗?

#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

sudo su

cd /root/notebooks

nohup jupyter notebook &

touch /var/lock/subsys/local

【问题讨论】:

    标签: linux amazon-web-services amazon-ec2 centos


    【解决方案1】:

    回答考虑到 Ubuntu 操作系统, 最简单和最好的解决方案(虽然这样它即使在服务器停止时也会运行,但这不是问题):

    1. 转到 /etc/init.d
    2. 在该目录中创建一个bash脚本(使用vim script不要给出扩展名)并输入如下内容:
    sudo su
    cd /root/notebooks
    nohup jupyter notebook &
    

    现在,在该目录本身内,运行以下命令:

    chmod +x script
    update-rc script defaults
    

    你已经完成了。 如果您使用的是 16.04 ubuntu,请使用 update-rc.d。

    【讨论】:

    • @Arturo 按照我告诉你的那样在 init.d 中创建脚本,然后运行“chkconfig --level 345 scriptname on”