2016년 6월 29일 수요일

uWSGI init.d 스크립트 | uWSGI init.d Script

#!/bin/bash
# chkconfig: 2345 80 20

. /etc/rc.d/init.d/functions

UWSGI='/opt/pyenv/shims/uwsgi'
OPTION='/etc/uwsgi/uwsgi.ini'

[ -f $UWSGI ] || exit 1
[ -f $OPTION ] || exit 1

RETVAL=0

start() {
  echo -n 'Starting uwsgi: '
  daemon "$UWSGI --ini $OPTION &> /dev/null &"
  RETVAL=$?
  echo
  return $RETVAL
}

stop() {
  echo -n 'Stopping uwsgi: '
  killproc $UWSGI
  RETVAL=$?
  echo
  return $RETVAL
}

status() {
  PGREP="$(ps aux | grep uwsgi | grep www-data | awk '{print $2}' | sed -n 1p)"
  if [ -z $PGREP ]; then
    echo 'uwsgi is stopped...';
  else
    echo "uwsgi is running... (pid: $PGREP)";
  fi
}

case "$1" in
  start)
    start
    ;;

  stop)
    stop
    ;;

  status)
    status
    ;;

  restart)
    stop
    start
    ;;
esac

exit $REVAL

See source code in Gist

댓글 없음:

댓글 쓰기