编译安装的nginx默认是无法使用service nginx start
或者systemctl start nginx
管理进程
为了方便使用,有时候需要自己编写启动脚本
vi /etc/init.d/nginx
写入以下内容:
#!/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
#以上内容根据实际内容填写
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
网友评论