实现linux系统下开启自启动,且如果启动失败不会陷入死循环。/etc/init.d的方式虽然也可以实现,但是如果失败了就会开机失败。
所以在这里使用systemctl的方式创建自启动服务
1.新建服务
sudo nano /etc/systemd/system/npsc.service
2.编辑服务
[Unit]
Description=nps Client
After=network.target
Wants=network.target
[Service]
Type=oneshot
RemainAfterExit=yes
KillMode=none
ExecStart=/bin/nps start
ExecStop=exit
[Install]
WantedBy=multi-user.target
3.开机启动服务,启动服务
sudo systemctl enable npsc.service #开机自动运行
sudo systemctl start npsc.service #