How to change the Jenkins Home Directory from /var/lib to app and create a symlink for orginal location as job wont get affected - linux

I need to change my Jenkins 2.89.3 version Home Directory from /Var/lib/jenkins to /app due to space constraints. I need to make sure , all jobs which are using the /var/lib/jenkins directory wont get affected by this migration. how to perform this operation and ran my jenkins job as expected
Current size of /var/lib/jenkins 5.1G
Move all contents to /app/
run jenkins jobs without any issues
Please help in this migration

You can use a symbolic link to do that:
Shutdown you Jenkins.
Move all files from /var/lib/jenkins to /app/jenkins
mv /var/lib/jenkins /app/
Replace /var/lib/jenkins with a symbolic link to /app/jenkins
ln -s /app/jenkins /var/lib/jenkins
Start Jenkins again.
That way all the files are actually stored under /app but all paths to /var/lib/jenkins stay valid due to the symbolic link.

Related

Gitlab CI invokes docker install.sh and always runs instruction with Sudo

I am trying to run gitlab ci which contains custom php image. The before_script invokes docker_install.sh
In docker_install.sh I executed whoami it gives "docker". I tried to list down groups it gives "docker sudo".
When I try to execute further instructions in docker_install.sh file, like
cp ci/php.ini /etc/php/7.4/cli/php.ini
It does not execute and gives error cp: cannot create regular file '/etc/php/7.4/cli/php.ini': Permission denied
If I do
sudo cp ci/php.ini /etc/php/7.4/cli/php.ini
it executes successfully. However there are many such instruction for which I do not want to append sudo.
What is the solution to this problem?
Docker user doesn't have root permissions.
Gitlab CI doesn't allow you modifying the user
One way is to derive FROM the original image by Dockerfile set user to USER root and after you have finished with your installation back to USER docker. Or leave it at root and just run your CI job.
Another less secure way is using su-exec (instead of sudo)
https://github.com/ncopa/su-exec

How to recover permissions on freebsd

Can not login to system after start server:
openpam_check_desc_owner_perms() : /etc/pam.d/login insecure perms
Started system in single-user mod. There are all system dirs (/boot , /lib ...)
nobody:nogroup
ownership.
Ofc, i cannot just chown system dirs. So, how can i restore ownership to root?
Firstly, you should use a live boot downloaded from official repository. I don't think rescue mode (in this case) can save you.
In live the live environment, just mount your impacted filesystems somewhere:
mount /dev/${your_partition} /mnt
Now, you can use mtree to set good rights on all default files and directory. This command will re-create your tree with good rights. Before executing it, you can run it to check state of your filesystem.
# check before act
mtree -f /etc/mtree/BSD.root.dist -p /mnt
# you can now apply change
mtree -u -f /etc/mtree/BSD.root.dist -p /mnt
You can find more mtree files in /etc/mtree:
BSD.debug.dist
BSD.include.dist
BSD.sendmail.dist
BSD.usr.dist
BSD.var.dist
After doing that, you can now run mergemaster. mergemaster will warn when some files aren't well configured with good rights:
mergemaster -iD /mnt
If you have still issue, you can download or fetch FreeBSD source from SVN, extract them, and reinstall your configuration files manually (do a backup of your configuration before doing that and please read official FreeBSD documentation about using source).
cd /usr/src
svnlite https://svnweb.freebsd.org/base/releng/${your_freebsd_release} .
cd /usr/src/etc
make install DESTDIR=/mnt
You can now reboot your computer or server without live CD.

"Unable to create home directory" error when changing JENKINS_HOME

Jenkins was running all fine on a RedHat Linux machine (a clean EC2 machine on AWS), until I decided to change the JENKINS_HOME. I simply moved the Jenkins directory from /var/lib/jenkins to /home/ec2-user/jenkins and then created a symlink. (I followed the first answer to this question: Change JENKINS_HOME on Red Hat Linux?).
However when I restart Jenkins I get the error:
Unable to create the home directory ‘/var/lib/jenkins’. This is most
likely a permission problem. To change the home directory, use
JENKINS_HOME environment variable or set the JENKINS_HOME system
property.
I tried changing JENKINS_HOME in /etc/sysconfig/jenkins, setting it to the new folder (which I suppose defeats the point of a symlink?) and I still get the same error
Unable to create the home directory ‘/home/ec2-user/jenkins’.
It is for backup purposes, so that I have all Jenkins data in a mounted external data storage (AWS Elastic File System).
I've figured it out. This error was persisting because the /jenkins/ folder needs to be accessible to user 'jenkins' to run processes, but it couldn't access this folder because it is belongs to the particular logged in user. I changed the mounting to /var/ where jenkins can access as global process, and it solved the problem.
I ran into the same problem, so sharing my solution here:
The user jenkins does not have access to the folder home/ec2-user/jenkins. You can modify the access rights of the folder home/ec2-user/home by changing or adding the user jenkins to owner
sudo chown jenkins /home/ec2-user/jenkins
sudo chmod u+w /home/ec2-user/jenkins
To verify the new ownership, you can do:
ls -ld /home/ec2-user/jenkins
The error seems pretty obvious: "This is most likely a permission problem."
I assume /home/jenkins does not exists, and the user jenkins does not have write permissions in /home. If you moved the Jenkins home, then you probably did it as root and just forgot to update owner permissions.
You would need to create the home, something like this:
sudo service jenkins stop
# make the changes in /etc/sysconfig/jenkins
sudo mkdir --parents /home/jenkins # or mv, in your case
sudo chown --recursive jenkins /home/jenkins
sudo service jenkins start

How can I make the directory writable, permanently, without having to run the command again?

I have a problem with making /dao permanently writable. I use this command:
chmod -R 777 /opt/project/newproject/target/scala-2.11/classes/dao
I am using Play-Framework. But when I run activator, the command delete the directory "dao" and create a new one.
I am working with Debian and trying start a bash file in Jenkins to create the Project on a Server

working on lamp server in ubuntu

i m working on ubuntu and just installed lamp.As i m new to linux i m not sure how to create a directory or file under /var/www of lamp server to start working on my website project
Under *nix you can create a directory using mkdir newdirname and you can create a new and empty file, using touch newfilename. Those are commands you need to execute from a shell/terminal. In order to get to /var/www, you will need to cd /var/www.
If you are new to Linux I suggest reading any guide on basic like this or this.
Chances are you do not have sufficient privileges as your normal user to add files or create directories. You can either change the ownership of the /var/www directory (and everything within) or you can sudo each one you want to add.
From the prompt: chown [your_user_name].users -R /var/www
Then you can mkdir [directory name] to make a directory or touch [filename] to create a file.
If you do not change the permissions of the /var/www you may need to put sudo in front of each of the above commands (will be prompted for password)

Resources