#!/bin/sh

#
# chkconfig: 35 99 99
# description: For the puma app in <%= @working_dir %>

# load some init.d helper functions
. /etc/rc.d/init.d/functions

APPNAME="<%= @name %>"
APP_DIR="<%= @directory %>"

PUMA_DIR="$APP_DIR/shared/puma"
PIDFILE="$APP_DIR/shared/pids/$APPNAME.pid"
STARTUP="$PUMA_DIR/puma_start.sh"
cleanup() {
  rm -f $PUMA_DIR/$APPNAME*.{pid,state,sock}
}

start() {
  echo -n "Starting $APPNAME.."
  daemon --pidfile $PIDFILE $STARTUP && success || failure
}

stop() {
  echo -n "Shutting down $APPNAME.."
  killproc -p $PIDFILE puma && cleanup && success || failure
}

restart() {
  if [ -e $PIDFILE ]; then
    echo -n "Hot Restarting $APPNAME"
    killproc -p $PIDFILE puma -USR1 && success || failure
  else
    echo "$APPNAME isn't running.."
    start
  fi
}

case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  restart)
    restart
    ;;
  hard-restart)
    stop
    start
    ;;
  *)
    echo "Usage: $0 {start|stop|restart|hard-restart}"
    exit 2
esac

exit $?

# vim: set filetype=sh :

#!/bin/sh

#
# chkconfig: 35 99 99
# description: For the puma app in <%= @working_dir %>

# load some init.d helper functions
. /etc/rc.d/init.d/functions

APPNAME="<%= @name %>"
APP_DIR="<%= @directory %>"
USERNAME="<%= @owner %>"

PUMA_DIR="$APP_DIR/shared/puma"
PIDFILE="$APP_DIR/shared/pids/$APPNAME.pid"
START="$PUMA_DIR/puma_start.sh"
STOP="$PUMA_DIR/puma_stop.sh"
RESTART="$PUMA_DIR/puma_restart.sh"

start() {
  daemon --user $USERNAME --pidfile $PIDFILE $STARTUP && success || failure
}

stop() {
  $(STOP)
}

restart() {
  $(RESTART)
}

case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  restart)
    restart
    ;;
  hard-restart)
    stop
    start
    ;;
  *)
    echo "Usage: $0 {start|stop|restart|hard-restart}"
    exit 2
esac

exit $?

# vim: set filetype=sh :

Rework init.d to use the app scripts for all the commands
Rework init.d to use the app scripts for all the commands
