編譯安裝的nginx默認(rèn)是無法使用service nginx start
或者systemctl start nginx管理進(jìn)程
為了方便使用,有時候需要自己編寫啟動腳本
vi /etc/init.d/nginx 寫入以下內(nèi)容:
#!/bin/bash
# wobuchimangguo
# chkconfig: - 85 15 這一行必須要
# description: nginx init tools 這一行必須要
conf=/opt/nginx/conf/nginx.conf
bin=/opt/nginx/sbin/nginx
pid=/opt/nginx/logs/nginx.pid
#以上內(nèi)容根據(jù)實(shí)際內(nèi)容填寫
SHOW () {
if [ $? -eq 0 ];then
echo -en "$1 [\e[1;32mOK\e[0m]";echo
else
echo -en "$1 [\e[1;31mFAIL\e[0m]";echo
fi
}
START () {
if [ -f $pid ];then
echo "Nginx is running,please use [stop|restart|reload|status]"
else
$bin && SHOW 'Start nginx'
fi
}
STOP () {
if [ -f $pid ];then
kill `cat $pid` && SHOW 'Stop nginx'
else
echo "Nginx is not running,please use [start|restart|status]"
fi
}
RESTART () {
kill `cat $pid` && SHOW 'Stop nginx'
$bin && SHOW 'Start nginx'
}
RELOAD () {
if [ -f $pid ];then
$bin -s reload && SHOW 'Reload nginx'
else
echo "Nginx is not running,please use [start|status]"
fi
}
STATUS () {
if [ -f $pid ];then
echo -en "Nginx is \e[1;32mrunning\e[0m";echo
else
echo -en "Nginx is \e[1;31mdeal\e[0m";echo
fi
}
case $1 in
start) START;;
stop) STOP;;
restart) RESTART;;
reload) RELOAD;;
status) STATUS;;
*)
echo "Please use [start|stop|restart|reload|status]" && exit 1
;;
esac
填寫完畢以后
chmod +x /etc/init.d/nginx
chkconfig --add /etc/init.d/nginx
chkconfig nginx on
完畢!試試命令service nginx status或者systemctl status nginx