#!/bin/bash # Nginx chroot startup script # chkconfig: 345 90 90 # Description: Nginx Chroot init script PID=`pidof -o %PPID -x /opt/nginx_jail/sbin/nginx` start() { if [[ -z $PID ]]; then /usr/sbin/chroot /opt/nginx_jail /usr/sbin/nginx; echo "Starting Nginx jail."; else echo "PID Error ($PID): Nginx jail is currently running."; fi } stop() { if [[ -n $PID ]]; then /usr/sbin/chroot /opt/nginx_jail /usr/sbin/nginx -s quit; echo "Stopping Nginx jail."; PID=`pidof -o %PPID -x /opt/nginx_jail/sbin/nginx` else echo "Error: Nginx jail is currently not running."; fi } reload(){ if [[ -n $PID ]]; then /usr/sbin/chroot /opt/nginx_jail /usr/sbin/nginx -s reload; echo "Reload done."; else echo "Error: Nginx jail is currently not running."; fi } status(){ if [[ -n $PID ]]; then echo "Nginx jail is currently running, PIDs: $PID"; else echo "Nginx jail is currently not running."; fi } restart(){ if [[ -n $PID ]]; then /usr/sbin/chroot /opt/nginx_jail /usr/sbin/nginx -s stop; echo "Stopping Nginx jail."; PID=`pidof -o %PPID -x /opt/nginx_jail/sbin/nginx`; else echo "Error: Nginx jail is currently not running."; fi sleep 2; start } case "$1" in start) start ;; stop) stop ;; reload) reload ;; status) status ;; restart) restart ;; *) echo "Usage: $0 {start|stop|restart|reload|status}" esac exit 0