nginx控制脚本
#!/bin/bash
. /etc/init.d/functions
args=$1
fun(){
[ $? -eq 0 ] && action "Nginx $args is " /bin/true || echo "Nginx $args is " /bin/false
}
case $1 in
start)
netstat -lntup|grep ":80\b" &>/dev/null
if [ $? -eq 0 ];then
echo "Nginx is runing..."
else
/usr/local/nginx/sbin/nginx #nginx命令的路径
fun
fi
;;
stop)
/usr/local/nginx/sbin/nginx -s stop
fun
;;
reload)
/usr/local/nginx/sbin/nginx -s reload
fun
;;
restart)
netstat -lntup|grep ":80\b" &>/dev/null
if [ $? -ne 0 ];then
/usr/local/nginx/sbin/nginx
[ $? -eq 0 ] && echo "Nginx start is ok" || echo "Nginx start is failed"
else
/usr/local/nginx/sbin/nginx -s stop
[ $? -eq 0 ] && echo "Nginx stop is ok" || echo "Nginx stop is failed"
sleep 2
/usr/local/nginx/sbin/nginx
fun
fi
;;
status)
netstat -lntup|grep ":80\b" &>/dev/null
if [ $? -eq 0 ];then
echo "Nginx is runing ..."
else
echo "Nginx is not runing ..."
fi
;;
*)
echo "Usage: $0 {start|stop|status|restart|reload}"
exit 2
esac
systemctl管理脚本
[Unit]
Description=Nginx server daemon
[Service]
Type=forking
ExecStart=/scripts/nginx.sh start
ExecStop=/scripts/nginx.sh stop
ExecReload=/scripts/nginx.sh reload
ExecRestart=/scripts/nginx.sh restart
Execstatus=/scripts/nginx.sh status
PrivateTmp=true
[Install]
WantedBy=multi-user.target
放到/usr/lib/systemd/system/目录
754权限
systemctl daemon-reload重新加载
搬运记录