python 程序开机自启动,亲测可用
生活随笔
收集整理的這篇文章主要介紹了
python 程序开机自启动,亲测可用
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
我們公司的采用的谷歌的云機(jī)器,如果機(jī)器里由顯卡,那么這臺(tái)機(jī)器會(huì)每隔一段時(shí)間會(huì)重啟重啟后會(huì)導(dǎo)致任務(wù)掛掉,對(duì)于布置的在機(jī)器上的服務(wù)需要設(shè)置開(kāi)機(jī)自啟動(dòng)。
這個(gè)是開(kāi)機(jī)就啟動(dòng)python 程序
在 /lib/systemd/system/ 新建 glory.service文件
所有路徑都用絕對(duì)路徑
sudo vi /lib/systemd/system/glory.service [Unit] #這段是描述,隨便寫(xiě)寫(xiě) Description=start_rule_mafia1_agent[Service] # 你的Ubuntu 用戶名稱 User=game #你的用戶分組默認(rèn)與用戶名相同 Group=game #這段非常重要,op.sh 是你開(kāi)機(jī)要執(zhí)行的shell 腳本,全部用絕對(duì)路徑 ExecStart=/bin/bash /home/game/glory_btps1/AP/rec1/op.shExecStop=/bin/kill $MAINPID PrivateTmp=true[Install] WantedBy=multi-user.target下面就是寫(xiě)這個(gè)op.sh 腳本,用于啟動(dòng)一個(gè)叫op.py 的python 程序
vi op.sh #!/bin/bash path=$(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 文件夾讀寫(xiě)權(quán)限,這一步非常重要
sudo chmod 777 -R * sudo systemctl enable glory.service查看有無(wú)報(bào)錯(cuò)
sudo systemctl daemon-reload sudo systemctl status glory.service如果顯示不成功再執(zhí)行
sudo systemctl start glory.service sudo systemctl status glory.service總結(jié)
以上是生活随笔為你收集整理的python 程序开机自启动,亲测可用的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: tf.cond
- 下一篇: BP神经网络python代码详细解答(来