Skip to content

Instantly share code, notes, and snippets.

@koola
Last active December 19, 2015 19:58
Show Gist options
  • Save koola/6009502 to your computer and use it in GitHub Desktop.
Save koola/6009502 to your computer and use it in GitHub Desktop.
Setup Jenkins CI Server on Cent 6.3 minimal install
#!/bin/bash
# /etc/init.d/jenkins
# CentOS release 6.3 (Final)
#
### BEGIN INIT INFO
# Provides: jenkins
# Required-Start: $local_fs $remote_fs $syslog $network $time
# Required-Stop: $local_fs $remote_fs $syslog $network $time
# Default-Start: 3 5
# Default-Stop: 0 1 2 6
# Short-Description: Jenkins CI Server
# Description: Jenkins Continuous Integration Server.
### END INIT INFO
JENKINS_USER="jenkins"
JENKINS_HOME="/home/jenkins"
JENKINS_WAR="/home/jenkins/jenkins.war"
JENKINS_LOG="/var/log/jenkins/jenkins.log"
JENKINS_OPTS="--logfile=$JENKINS_LOG --webroot=$JENKINS_HOME/war --daemon"
JAVA="/usr/bin/java"
JAVA_ARGS="-Djava.awt.headless=true -DJENKINS_HOME=$JENKINS_HOME"
PID_FILE="/var/run/jenkins.pid"
# Run as root
(( $UID == 0 )) || exit 0
# Check files and log directory exist
[ -x "$JAVA" -o -x "$JENKINS_WAR" -o -d "${JENKINS_LOG%/*}" ] || exit 0
# Source function library
. /etc/init.d/functions
case "$1" in
start)
echo -n $"Starting Jenkins "
daemon --user="$JENKINS_USER" --pidfile="$PID_FILE" "$JAVA $JAVA_ARGS -jar $JENKINS_WAR $JENKINS_OPTS" >/dev/null
if (( $? == 0 )); then
success
/bin/ps hww -u "$JENKINS_USER" -o pid,cmd | grep [j]enkins.war | { read pid cmd; echo $pid > "$PID_FILE"; }
else
failure
fi
echo
;;
stop)
echo -n $"Shutdown Jenkins "
killproc -p "$PID_FILE" jenkins
(( $? == 0 )) && rm -f "$PID_FILE"
echo
;;
status)
status jenkins
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: $0 {start|stop|status|restart}" >&2
exit 1
;;
esac
exit 0
/var/log/jenkins/jenkins.log {
rotate 4
size 100k
create 0644 root root
}
/usr/sbin/groupadd -g 200 jenkins
/usr/sbin/useradd -u 200 -g jenkins jenkins
wget -O /home/jenkins/jenkins.war http://mirrors.jenkins-ci.org/war/latest/jenkins.war
mkdir -m 0755 -p /var/log/jenkins
chown jenkins. /var/log/jenkins /home/jenkins/jenkins.war
wget -O /etc/init.d/jenkins https://gist.github.com/koola/6009502/raw/6b95a60651d684958cd13a52f4404d14e0793946/jenkins
chmod 755 /etc/init.d/jenkins
yum install -y java-1.6.0-openjdk.x86_64 # Optional
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment