ubuntu18开机启动 python django项目 :使用 /etc/rc.local

 

参考文章: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

​

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值