Skip to content

Instantly share code, notes, and snippets.

@caramelchocolate
Created July 20, 2019 06:40
Show Gist options
  • Save caramelchocolate/bb02e0c86c8b878628053481060fa9dd to your computer and use it in GitHub Desktop.
Save caramelchocolate/bb02e0c86c8b878628053481060fa9dd to your computer and use it in GitHub Desktop.
特定のnginx.confを読み込み、start|restart|stopをする場合に使用するラッパー。
#!/bin/sh
# nginx.conf の pid /path/nginx.pid; の調整は必要。
args=${1:-""}
case "${args}" in
stop)
echo 'stop';
;;
restart)
echo 'restart'
action_type=start
;;
start)
echo 'start'
action_type=start
;;
*)
echo "none args..."
exit 1
esac
pid_file="nginx.pid"
if [ -e ${pid_file} ] ; then
pid=`cat ${pid_file}`
ps -p ${pid} >/dev/null
if [ $? -eq 0 ] ; then
echo "kill process ${pid}"
sudo kill ${pid}
fi
fi
if [ "${action_type}" = start ]; then
echo 'start...';
sudo /path/nginx -c /path/nginx.conf
fi
@caramelchocolate
Copy link
Author

caramelchocolate commented Jul 20, 2019

how to use

(1) nginx start
$ sh main.sh start

(2) nginx start
$ sh main.sh restart

(3) nginx stop
$ sh main.sh stop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment