1、 创建re-local.service文件
vim /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
2、配置启动文件
方法一:
创建rc.local文件:
vim /etc/rc.local
文件内容:
#!/bin/bash -e
# source /root/anaconda3/bin/activate flask_test
# source命令进行conda环境激活,需要使用绝对路径打开acvatie目录指定。
cd /root/flask_test
gunicorn -w 4 -b 127.0.0.1:8000 flask_test:app &
exit 0
给定权限:
chmod 777 /etc/rc.local
方法二:
创建rc.local文件:
vim /etc/rc.local
文件内容:
#!/bin/bash -e
bash /root/flask_test/flask_test.sh
exit 0
创建flask_test.sh文件:
vim /root/flask_test/flask_test.sh
文件内容:
#!/bin/bash
cd /root/flask_test
gunicorn -w 4 -b 127.0.0.1:8000 flask_test:app &
给定权限:
chmod 777 /etc/rc.local
chmod 777 /root/flask_test/flask_test.sh
3、设置开机启动
systemctl enable rc-local.service
4、立即启动
systemctl start rc-local.service
5、查看服务状态
systemctl status rc-local.service
成功状态:
如需停止服务:
systemctl stop rc-local.service
设置开机自启同时立即启动:
systemctl enable --now rc-local.service
————————————————
版权声明:本文为CSDN博主「limengshi138392」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/limengshi138392/article/details/121701328