1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > python 程序开机自启动 亲测可用

python 程序开机自启动 亲测可用

时间:2022-11-23 14:17:31

相关推荐

python 程序开机自启动 亲测可用

我们公司的采用的谷歌的云机器,如果机器里由显卡,那么这台机器会每隔一段时间会重启重启后会导致任务挂掉,对于布置的在机器上的服务需要设置开机自启动。

这个是开机就启动python 程序

在/lib/systemd/system/新建glory.service文件

所有路径都用绝对路径

sudo vi /lib/systemd/system/glory.service

[Unit]#这段是描述,随便写写Description=start_rule_mafia1_agent[Service]# 你的Ubuntu 用户名称User=game#你的用户分组默认与用户名相同Group=game#这段非常重要,op.sh 是你开机要执行的shell 脚本,全部用绝对路径ExecStart=/bin/bash /home/game/glory_btps1/AP/rec1/op.shExecStop=/bin/kill $MAINPIDPrivateTmp=true[Install]WantedBy=multi-user.target

下面就是写这个op.sh 脚本,用于启动一个叫op.py 的python 程序

vi op.sh

#!/bin/bashpath=$(cd $(dirname $0);pwd)cd "$path"#/home/game/anaconda3/bin/python start-gate.py > p.log/home/game/anaconda3/bin/python schd.py > p1.log

赋予op.sh 文件夹读写权限,这一步非常重要

sudo chmod 777 -R *

sudo systemctl enable glory.service

查看有无报错

sudo systemctl daemon-reloadsudo systemctl status glory.service

如果显示不成功再执行

sudo systemctl start glory.servicesudo systemctl status glory.service

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。