97 lines
1.8 KiB
Bash
97 lines
1.8 KiB
Bash
#!/bin/sh
|
|
#
|
|
# Openresty daemon control script.
|
|
# Written for Slackware Linux by Cherife Li <cherife-#-dotimes.com>.
|
|
|
|
BIN=/usr/bin/openresty
|
|
CONF=/etc/openresty/nginx.conf
|
|
PID=/var/run/openresty.pid
|
|
|
|
openresty_start() {
|
|
# Sanity checks.
|
|
if [ ! -r $CONF ]; then # no config file, exit:
|
|
echo "$CONF does not appear to exist. Abort."
|
|
exit 1
|
|
fi
|
|
|
|
if [ -s $PID ]; then
|
|
echo "Openresty appears to already be running?"
|
|
exit 1
|
|
fi
|
|
|
|
echo "Starting Openresty server daemon..."
|
|
if [ -x $BIN ]; then
|
|
$BIN -c $CONF
|
|
fi
|
|
}
|
|
|
|
openresty_test_conf() {
|
|
echo "Checking configuration for correct syntax and"
|
|
echo "then trying to open files referenced in configuration..."
|
|
$BIN -t -c $CONF
|
|
}
|
|
|
|
openresty_term() {
|
|
echo "Shutdown Openresty quickly..."
|
|
kill -TERM $(cat $PID)
|
|
}
|
|
|
|
openresty_stop() {
|
|
echo "Shutdown Openresty gracefully..."
|
|
kill -QUIT $(cat $PID)
|
|
}
|
|
|
|
openresty_reload() {
|
|
echo "Reloading Openresty configuration..."
|
|
kill -HUP $(cat $PID)
|
|
}
|
|
|
|
openresty_upgrade() {
|
|
echo "Upgrading to the new Openresty binary."
|
|
echo "Make sure the Openresty binary has been replaced with new one"
|
|
echo "or Openresty server modules were added/removed."
|
|
kill -USR2 $(cat $PID)
|
|
sleep 3
|
|
kill -QUIT $(cat $PID.oldbin)
|
|
}
|
|
|
|
openresty_rotate() {
|
|
echo "Rotating Openresty logs..."
|
|
kill -USR1 $(cat $PID)
|
|
}
|
|
|
|
openresty_restart() {
|
|
openresty_stop
|
|
sleep 3
|
|
openresty_start
|
|
}
|
|
|
|
case "$1" in
|
|
check)
|
|
openresty_test_conf
|
|
;;
|
|
start)
|
|
openresty_start
|
|
;;
|
|
term)
|
|
openresty_term
|
|
;;
|
|
stop)
|
|
openresty_stop
|
|
;;
|
|
reload)
|
|
openresty_reload
|
|
;;
|
|
restart)
|
|
openresty_restart
|
|
;;
|
|
upgrade)
|
|
openresty_upgrade
|
|
;;
|
|
rotate)
|
|
openresty_rotate
|
|
;;
|
|
*)
|
|
echo "usage: `basename $0` {check|start|term|stop|reload|restart|upgrade|rotate}"
|
|
esac
|