1.建立rc-local.service文件
sudo vi /etc/systemd/system/rc-local.service
内容如下:
[Unit]
Description=service
After=mysql #在这些服务后启动本服务
[Service]
Type=forking
User=xxxx
Restart=always
RestartSec=60
LimitNOFILE=65535
ExecStart=/home/xxxx/auto_service.sh
ExecReload=/home/xxxx/auto_service.sh
[Install]
WantedBy=multi-user.target
2.auto_service.sh启动脚本如下:
#!/bin/bash
cd /home/xxxx/workplaces/OKAI
nohup /home/xxxx/Documents/anaconda3/envs/py3/bin/python manage.py runserver -h 0.0.0.0 >log_server 2>&1 &
echo "service start"
注意可执行文件加上权限 :
sudo chmod +x auto_service.sh
3.开机自启设置
sudo systemctl enable rc-local.service
systemctl is-enabled rc-local.service # 查看启用状态
参考
https://blog.csdn.net/Bennett_Doris/article/details/108342630
https://www.cnblogs.com/mafeng/p/10316351.html