Life With Systemd

 

For those of you who using Fedora Core, may have noticed that they are using a completely new system and service manager called systemd, which replaces SysV.  This new tool addresses some of the inherent problems with Sysv including providing better service management, addressing dependency between services.  Like many folks out there, I am adapting to this rather major change, but at the same time, I believe it is the step in the right direction.  If you have looked at Solaris, they already have a robust system and service manager which is in some ways very similar to systemd.   And even Microsoft Windows has enjoyed many of the benefits already offered by systemd for many years, maybe perhaps since NT4, but definitely since Windows 2000. 

If you are using Fedora Core, and you have access the the GUI, the easiest way to manage systemd is via the systemadm tool.  If you type systemadm, you will see the systemd graphical user interface.

What I am really impressed with is all the information about the service, the dependencies and the state information.  However, for many of us, the graphical user interface is nice, but what we really want to do is understand the how systemd really works, where you can add new system initialization scripts, and alter existing one.  A huge reason you may want to alter systemd configurations is to change where MySQL or Postgresql store their data files.  Typically I like to put MySQL and Postgresql logs on a seperate I/O channel than the data volume for performance reasons.  

If you take a look at /etc/init.d/ you will see that there is very little in this directory in terms of initialization scripts.  And what is there is usually just a shim for the systemctl command.  So where is everything stored?  Well, all the scripts are now in /lib/systemd/system and you no longer have to be a BASH expert to build scripts.  Everything uses a simple configuration style syntax.  Additionally you need to be aware that you do not actually change any scripts /lib/systemd/system.  All the changes you make go into /etc/systemd/system.  Apparently there is some sort of mechanism where you make changes in /etc/systemd/system will override the corresponding file in /lib/systemd/system.

So if you wanted to change the path where postgresql stores its data, you would copy the script from /lib/systemd/system/postgresql.service to /etc/systemd/system/postgresql.service.  

Then you would edit the /etc/systemd/system/postgresql.service file and change the line the file 

# Location of database directory
Environment=PGDATA=/var/lib/pgsql
To the following if you wanted to have Postresql store its files in /local
# Location of database directory
Environment=PGDATA=/local/postgresql/9.1/main/
Now let's take a look at  how we can enable sshd service.  Since it is not enabled by default.  All of our interaction will be with the systemctl command.  It is a command line interface to systemd.  You could have easily used the systemdadm command as well.  

To enable ssh via system do the following:
systemctl enable sshd.service

To start the ssh service:

systemctl start sshd.service

Obtain the status of the ssh service

systemctl status sshd.service

If you need to restart the service

systemctl restart sshd.service

Stop the sshs service

systemctl stop sshd.service

To list all the services, just type systemctl.

Of course, there is a lot more systemd can do.  I see there is an entire jobs category.  Not sure if this is a cron replacement or some other type of process management facility.  

 

Tags: