一、將自己程序設置爲服務
1. 首先在/lib/systemd/system/目錄下,創建服務腳本:nginx-1.13.0.service
[Unit]
Description=nginx-1.13.0
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/nginx-1.13.0/sbin/nginx -c /usr/local/nginx-1.13.0/conf/nginx.conf
ExecStop=/usr/local/nginx-1.13.0/sbin/nginx -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
2. 設置讓腳本開機自動啓動
sudo systemctl enable nginx-1.13.0.service
3、常用命令
重新加載service文件:systemctl daemon-reload
啓動一個服務:systemctl start nginx-1.13.0.service
關閉一個服務:systemctl stop nginx-1.13.0.service
重啓一個服務:systemctl restart nginx-1.13.0.service
顯示一個服務的狀態:systemctl status nginx-1.13.0.service
在開機時啓用一個服務:systemctl enable nginx-1.13.0.service
在開機時禁用一個服務:systemctl disable nginx-1.13.0.service
查看服務是否開機啓動:systemctl is-enabled nginx-1.13.0.service
查看已啓動的服務列表:systemctl list-unit-files|grep enabled
查看啓動失敗的服務列表:systemctl --failed
禁用服務:systemctl mask nginx-1.13.0.service
解禁服務:systemctl unmask nginx-1.13.0.service
二、管理工具
sudo apt-get install sysv-rc-conf ,這個命令啓動後,界面如下: