Before we start to write any line of code, we should make sure, that out buildsystem is running and the CI process in our new project is automatted.
The CI pipline only is complete, when you deploy your project directly to your test , stage and liveservern.
One possibility is, to register your webserver as a slave on your buildserver.
In our case we are using jenkins as a master build server and a ubuntu webserver as a slave.
If everythings is correct, you will see yout slavenode on the jenkinsdashboard.
Our slave is called "docker_gitlab_webserver_1" our Jenkins server listens to "dockergitlab_jenkins_1" on port 8080
So let'shave a look on the configuration
Configure your new node

Create that folder a on the slave machine nd make it accessable for the master.
This configuration will use Java Webstart with Jnpl. This will do the trick on communication between slave and master.
After you save the configuration you will get a downloadlink for your "slave.jar" and a command, which you can execute on your slave
Execute on your slave
java -jar slave.jar -jnlpUrl http://dockergitlab_jenkins_1:8080/computer/dockergitlab_webserver_1/slave-agent.jnlp
This has to be executed in "/var/lib/jenkins"
Make sure you have java 7 installed
After that you can see your slave running "connected" on your jenkins master.
Great !
Install this startupscript as a serviceTo make that rebootsafe you have to create a service and add it to the ubuntu runlevels S and 2, 3 and 6
Create a file "/etc/init.d/jenkins-slave"
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
#!/bin/bash | |
# | |
# /etc/init.d/jenkins-slave | |
# | |
# To add the script to autostart call => | |
# sudo update-rc.d jenkins-slave defaults | |
# | |
# To remove the script from autostart call => | |
# sudo update-rc.d -f jenkins-slave remove | |
# | |
### BEGIN INIT INFO | |
# Provides: jenkins-slave | |
# Required-Start: $local_fs $remote_fs $network $syslog $named | |
# Required-Stop: $local_fs $remote_fs $network $syslog $named | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: Starts jenkins-slave | |
# Description: Starts jenkins-slave | |
### END INIT INFO | |
Name="Jenkins Slave" | |
InstanceName="linux-shop-ci" | |
JenkinsUrl="https://<your jenkins ur.>" | |
Log="/var/log/jenkins" | |
Pidfile="/var/run/jenkins-slave.pid" | |
JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64 | |
case "$1" in | |
start) | |
touch $Log | |
chown shopbuilduser.root $Log | |
echo "Starting $Name">>$Log | |
"$JAVA_HOME/bin/java" -jar /usr/local/jenkins/slave.jar -jnlpUrl $JenkinsUrl/computer/$InstanceName/slave-agent.jnlp -noCertificateCheck 2>>$Log >>$Log & | |
Pid=$! | |
if [ -z $Pid ]; then | |
printf "%s\n" "Fail" | |
else | |
echo $Pid > $Pidfile | |
printf "%s\n" "Ok" | |
fi | |
;; | |
stop) | |
printf "%-50s" "Stopping $Name" | |
Pid=`cat $Pidfile` | |
if [ -f $Pidfile ]; then | |
kill -TERM $Pid | |
printf "%s\n" "Ok" | |
rm -f $Pidfile | |
else | |
printf "%s\n" "pidfile not found" | |
fi | |
;; | |
restart) | |
$0 stop | |
$0 start | |
;; | |
status) | |
printf "%-50s" "Checking $Name..." | |
if [ -f $Pidfile ]; then | |
Pid=`cat $Pidfile` | |
if [ -z "`ps axf | grep ${Pid} | grep -v grep`" ]; then | |
printf "%s\n" "Process dead but pidfile exists" | |
echo "Pidfile: $Pidfile" | |
else | |
echo "Running" | |
echo "Pid: $Pid" | |
echo "Pidfile: $Pidfile" | |
fi | |
else | |
printf "%s\n" "Service not running" | |
fi | |
;; | |
*) | |
echo "Usage: $0 {start|stop|restart}" | |
;; | |
esac |
sudo chmod 755 /etc/init.d/jenkins-slave sudo chown root:root /etc/init.d/
jenkins-slave
sudo update-rc.d jenkins-slave defaults
Add it to Autostart
sudo ln -s /usr/lib/insserv/insserv /sbin/jenkins-slave
sudo insserv
jenkins-slave
This will set correct accessrights to your service Make sure, you have replaced the parameters with your data.
Keine Kommentare:
Kommentar veröffentlichen