Skip to content

Instantly share code, notes, and snippets.

@nicdoye
Created March 1, 2013 16:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicdoye/5065871 to your computer and use it in GitHub Desktop.
Save nicdoye/5065871 to your computer and use it in GitHub Desktop.
Simple startup file for individual [Puma](http://puma.io) apps on RHEL/CentOS (tested on 6.x). Just the bare minumum needed, really. Do not call it puma.sh but place a copy in for each of your puma applications. (It relies on its own name to work) By renaming it you can have as many different apps (on separate ports) as you require. You'll need …
#!/bin/sh
#
# Puma control script
#
# chkconfig: - 80 20
# description: Puma
# Create an /etc/sysconfig/file of the same name as this with the following settings
# Note this code does NOT pick any defaults, so will fall over if these are unset.
# RACK_ENV=production
# RACKINIT_USER=<user>
# RACKINIT_DIRECTORY=<Folder containing config.ru>
# RACKINIT_PORT=<Port number. 9292 is traditional>
# RACKINIT_THREADS=<Puma expects something like 0:16 for min:max threads>
# Source function library.
. /etc/init.d/functions
prog=$(basename $(readlink -f $0))
# Load configuration.
[ -r /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
export RACK_ENV
# Config not there? Exit
if [ -z "$RACKINIT_DIRECTORY" ]; then
exit 6
fi
CMD_PREFIX=''
if [ ! -z "$RACKINIT_USER" ]; then
if [ -x /etc/rc.d/init.d/functions ]; then
CMD_PREFIX="daemon --user $RACKINIT_USER"
else
CMD_PREFIX="su - $RACKINIT_USER -c"
fi
fi
start() {
echo -n "Starting $prog: "
if [ ! -z "$RACKINIT_USER" ]; then
if [ -x /etc/rc.d/init.d/functions ]; then
daemon --user $RACKINIT_USER "cd $RACKINIT_DIRECTORY && bundle exec rackup -p $RACKINIT_PORT -O Threads=$RACKINIT_THREADS config.ru"&
else
su - $RACKINIT_USER -c "cd $RACKINIT_DIRECTORY && bundle exec rackup -p $RACKINIT_PORT -O Threads=$RACKINIT_THREADS config.ru" 2>&1 > /dev/null &
fi
fi
success
echo
return 0
}
stop() {
echo -n $"Stopping $prog: "
count=0;
fuser -k -n tcp $RACKINIT_PORT
success
echo
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
$0 stop
$0 start
;;
*)
## If no parameters are given, print which are avaiable.
echo "Usage: $0 {start|stop|restart}"
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment