Project

General

Profile

Feature #1472

make init scripts aware of passenger

Added by Mikael Fridh over 7 years ago. Updated over 7 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Packaging
Target version:
Difficulty:
easy
Triaged:
No
Bugzilla link:
Pull request:
Team Backlog:
Fixed in Releases:
Found in Releases:

Description

I suggest we make the init scripts aware of passenger:

default file should be made to look something like this:
@@
  1. sysconfig/foreman || default/foreman on debian
  1. the location where foreman is installed
    #FOREMAN_HOME=/usr/share/foreman
  1. the port which foreman web server is running at
  2. note that if the foreman user is not root, it has to be a > 1024
    #FOREMAN_PORT=3000
  1. the user which runs the web interface
    #FOREMAN_USER=foreman
  1. the rails environment in which foreman runs
    #FOREMAN_ENV=production
  1. Enable to allow the foreman init script to refuse start and stop
  2. but handle rails app restart by touching $FOREMAN_HOME/tmp/restart.txt
    #FOREMAN_USE_PASSENGER=0
    @@
And this start script is a working example for Redhat:
@@
#!/bin/bash #
  1. Init script for foreman #
  2. chkconfig: - 85 15
  3. description: Init script for foreman
  1. 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
}
  1. 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
@@

  1. 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.

Associated revisions

Revision 23a4a9f6 (diff)
Added by Mikael Fridh over 7 years ago

fixes #1472 - make init script passenger-aware (redhat)

History

#1 Updated by Mikael Fridh over 7 years ago

Sorry for the formatting, booboo... here's a patch for the Redhat side of things.

#2 Updated by Ohad Levy over 7 years ago

  • Assignee set to Mikael Fridh

#3 Updated by Mikael Fridh over 7 years ago

  • Status changed from New to Closed
  • % Done changed from 20 to 100

#4 Updated by Ohad Levy over 7 years ago

thanks!
as a follow up, would you mind updating the puppet module to configure passenger at sysconfig as well? :)

Also available in: Atom PDF