Skip to content

Instantly share code, notes, and snippets.

@desnudopenguino
Last active March 11, 2018 01:16
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 desnudopenguino/14b6d0ac0514fd78907a1942cbfe81dd to your computer and use it in GitHub Desktop.
Save desnudopenguino/14b6d0ac0514fd78907a1942cbfe81dd to your computer and use it in GitHub Desktop.
Puma rc.d script for FreeBSD
#!/bin/sh
#
. /etc/rc.subr
name="puma"
start_cmd="${name}_start"
stop_cmd="${name}_stop"
restart_cmd="${name}_restart"
rcvar=puma_enable
required_files=/usr/local/etc/puma.conf
puma_start()
{
server_count=$(/usr/local/bin/jq ".servers[] .ruby_env" /usr/local/etc/puma.conf | wc -l)
i=0
while [ "$i" -lt "$server_count" ]; do
rb_env=$(/usr/local/bin/jq ".servers[$i].ruby_env" /usr/local/etc/puma.conf)
dir=$(/usr/local/bin/jq ".servers[$i].dir" /usr/local/etc/puma.conf)
user=$(/usr/local/bin/jq ".servers[$i].user" /usr/local/etc/puma.conf)
rb_ver=$(/usr/local/bin/jq ".servers[$i].ruby_version" /usr/local/etc/puma.conf)
echo "$i: Starting $rb_env puma server $dir run by $user on ruby v$rb_ver..."
case $rb_env in
"rbenv")
su - $user -c "cd $dir && rbenv shell $rb_ver && bundle exec puma -C $dir/config/puma.rb -d"
;;
*)
echo "Skipping, no environment set"
;;
esac
i=$(( i + 1 ))
done
}
puma_stop()
{
pkill ruby
}
puma_restart()
{
if [ $ruby_env == "rbenv" ]; then
su - $user -c "cd $dir && pkill ruby && rbenv shell $ruby_version && bundle exec puma -C $dir/config/puma.rb -d"
fi
}
load_rc_config $name
run_rc_command "$1"
{
"servers" : [
{
"dir": "/usr/home/yacfr/yacfr",
"user": "yacfr",
"ruby_version": "2.4.1",
"ruby_env": "rbenv"
},
{
"dir": "/usr/home/yacfr/yacfr",
"user": "yacfr",
"ruby_version": "2.4.1",
"ruby_env": "rbenv"
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment