Get the App
SLTechnology News&Howtos  ›  Servers  › 

Shell script applies "four" Nginx service start-stop reload script

Shulou Source: shulou.com Published: 2022-06-03 05:38:48 09月16日 Update

Nginx service startup stop reload script known Nginx management commands are: start: / application/nginx/sbin/nginx stop: / application/nginx/sbin/nginx-s stop reload: / application/nginx/sbin/nginx-s reload Please use case script to simulate Nginx startup shutdown / etc/init.d/nginx {start | stop | restart | reload} and can be managed through chkonfig

Script:

#

# nginx startup script

# 2018-11-29

#

#! / bin/bash

# calling system functions and custom variables

[- f / etc/init.d/functions] & &. / etc/init.d/functions

Pidfile=/application/nginx/logs/nginx.pid

# shared functions

Publics () {

RETVAL=$?

If [$RETVAL-eq 0]; then

Action "Nginx is $1" / bin/true

Else

Actio "Nginx is $1" / bin/false

Fi

}

# launch function start

Start () {

If [- f $Pidfile]; then

Echo "Nginx is running"

Else

/ application/nginx/sbin/nginx

Publics Started

Fi

Return $RETVAL

}

# turn off function stop

Stop () {

If [!-f $Pidfile]; then

Echo "Nginx is not runing"

Else

/ application/nginx/sbin/nginx-s stop

Publics Stopped

Fi

Return $RETVAL

}

# reload the function reload

Reload () {

If [!-f $Pidfile]; then

Echo "Can't open $Pidfile, no such file directory"

Else

/ application/nginx/sbin/nginx-s reload

Publics Reload

Fi

Return $RETVAL

}

# case statement using selection

Case "$1" in

Start)

Start

RETVAL=$?

Stop)

Stop

RETVAL=$?

Reload)

Reload

RETVAL=$?

Restart)

Stop

Sleep 2

Start

RETVAL=$?

*)

Echo "USAGE:$0 {satrt | stop | restart | reload}"

Exit 1

Esac

Tags: Functions scripts management services variables commands systems statements accessibility selection application Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Shulou Technology Microsoft Linux macOS