I'd like to learn about how systemd
starts services, specifically which user the service is started as, and I'd like to use Jenkins running on my Linux PC as an example.
I know that init
is pid 1
, the mother of all processes in Linux, and in my case pid 1
belongs to systemd
, which I can see from running top
:
$ top
Tasks: 646 total, 1 running, 645 sleeping, 0 stopped, 0 zombie
%Cpu(s): 1.0 us, 0.6 sy, 0.0 ni, 97.0 id, 1.3 wa, 0.0 hi, 0.1 si, 0.0 st
MiB Mem : 257826.8 total, 198695.4 free, 28529.6 used, 30601.7 buff/cache
MiB Swap: 262012.0 total, 262012.0 free, 0.0 used. 227579.3 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1 root 20 0 171284 11196 7904 S 0.3 0.0 31:49.54 systemd
I had naively assumed that because systemd
runs as root
, all services that it runs would run as root.
But I think that Jenkins is running as admin
on my PC.
I tried to use systemctl
to determine which user Jenkins was running as, but I didn't see any user info in the stdout:
user@linux_box:~$ systemctl status jenkins
● jenkins.service - LSB: Start Jenkins at boot time
Loaded: loaded (/etc/init.d/jenkins; generated)
Active: active (exited) since Fri 2023-05-05 11:50:06 PDT; 3 days ago
Docs: man:systemd-sysv-generator(8)
Tasks: 0 (limit: 4915)
Memory: 0B
CGroup: /system.slice/jenkins.service
Warning: Journal has been rotated since unit was started. Log output is incomplete or unavailable.
user@linux_box:~$
...so I tried ps aux
:
user@linux_box:~$ ps aux | grep jenkins
admin 2042 0.0 0.0 14164 196 ? S May05 0:00 /usr/bin/daemon --name=admin --inherit --env=JENKINS_HOME=/home/admin/jenkins --output=/var/log/jenkins/jenkins.log --pidfile=/var/run/admin/admin.pid -- /usr/bin/java -Djava.awt.headless=true -jar /home/admin/jenkins/jenkins.war --webroot=/var/cache/jenkins/war --httpPort=8080
admin 2043 1.7 5.3 48146100 14118144 ? Sl May05 83:41 /usr/bin/java -Djava.awt.headless=true -jar /home/admin/jenkins/jenkins.war --webroot=/var/cache/jenkins/war --httpPort=8080
admin 29932 0.0 0.0 6204 892 pts/1 S+ 20:37 0:00 grep jenkins
...I think that leftmost column is saying that Jenkins is running as admin
, no?
Can someone please explain the relationship between systemd
, the user that it runs as vs. the user that services are run as? It would be great if the answer could tie that to what's specifically going on with Jenkins on this Linux PC.