Initial commit
This commit is contained in:
132
nginx/rc.nginx
Normal file
132
nginx/rc.nginx
Normal file
@@ -0,0 +1,132 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Nginx daemon control script.
|
||||
# Written for Slackware Linux by Cherife Li <cherife-#-dotimes.com>.
|
||||
# Updated by Sergei Fedosoff <eleksir@gmail.com>
|
||||
|
||||
BIN=/usr/sbin/nginx
|
||||
CONF=/etc/nginx/nginx.conf
|
||||
PID=/run/nginx.pid
|
||||
LOGDIR=/var/log/nginx
|
||||
VARDIR=/var/lib/nginx
|
||||
USER=apache
|
||||
|
||||
nginx_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 "Nginx appears to already be running?"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -d $LOGDIR ]; then
|
||||
chmod -R $USER $LOGDIR
|
||||
else
|
||||
install -dm 0755 -o $USER $LOGDIR
|
||||
fi
|
||||
|
||||
if [ -d $VARDIR ]; then
|
||||
chown -R $USER $VARDIR
|
||||
else
|
||||
install -dm 0755 -o $USER $VARDIR
|
||||
fi
|
||||
|
||||
echo "Starting Nginx server daemon..."
|
||||
if [ -x $BIN ]; then
|
||||
$BIN -c $CONF
|
||||
fi
|
||||
}
|
||||
|
||||
nginx_test_conf() {
|
||||
echo "Checking configuration for correct syntax and"
|
||||
echo "then trying to open files referenced in configuration..."
|
||||
$BIN -t -c $CONF
|
||||
}
|
||||
|
||||
nginx_term() {
|
||||
echo "Shutdown Nginx quickly..."
|
||||
kill -TERM $(cat $PID)
|
||||
}
|
||||
|
||||
nginx_stop() {
|
||||
echo "Shutdown Nginx gracefully..."
|
||||
if [ -x $BIN ]; then
|
||||
$BIN -s quit
|
||||
else
|
||||
kill -QUIT $(cat $PID) 2 >/dev/null
|
||||
fi
|
||||
}
|
||||
|
||||
nginx_reload() {
|
||||
echo "Reloading Nginx configuration..."
|
||||
if [ -x $BIN ]; then
|
||||
$BIN -s reload
|
||||
else
|
||||
kill -HUP $(cat $PID)
|
||||
fi
|
||||
}
|
||||
|
||||
nginx_upgrade() {
|
||||
echo "Upgrading to the new Nginx binary."
|
||||
echo "Make sure the Nginx binary has been replaced with new one"
|
||||
echo "or Nginx server modules were added/removed."
|
||||
kill -USR2 $(cat $PID)
|
||||
sleep 3
|
||||
kill -QUIT $(cat $PID.oldbin)
|
||||
}
|
||||
|
||||
nginx_rotate() {
|
||||
echo "Rotating Nginx logs..."
|
||||
if [ -x $BIN ]; then
|
||||
$BIN -s reopen
|
||||
else
|
||||
kill -USR1 $(cat $PID)
|
||||
fi
|
||||
}
|
||||
|
||||
nginx_restart() {
|
||||
nginx_stop
|
||||
for i in 1 2 3; do
|
||||
if [ -e $PID ]; then
|
||||
/usr/bin/echo -n "."
|
||||
sleep 1
|
||||
else
|
||||
break
|
||||
fi
|
||||
done
|
||||
echo
|
||||
nginx_start
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
check)
|
||||
nginx_test_conf
|
||||
;;
|
||||
start)
|
||||
nginx_start
|
||||
;;
|
||||
term)
|
||||
nginx_term
|
||||
;;
|
||||
stop)
|
||||
nginx_stop
|
||||
;;
|
||||
reload)
|
||||
nginx_reload
|
||||
;;
|
||||
restart)
|
||||
nginx_restart
|
||||
;;
|
||||
upgrade)
|
||||
nginx_upgrade
|
||||
;;
|
||||
rotate)
|
||||
nginx_rotate
|
||||
;;
|
||||
*)
|
||||
echo "usage: `basename $0` {check|start|term|stop|reload|restart|upgrade|rotate}"
|
||||
esac
|
||||
Reference in New Issue
Block a user