Exploring 1 – systemd

Starting to poke around systemd a bit more.The following is some running commentary – I may have no idea what I’m talking about.

I have to admit to myself I didn’t truly understand sysvinit all that well, I just knew how to get done what I needed to. Other than being used to typing “service xyz start” and “chkconfig xyz on” and looking in /etc/init.d for control scripts and /etc/rc*.d for symlinks, I couldn’t have answered a lot of specific questions about how it works. So really, aside from having to update my muscle memory for those things, I don’t have a huge attachment to sysvinit.

Google directed me to what looks like a good series of blog posts on systemd starting at http://0pointer.net/blog/projects/systemd-for-admins-1.html – starting in 2011 so there’s probably been a lot of drift since, but still looks like a good starting point with motivation and technical underpinnings. There’s just always more to learn about the OS.

systemctl status has a great deal more info than service status ever did, because systemd seems to standardize a bunch of stuff that was just left up to the control script before. Consider for httpd:

# service httpd status
httpd (pid 7114) is running...

So, we get that there is a running process, because the httpd daemon put down a pidfile and the process with that pid is running and looks like an httpd process. There are several other variations, including not being running, or having a pidfile but no corresponding process… well, the httpd service script could have put just about anything in its status output, tracking down log files and process trees would just be a little extra work there. systemd seems to keep track of a bunch more:

# systemctl status httpd
httpd.service - The Apache HTTP Server
 Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled)
 Active: active (running) since Tue 2014-12-02 08:11:22 EST; 12min ago
 Main PID: 23773 (httpd)
 Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec"
 CGroup: /system.slice/httpd.service
 ├─23773 /usr/sbin/httpd -DFOREGROUND
 ├─23774 /usr/sbin/httpd -DFOREGROUND
 ├─23775 /usr/sbin/httpd -DFOREGROUND
 ├─23776 /usr/sbin/httpd -DFOREGROUND
 ├─23777 /usr/sbin/httpd -DFOREGROUND
 └─23778 /usr/sbin/httpd -DFOREGROUND
Dec 02 08:11:22 lmeyer-1201-rhel7 systemd[1]: Starting The Apache HTTP Server...
Dec 02 08:11:22 lmeyer-1201-rhel7 systemd[1]: Started The Apache HTTP Server.

We get a pointer to the systemd unit file for httpd, whether it’s enabled (for running automatically at boot), whether it’s running (“active”) and for how long, process tree (which we can obtain with confidence because the daemon is put in a cgroup at start), some log entries, and some service-specific “Status” about traffic. That’s pretty handy, and not to say that the service script couldn’t have done all this, but systemd seems to standardize it.

# cat /usr/lib/systemd/system/httpd.service
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND
ExecReload=/usr/sbin/httpd $OPTIONS -k graceful
ExecStop=/bin/kill -WINCH ${MAINPID}

I looked in the unit file and I’m curious how it does all this, since there’s no entry for logs or status. Something to look out for.

Part 2 gets into the usage of cgroups, which seems like a neat use case. I notice that the cgroup names seem to be longer than when the article was written, so it’s helpful to expand the column in the ps command suggested for viewing processes with cgroups:

# alias psc='ps xawf -eo pid,user:16,cgroup:64,args' 
# psc
23773 root   1:name=systemd:/system.slice/httpd.service /usr/sbin/httpd -DFOREGROUND
23774 apache 1:name=systemd:/system.slice/httpd.service \_ /usr/sbin/httpd -DFOREGROUND
23775 apache 1:name=systemd:/system.slice/httpd.service \_ /usr/sbin/httpd -DFOREGROUND
23776 apache 1:name=systemd:/system.slice/httpd.service \_ /usr/sbin/httpd -DFOREGROUND
23777 apache 1:name=systemd:/system.slice/httpd.service \_ /usr/sbin/httpd -DFOREGROUND
23778 apache 1:name=systemd:/system.slice/httpd.service \_ /usr/sbin/httpd -DFOREGROUND

I read through http://0pointer.de/blog/projects/systemd.html which is a long and detailed introduction to the motivations behind systemd. Probably should have done that first.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: