Seleccionar página

Se puede usar este script para arrancar Hudson o Jenkins, preferiblemente este último, como servicio en linux usando como servidor web el “Winstone” que lleva embebido en el war:


#!/bin/bash
#
# Startup script for Hudson
#
# chkconfig: - 84 16
# description: Hudson CI server

# Source function library.
. /etc/rc.d/init.d/functions
[ -z "$JAVA_HOME" -a -x /etc/profile.d/java.sh ] && . /etc/profile.d/java.sh
[ -z "$ANT_HOME" -a -x /etc/profile.d/ant.sh ] && . /etc/profile.d/ant.sh

HUDSON_HOME=/var/hudson
WAR="$HUDSON_HOME/hudson.war"
WAR_DIR="$HUDSON_HOME/hudson.war_dir" # WAR Descomprimido, por si se quiere personalizar
WAR_DIR_CLASSPATH="$WAR_DIR:$WAR_DIR/winstone.jar:$WAR_DIR/remoting.jar"
LOG="/var/log/hudson.log"
LOCK="/var/lock/subsys/hudson"
# con -1 no levanta el puerto
HTTP_PORT=18080
AJP_PORT=18009
#JAVA_HOME=/opt/java/jdk
PATH=$PATH:$JAVA_HOME/bin:$ANT_HOME/bin
# Put proxy
JAVA_OPTS="$JAVA_OPTS -Dhttp.proxyHost=172.24.201.108 -Dhttp.proxyPort=3128"

export HUDSON_HOME

RETVAL=0

pid_of_hudson() {
    ps auxwww | grep java | grep hudson | grep -v grep | awk '{print $2}'
}

start() {
    [ -e "$LOG" ] && cnt=`wc -l "$LOG" | awk '{ print $1 }'` || cnt=1

    echo -n $"Starting hudson: "

    cd "$HUDSON_HOME"
    nohup $JAVA_HOME/bin/java -jar "$WAR" $JAVA_OPTS --httpPort=$HTTP_PORT --ajp13Port=$AJP_PORT --prefix=/hudson >> "$LOG" 2>&1 &

    while { pid_of_hudson > /dev/null ; } &&
          ! { tail -n $cnt "$LOG" | grep -q 'Winstone Servlet Engine .* running' ; } ; do
        sleep 1
    done

    pid_of_hudson > /dev/null
    RETVAL=$?
    [ $RETVAL = 0 ] && success $"$STRING" || failure $"$STRING"
    echo

    [ $RETVAL = 0 ] && touch "$LOCK"
}

stop() {
    echo -n "Stopping hudson: "

    pid=`pid_of_hudson`
    [ -n "$pid" ] && kill $pid
    RETVAL=$?
    cnt=10
    while [ $RETVAL = 0 -a $cnt -gt 0 ] &&
          { pid_of_hudson > /dev/null ; } ; do
        sleep 1
        ((cnt--))
    done

    [ $RETVAL = 0 ] && rm -f "$LOCK"
    [ $RETVAL = 0 ] && success $"$STRING" || failure $"$STRING"
    echo
}

status() {
    pid=`pid_of_hudson`
    if [ -n "$pid" ]; then
        echo "hudson (pid $pid) is running..."
        return 0
    fi
    if [ -f "$LOCK" ]; then
        echo $"${base} dead but subsys locked"
        return 2
    fi
    echo "hudson is stopped"
    return 3
}

# See how we were called.
case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  status)
    status
    ;;
  restart)
    stop
    start
    ;;
  *)
    echo $"Usage: $0 {start|stop|restart|status}"
    exit 1
esac

exit $RETVAL