Main requirement of moving jenkins from root is that "root" always have lesser space captured in cloud platforms and "ebs" will be attached to provide more space to the node.
By default when you install jenkins on any linux machines(centos/ubuntu etc...) Jenkins will be placed under /var/lib/jenkins with owner & group ownership of "jenkins" user.
When we want to move jenkins from "root"(which is not having sufficient space) to /ebs(elastic block storage of any cloud CAAS), just follow below steps:
The example im taking here is I will be moving jenkins from "/var/lib/jenkins" to "/ebs/jenkins"
1. firstly stop the jenkins running by "sudo service jenkins stop"
2. copy all the contents of jenkins folder from "/var/lib/jenkins" to "/ebs/jenkins" by -
sudo cp -r /var/lib/jenkins /ebs/
3. now come to /ebs by "cd /ebs" and check the owner & group of jenkins folder under /ebs, now it will be your username instead of jenkins, we need to assign jenkins as both owner & group for all files inside jenkins directory by-
sudo chown -R jenkins:jenkins /ebs/jenkins <this will assign jenkins for all the files recursively>
4. now we need to change the new path of jenkins on "sudo /etc/passwd" file.
inside this file you will find a line starting with "jenkins" on end of teh line just change the content from "/var/lib/jenkins" to "/ebs/jenkins" and save file by ":x".
5. On bashrc we need to create JENKINS_HOME var with new path and assign it to path by-
vi ~/.bashrc
JENKINS_HOME=/ebs/jenkins
PATH=/sbin:/bin/java:$JENKINS_HOME
now save the bashrc file by ":x".
to execute this bashrc file run "source ~/.bashrc" which is mandatory that it will update all newly saved vars.
6. now open the main script of jenkins (sudo vi /etc/init.d/jenkins) which will be used when starting/stopping/restarting jenkins and change the content from "JENKINS_HOME" to "/ebs/jenkins" and save file by ":x".
7. Now run the command "sudo systemctl daemon-reload" which will reload all the new setting done to jenkins configuration file.
8. now time to restart jenkins by "sudo service jenkins start".
9. open the jenkins on browser with 8080 port to access newly changed path.
to verify whether jenkins is running on newly changed path run "ps -ef|grep jenkins"
on the results it gives, verify -DJENKINS_HOME= value (it should be now "/ebs/jenkins").

Comments
Post a Comment