Last active
January 19, 2018 11:57
-
-
Save ihor/3822929 to your computer and use it in GitHub Desktop.
/etc/init.d/nginx script for Homebrew installed Nginx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
DAEMON=/usr/local/sbin/nginx | |
NAME=nginx | |
DESC=nginx | |
test -x $DAEMON || exit 0 | |
set -e | |
test_config() { | |
if $DAEMON -t $DAEMON_OPTS >/dev/null 2>&1; then | |
return 0 | |
else | |
$DAEMON -t $DAEMON_OPTS | |
return $? | |
fi | |
} | |
start() | |
{ | |
test_config | |
# Check if the ULIMIT is set in /etc/default/nginx | |
if [ -n "$ULIMIT" ]; then | |
# Set the ulimits | |
ulimit $ULIMIT | |
fi | |
$DAEMON -g daemon | |
return | |
} | |
stop() | |
{ | |
$DAEMON -s stop | |
return | |
} | |
case "$1" in | |
start) | |
echo -n "Starting $DESC: " | |
start | |
echo "started." | |
;; | |
stop) | |
echo -n "Stopping $DESC: " | |
stop | |
echo "stopped." | |
;; | |
restart|force-reload) | |
echo -n "Restarting $DESC: " | |
stop | |
sleep 1 | |
start | |
echo "restarted." | |
;; | |
reload) | |
echo -n "Reloading $DESC configuration: " | |
test_config | |
kill -HUP `cat /usr/local/var/run/$NAME.pid` | |
echo "reloaded." | |
;; | |
configtest|testconfig) | |
echo -n "Testing $DESC configuration: " | |
if test_config; then | |
echo "config is ok." | |
else | |
exit $? | |
fi | |
;; | |
*) | |
echo "Usage: $0 {start|stop|restart|reload|force-reload|configtest}" >&2 | |
exit 1 | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment