Created
July 13, 2010 21:23
-
-
Save sax/474558 to your computer and use it in GitHub Desktop.
like apachectl, but for nginx
This file contains 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
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" | |
"http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>Label</key><string>nginx</string> | |
<key>Program</key><string>/usr/local/sbin/nginx</string> | |
<key>KeepAlive</key><true/> | |
<key>NetworkState</key><true/> | |
<key>StandardErrorPath</key><string>/var/log/nginx/error.log</string> | |
<key>LaunchOnlyOnce</key><true/> | |
</dict> | |
</plist> |
This file contains 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/sh | |
NGINX=/usr/local/sbin/nginx | |
LAUNCHCTL=/System/Library/LaunchDaemons/nginx.plist | |
find_nginx_pid(){ | |
echo `ps -ef | grep nginx | grep master | awk '{printf $2;}'`; | |
} | |
stop_nginx(){ | |
echo "Killing Nginx process" | |
kill -6 $(find_nginx_pid) | |
} | |
restart_nginx(){ | |
echo "Restarting Nginx process" | |
kill -HUP $(find_nginx_pid) | |
} | |
launch_nginx(){ | |
echo "Launching Nginx daemon" | |
launchctl load ${LAUNCHCTL} | |
} | |
start_nginx(){ | |
echo "Starting Nginx" | |
`${NGINX}` | |
} | |
check_nginx_running(){ | |
if [ "$(find_nginx_pid)" ]; then | |
return 0 | |
else | |
echo "Nginx is not currently running" | |
return 1 | |
fi | |
} | |
warn_already_running(){ | |
if [ "$(find_nginx_pid)" ]; then | |
echo "Nginx is already running" | |
return 0 | |
else | |
return 1 | |
fi | |
} | |
show_pid(){ | |
echo $(find_nginx_pid) | |
} | |
case $1 in | |
start) | |
warn_already_running || start_nginx | |
;; | |
stop) | |
check_nginx_running && stop_nginx | |
;; | |
restart) | |
check_nginx_running && restart_nginx | |
;; | |
launch) | |
warn_already_running || launch_nginx | |
;; | |
pid) | |
check_nginx_running && show_pid | |
;; | |
*) | |
echo "usage : [sudo] nginxctl [pid|start|stop|restart|launch]" | |
exit 1 | |
;; | |
esac | |
exit $? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment