ubuntu自定义服务自动启动
自定义服务
在路径 /etc/systemd/system/ 下 定义example.service
[Unit]
Description=My Custom Script[Service]
ExecStart=/root/exe_start.sh
Type=oneshot
RemainAfterExit=yes[Install]
WantedBy=multi-user.target
在/root/ 路径下执行
vi exe_start.sh
cd /root/mes_server/
nohup python3 manage.py runserver 0:50009 &
可以在exe_start.sh中继续追加其他命令
手动测试
sudo systemctl start example.service
访问对应的服务是否启动成功,如果没有启动,查看日志
sudo systemctl status example.service
设置开机启动
sudo systemctl enable example.service
查看是否设置成功
sudo systemctl is-enabled example.service