美文网首页
使用Systemd设置自动运行Python脚本

使用Systemd设置自动运行Python脚本

作者: JM68 | 来源:发表于2019-10-16 17:53 被阅读0次

Python Script(jm68.py)

/usr/bin/jm68.py

import time

while true:
    with open('test.log','a+') as f:
        f.write(time.time)
        time.sleep(1)

Service Conf(jm68.service)

/lib/systemd/system/jm68.service

[Unit]
Description=QR Code Reader Service
After=multi-user.target
Conflicts=getty@tty1.service

[Service]
Type=simple
ExecStart=/usr/bin/python3 /usr/bin/jm68.py
StandardInput=tty-force

[Install]
WantedBy=multi-user.target

How to use

  1. sudo systemctl daemon-reload
  2. sudo systemctl enable jm68.service
  3. sudo systemctl start jm68.service

相关文章

网友评论

      本文标题:使用Systemd设置自动运行Python脚本

      本文链接:https://www.haomeiwen.com/subject/itbumctx.html