使用systemctl進行服務管理

王營90發表於2020-10-26

以nginx為例

  • 操作命令
# 新增一個.service檔案
vim /usr/lib/systemd/system/nginx.service
# 過載系統服務
systemctl daemon-reload	
  • nginx.service檔案內容
[Unit] # 服務描述
Description=The nginx HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service] # 服務命令
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
# systemctl startPre nginx
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
# systemctl start nginx
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
# systemctl reload nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
# systemctl stop nginx
ExecStop=/usr/local/nginx/sbin/nginx -s stop
# systemctl quit nginx
ExecQuit=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true

[Install]
WantedBy=multi-user.target	

相關文章