添加nginx服務到service的過程


一、問題描述

1、安裝完nginx后,無法使用service或systemctl命令管理nginx服務

 

二、問題分析

1、/etc/init.d/目錄下缺少nginx默認啟動腳本

 

三、在/etc/init.d/路徑下添加腳本文件,名稱為nginx,並添加文件可執行權限,如下:

 

 1 #!/bin/bash
 2 #Startup script for the nginx Web Server
 3 #chkconfig: 2345 85 15
 4 nginx=/usr/local/nginx/sbin/nginx
 5 conf=/usr/local/nginx/conf/nginx.conf
 6 case $1 in 
 7 start)
 8 echo -n "Starting Nginx"
 9 $nginx -c $conf
10 echo " done."
11 ;;
12 stop)
13 echo -n "Stopping Nginx"
14 killall -9 nginx
15 echo " done."
16 ;;
17 test)
18 $nginx -t -c $conf
19 echo "Success."
20 ;;
21 reload)
22 echo -n "Reloading Nginx"
23 ps auxww | grep nginx | grep master | awk '{print $2}' | xargs kill -HUP
24 echo " done."
25 ;;
26 restart)
27 $nginx -s reload
28 echo "reload done."
29 ;;
30 *)
31 echo "Usage: $0 {start|restart|reload|stop|test|show}"
32 ;;
33 esac

 

四、問題驗證

1、service命令

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM