1.创建.service文件放到 /etc/systemd/system目录下。 例:edgePython.service.文件内容为:
[Unit]
Description=edgePythonService
[Service]
Type=simple
User=root
Group=root
#设置应用的工作目录
WorkingDirectory=/root
ExecStart=/usr/bin/python /root/esms/py/run.py
Restart=always
ExecStop=/bin/kill -s TERM $MAINPID
[Install]
WantedBy=multi-user.target
配置上文中的ExecStart
/usr/bin/python 路径为python根目录
/root/esms/py/run.py 路径为自建的python服务程序。
2.将.service文件放到/etc/systemd/system目录下后(或在此目录下直接创建),执行:
(1) 重载系统服务:
systemctl daemon-reload
(2)启动/停止/查看python服务:
systemctl start edgePython.service
systemctl stop edgePython.service
systemctl status edgePython.service
(3)设置开机启动
systemctl enable edgePython.service