参考文章:https://www.cnblogs.com/airdot/p/9688530.html
# 版本 ubuntu18 python3.6 django2.2
# cat /etc/systemd/system/rc-local.service
[Unit]
Description=/etc/rc.local Compatibility
ConditionPathExists=/etc/rc.local
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99
[Install]
WantedBy=multi-user.target
# cat /etc/rc.local
#!/bin/sh -e
#
# 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 "看到这行字,说明添加自启动脚本成功。" > /root/test.log
a=`lsof -i:8000 | wc -l`
if [ "$a" -eq "0" ];then
echo "start nohup django:8000" >> /root/test.log
nohup /root/code/django_env/bin/python3 /root/code/cmdb_mysql/manage.py runserver 0.0.0.0:8000 > cmdb.log 2>&1 &
else
echo "8000 端口被占用" >> /root/test.log
fi
#source /root/code/cmdb_mysql/django_env/bin/activate
#nohup /root/code/django_env/bin/python3 /root/code/cmdb_mysql/manage.py runserver 0.0.0.0:8000 > cmdb.log 2>&1 &
echo "看到这行字,说明django.sh执行过。" >> /root/test.log
exit 0
# 记得给rc.local执行权限 然后就可以曲线救国实现开机启动某个脚本和项目了
chmod +x /etc/rc.local
systemctl enable rc-local
systemctl start rc-local.service
systemctl status rc-local.service

1万+

被折叠的 条评论
为什么被折叠?



