systemctl管理nginx

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重新加载

搬运记录

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值