在linux 上用系统命令systemctl 执行python脚本

首先编写好自己的python脚本

然后执行命令vi xxxx.service

输入以下内容

[Unit]

Description = xxxx  #描述#

After = network.target

[Service]

ExecStart = /usr/bin/python -u python脚本名

WorkingDirectory = /home  #脚本所在目录#

StandardOutput = inherit

StandardError = inherit

Restart = always

User = pi  #系统登录用户名#

[Install]

WantedBy=multi-user.target

 

然后把 xxx.service 复制到 /etc/systemd/system/

sudo cp xxx.service /etc/systemd/system/xxx.service

最后

启动该服务 sudo systemctl start xxx.service

停止该服务sudo systemctl stop xxx.service

查看运行状态sudo systemctl status xxx.service

设置开机运行 sudo systemctl enable xxx.service

posted @ 2019-12-26 15:39  赵伟航  阅读(2652)  评论(0编辑  收藏  举报