running jenkins under different user

Viewed 33

I am trying to run Jenkins under a different user than "Jenkins" on my ubuntu server. I want to run it under "alihasan". I followed this guide and it used to work, used for years but it does not seem to work anymore. As soon as I change user and chown dirs, Jenkins service fails to start, with errors like this

May 16 14:11:29 mark85 jenkins[455372]: java.io.FileNotFoundException: /var/lib/jenkins/identity.key.enc (Permission denied)
May 16 14:11:29 mark85 jenkins[455372]:         at java.base/java.io.FileOutputStream.open0(Native Method)
May 16 14:11:29 mark85 jenkins[455372]:         at java.base/java.io.FileOutputStream.open(FileOutputStream.java:298)
May 16 14:11:29 mark85 jenkins[455372]:         at java.base/java.io.FileOutputStream.<init>(FileOutputStream.java:237)
May 16 14:11:29 mark85 jenkins[455372]:         at java.base/java.io.FileOutputStream.<init>(FileOutputStream.java:187)
May 16 14:11:29 mark85 jenkins[455372]:         at org.jenkinsci.main.modules.instance_identity.InstanceIdentity.write(InstanceIdentity.java:97)
May 16 14:11:29 mark85 jenkins[455372]:         at org.jenkinsci.main.modules.instance_identity.InstanceIdentity.<init>(InstanceIdentity.java:66)
May 16 14:11:29 mark85 jenkins[455372]:         at org.jenkinsci.main.modules.instance_identity.InstanceIdentity.<init>(InstanceIdentity.java:40)
May 16 14:11:29 mark85 jenkins[455372]:         at org.jenkinsci.main.modules.instance_identity.PageDecoratorImpl.<init>(PageDecoratorImpl.java:22)
May 16 14:11:29 mark85 jenkins[455372]:         at org.jenkinsci.main.modules.instance_identity.PageDecoratorImpl$$FastClassByGuice$$1384067.GUICE$T
RAMPOLINE(<generated>)
May 16 14:11:29 mark85 jenkins[455372]:         at org.jenkinsci.main.modules.instance_identity.PageDecoratorImpl$$FastClassByGuice$$1384067.apply(<
generated>)

I have followed different other guides and fixes found on the internet for the past 3-4 days, but nothing worked. I don't have much knowledge about it, any sort of help is very appreciated.

Thanks

1 Answers

Fixed after editing User and Environment variable directly in /etc/systemd/system/multi-user.target.wants/jenkins.service Maybe there is a better way such as using systemctl edit jenkins, but first one is working fine right now, at least until jenkins gets updated again.

Posting it if someone else comes around the same issue.

Related