Skip to content

Instantly share code, notes, and snippets.

@katafrakt
Created October 11, 2012 18:59
Show Gist options
  • Save katafrakt/3874733 to your computer and use it in GitHub Desktop.
Save katafrakt/3874733 to your computer and use it in GitHub Desktop.
simple and stupid Arch Linux rc.d script for starting and stopping puma (http://puma.io) with certain rails app
#!/bin/bash
. /etc/rc.conf
. /etc/rc.d/functions
. /etc/profile
DAEMON=prozatorium
PIDFILE=/path/to/pidfile
app_path=/path/to/rails_app
config=config/puma.rb
logfile=log/puma.log
case "$1" in
start)
stat_busy "Starting $DAEMON"
[ -z "$PID" ] && cd $app_path && bundle exec puma --pidfile $PIDFILE -C $config &>/dev/null >> $logfile &
if [ $? = 0 ]; then
add_daemon $DAEMON
stat_done
else
stat_fail
exit 1
fi
;;
stop)
PID=`cat $PIDFILE`
stat_busy "Stopping $DAEMON"
[ -n "$PID" ] && kill $PID &>/dev/null
if [ $? = 0 ]; then
rm_daemon $DAEMON
stat_done
else
stat_fail
exit 1
fi
;;
restart)
$0 stop
sleep 1
$0 start
;;
*)
echo "usage: $0 {start|stop|restart}"
esac
@dt1973
Copy link

dt1973 commented Apr 2, 2015

These (like everything else) tend to look a lot better on OpenBSD:

#!/bin/sh

# Puma startup script

# chmod +x /etc/rc.d/myapp

# http://cvsweb.openbsd.org/cgi-bin/cvsweb/ports/infrastructure/templates/rc.template

. /etc/rc.d/rc.subr

myapp_home="/home/www/myapp"

pumactl="/usr/local/bin/pumactl"
puma_config="-C ${myapp_home}/config/puma.rb"
puma_state="-S ${myapp_home}/tmp/puma.state"

rc_start() {
  ${rcexec} "${pumactl} ${puma_state} start ${puma_config}"
}

rc_reload() {
  ${rcexec} "${pumactl} ${puma_state} restart ${puma_config}"
}

rc_stop() {
  ${rcexec} "${pumactl} ${puma_state} stop"
}

rc_check() {
  ${rcexec} "${pumactl} ${puma_state} status"
}

rc_cmd $1

Or FreeBSD:

#!/bin/sh

# Puma startup script

# chmod +x /usr/local/etc/rc.d/myapp

# https://freebsd.org/doc/en/articles/rc-scripting/rcng-dummy.html

. /etc/rc.subr

name=myapp
rcvar=myapp_enable

myapp_home="/home/www/myapp"

pumactl="/usr/local/bin/pumactl"
puma_config="-C ${myapp_home}/config/puma.rb"
puma_state="-S ${myapp_home}/tmp/puma.state"

start_cmd="${pumactl} ${puma_state} start ${puma_config}"
stop_cmd="${pumactl} ${puma_state} stop"
restart_cmd="${pumactl} ${puma_state} restart"

load_rc_config $name
run_rc_command "$1"

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