Feature #1472
closedmake init scripts aware of passenger
Description
I suggest we make the init scripts aware of passenger:
default file should be made to look something like this:@@
- sysconfig/foreman || default/foreman on debian
- the location where foreman is installed
#FOREMAN_HOME=/usr/share/foreman
- the port which foreman web server is running at
- note that if the foreman user is not root, it has to be a > 1024
#FOREMAN_PORT=3000
- the user which runs the web interface
#FOREMAN_USER=foreman
- the rails environment in which foreman runs
#FOREMAN_ENV=production
- Enable to allow the foreman init script to refuse start and stop
- but handle rails app restart by touching $FOREMAN_HOME/tmp/restart.txt
#FOREMAN_USE_PASSENGER=0
@@
@@
#!/bin/bash #
- Init script for foreman #
- chkconfig: - 85 15
- description: Init script for foreman
- Source function library.
. /etc/rc.d/init.d/functions
if [ -f /etc/sysconfig/foreman ]; then
. /etc/sysconfig/foreman
fi
prog=foreman
RETVAL=0
FOREMAN_PORT=${FOREMAN_PORT:-3000}
FOREMAN_USER=${FOREMAN_USER:-foreman}
FOREMAN_HOME=${FOREMAN_HOME:-/usr/share/foreman}
FOREMAN_ENV=${FOREMAN_ENV:-production}
FOREMAN_PID=${FOREMAN_PID:-${FOREMAN_HOME}/tmp/pids/server.pid}
FOREMAN_USE_PASSENGER=${FOREMAN_USE_PASSENGER:-0}
start() {
echo -n $"Starting $prog: "
daemon --user ${FOREMAN_USER} /usr/bin/ruby ${FOREMAN_HOME}/script/server -p ${FOREMAN_PORT} -e ${FOREMAN_ENV} -d > /dev/null
RETVAL=$?
if [ $RETVAL = 0 ]
then
echo_success
else
echo_failure
fi
echo
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
if [ -f ${FOREMAN_PID} ]; then
killproc -p ${FOREMAN_PID}
RETVAL=$?
else
echo -n $"Foreman was not running.";
failure $"Foreman was not running.";
echo
return 1
fi
echo
return $RETVAL
}
railsrestart() {
echo -n $"Restarting foreman rails app: "
touch "${FOREMAN_HOME}/tmp/restart.txt"
RETVAL=$?
if [ $RETVAL = 0 ]
then
echo_success
else
echo_failure
fi
echo
return $RETVAL
}
- See how we were called.
case "$1" in
start|stop)
if [ ${FOREMAN_USE_PASSENGER} = 1 ]
then
echo -n "Foreman is running under passenger"
echo_passed
echo
else
$1
fi
RETVAL=$?
;;
restart)
if [ ${FOREMAN_USE_PASSENGER} = 1 ]
then
railsrestart
RETVAL=$?
else
stop
start
RETVAL?$?
fi
;;
status)
echo -n "Foreman"
if [ ${FOREMAN_USE_PASSENGER} = 1 ]
then
echo -n " is running under passenger"
echo_passed
echo
else
status -p $FOREMAN_PID
fi
RETVAL=$?
;;
condrestart)
if [ -f ${FOREMAN_HOME}/tmp/pids/server.pid ]; then
restart
RETVAL=$?
fi
;;*)
echo $"Usage: $prog {start|stop|restart|condrestart}"
exit 1
esac
exit $RETVAL
@@
- sample output:
@
@
[root@staging-admin-lv-1 ~]# service foreman start
Foreman is running under passenger [PASSED]
[root@staging-admin-lv-1 ~]# service foreman stop
Foreman is running under passenger [PASSED]
[root@staging-admin-lv-1 ~]# service foreman status
Foreman is running under passenger [PASSED]
[root@staging-admin-lv-1 ~]# service foreman restart
Restarting foreman rails app: [ OK ]
[root@staging-admin-lv-1 ~]#
I chose to use PASSED here, we could consider opting for an ERROR or WARNING as well if that makes more sense. My opinion is it's useful for the operator, so he does not mess things up by starting something he shouldn't.
Files
Updated by Mikael Fridh about 13 years ago
- File 0001-fixes-1472-make-init-script-passenger-aware-redhat.patch 0001-fixes-1472-make-init-script-passenger-aware-redhat.patch added
- % Done changed from 0 to 20
Sorry for the formatting, booboo... here's a patch for the Redhat side of things.
Updated by Mikael Fridh about 13 years ago
- Status changed from New to Closed
- % Done changed from 20 to 100
Applied in changeset 23a4a9f66c21237d962e4dfdafb5797bd536bd93.
Updated by Ohad Levy about 13 years ago
thanks!
as a follow up, would you mind updating the puppet module to configure passenger at sysconfig as well? :)