Ubuntu设置服务自启

1. 进入/etc/init.d目录下

cd /etc/init.d

2.创建启动脚本run_script.sh

touch run_script.sh

3.编辑文件,保存以下内容

vi run_script.sh

#!/bin/sh

### BEGIN INIT INFO
# Provides:    gw
# Required-Start:    $remote_fs $syslog
# Required-Stop:    $remote_fs $syslog
# Default-Start:    2 3 4 5
# Default-Stop:    0 1 6
# Short-Description:    run script
# Description:    run script when starting up
### END INIT INFO

## 长城塬节灌启动开始
# uwsgi启动
uwsgi --ini /mnt/project/changchengyuan/03Development/lot_irrigated_changchengyuan_v3/lot_irrigated_changchengyuan_v3_uwsgi.ini
# nginx启动
nginx -c /mnt/project/changchengyuan/03Development/lot_irrigated_changchengyuan_v3/lot_irrigated_changchengyuan_v3_nginx.conf
# dbq启动
nohup python /mnt/project/changchengyuan/03Development/lot_irrigated_changchengyuan_v3/bus_dbq_consumer_main.py >/dev/null 2>&1 &
# alarmq启动
nohup python /mnt/project/changchengyuan/03Development/lot_irrigated_changchengyuan_v3/bus_alarmq_consumer_main.py >/dev/null 2>&1 &
# worker启动
nohup python /mnt/project/changchengyuan/03Development/lot_irrigated_changchengyuan_v3/manage.py celery worker -c 4 --loglevel=info >/dev/null 2>&1 &
# beat启动
nohup python /mnt/project/changchengyuan/03Development/lot_irrigated_changchengyuan_v3/manage.py celery beat >/dev/null 2>&1 &
## 长城塬节灌启动结束

exit 0

4.设置权限

sudo chmod 755 run_script.sh

5.添加启动脚本,在这里90表明一个优先级,越高表示执行的越晚,一般在90以后

sudo update-rc.d run_script.sh defaults 90

6.移除启动脚本

sudo update-rc.d -f run_script.sh remove

你可能感兴趣的:(Ubuntu,ubuntu,shell,linux)