在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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM