linux service服务自启动

1、创建servce文件

sudo vim /lib/systemd/system/【yourservice_name】.service

2、写入内容

[Unit]
Description=Test Service
After=multi-user.target

[Service]
Type=idle
ExecStart=/usr/bin/python /home/snail/autorun.py

[Install]
WantedBy=multi-user.target

3、重定向到文件

ExecStart=/usr/bin/python /home/snail/autorun.py > /home/snail/autorun.log 2>&1
###   指向虚无  /dev/null

4、更改配置文件权限

sudo chmod 644 /lib/systemd/system/autorun.service

5、reload and enable

 sudo systemctl daemon-reload
 sudo systemctl enable autorun.service###使服务开机自启动

6、查看服务状态

sudo systemctl status autorun.service

你可能感兴趣的:(linux service服务自启动)