Last active
October 22, 2015 18:12
-
-
Save Ginja/fb123759d48b04b5f338 to your computer and use it in GitHub Desktop.
A service script to run dynflow-executor inside an RVM installation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Author: Riley Shott | |
# https://gist.github.com/Ginja/fb123759d48b04b5f338 | |
# dynflow-executor - starts or stops the Dynflow executor for Foreman tasks | |
# | |
# chkconfig: 345 99 20 | |
# description: dynflow-executor is a rake task that comes with \ | |
# the foreman-tasks gem | |
# processname: dynflow-executor | |
# pidfile: /usr/local/foreman/tmp/pids/dynflow_executor_monitor.pid | |
# pidfile: /usr/local/foreman/tmp/pids/dynflow_executor.pid | |
# Source function library. | |
. /etc/rc.d/init.d/functions | |
foreman_user='foreman' | |
rvm='/usr/local/.rvm/bin/rvm' | |
gemset='ruby-2.1.5@foreman-1.9.1' | |
foreman_app_path='/usr/local/foreman' | |
dynflow_executor="$(cd /usr/local/foreman && /usr/local/.rvm/bin/rvm ruby-2.1.5@foreman-1.9.1 do bundle show foreman-tasks)/bin/dynflow-executor" | |
rvm_do_dynflow="RAILS_ENV=production ${rvm} ${gemset} do ${dynflow_executor}" | |
prog=$(basename $dynflow_executor) | |
[ -f /etc/sysconfig/dynflow-executor ] && . /etc/sysconfig/dynflow-executor | |
start() { | |
[ -x $dynflow_executor ] || exit 5 | |
echo -n $"Starting $prog: " | |
su - $foreman_user -c "cd ${foreman_app_path} && ${rvm_do_dynflow} start" | |
RETVAL=$? | |
if [ $RETVAL -eq 0 ] | |
then success | |
else failure | |
fi | |
echo | |
return $RETVAL | |
} | |
stop() { | |
echo -n $"Stopping $prog: " | |
cd "${foreman_app_path}" | |
su - $foreman_user -c "cd ${foreman_app_path} && ${rvm_do_dynflow} stop" | |
RETVAL=$? | |
if [ $RETVAL -eq 0 ] | |
then success | |
else failure | |
fi | |
echo | |
return $RETVAL | |
} | |
status() { | |
pgrep -f -u $foreman_user dynflow_executor -l | |
} | |
restart() { | |
stop | |
sleep 2 | |
start | |
} | |
case "$1" in | |
start) | |
$1 | |
;; | |
stop) | |
$1 | |
;; | |
status) | |
$1 | |
;; | |
restart) | |
$1 | |
;; | |
*) | |
echo $"Usage: $0 {start|stop|status|restart}" | |
exit 2 | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment