Centos 系統服務腳本目錄:
/usr/lib/systemd/
有系統(system)和使用者(user)之分,
如需要開機沒有登陸情況下就能運作的程式,存在系統服務(system)裡,即:
/lib/systemd/system/
反之,使用者登入後才能運作的程式,存在使用者(user)裡
服務以.service結尾。
這邊以nginx開機運作為例
[html] view plaincopyprint?
vim /lib/systemd/system/nginx.service
[plain] view plaincopyprint?
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/www/lanmps/init.d/nginx start
ExecReload=/www/lanmps/init.d/nginx restart
ExecStop=/www/lanmps/init.d/nginx stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
[Unit]:服務的說明
Description:描述服務
After:描述服務類别
[Service]服務運作參數的設定
Type=forking是背景運作的形式
ExecStart為服務的具體運作指令
ExecReload為重新開機指令
ExecStop為停止指令
PrivateTmp=True表示給服務配置設定獨立的臨時空間
注意:[Service]的啟動、重新開機、停止指令全部要求使用絕對路徑
[Install]服務安裝的相關設定,可設定為多使用者
以754的權限儲存在目錄:
/lib/systemd/system
systemctl enable nginx.service
任務
舊指令
新指令
使某服務自動啟動
chkconfig --level 3 httpd on
systemctl enable httpd.service
使某服務不自動啟動
chkconfig --level 3 httpd off
systemctl disable httpd.service
檢查服務狀态
service httpd status
systemctl status httpd.service (服務詳細資訊)
systemctl is-active httpd.service (僅顯示是否 Active)
顯示所有已啟動的服務
chkconfig --list
systemctl list-units --type=service
啟動某服務
service httpd start
systemctl start httpd.service
停止某服務
service httpd stop
systemctl stop httpd.service
重新開機某服務
service httpd restart
systemctl restart httpd.service
啟動nginx服務
設定開機自啟動
停止開機自啟動
檢視服務目前狀态
重新啟動服務
檢視所有已啟動的服務
本文轉自yzy121403725 51CTO部落格,原文連結:http://blog.51cto.com/lookingdream/1846507,如需轉載請自行聯系原作者