Managing systemd configuration with cme

Dominique Dumont edited this page Dec 26, 2016 · 5 revisions

This page explains how to use cme to manage Systemd user configuration, i.e. how to use cme to update user Systemd configuration files located in ~/.config/systemd/user.

Installation

Debian/Ubuntu

On Debian/Ubuntu:

apt-get install cme libconfig-model-systemd-perl

To get the optional graphical interface, add:

apt-get install libconfig-model-tkui-perl

Others

Run

cpanm App::Cme
cpanm Config::Model::Systemd
cpanm Config::Model::TkUI

Usage

Checking user configuration

Run cme check systemd-user:

$ cme check systemd-user
cme: using Systemd model
loading data
checking data
check done

Checking system configuration

cme command can also be run as root to check Systemd configuration which is located in /etc/systemd/system/:

$ cme check systemd
cme: using Systemd model
loading data
checking data
check done

The edit modify and shell commands described below for systemd-user can be applied the same way to systemd.

Editing your configuration with a graphical interface

Once you run cme edit systemd-user, you will see a window like:

TkUI main screenshot

Most of your configuration will probably be in the service section. This section is shown in the screenshot above. It contains user services defined in global /usr/lib/systemd/user/ and in local ~/.config/systemd/user/. The services defined in the global directory can be overridden by files defined in the local directory.

With cme, you don't have to worry where the service files are stored. cme offers the possibility to override the global settings with local settings. This will be detailed later.

Let's edit the following example of a service file through cme:

$ cat ~/.local/share/systemd/user/free-imap-tunnel@.service
[Unit]
Description=Tunnel IMAPS connections to Free with Systemd

[Service]
StandardInput=socket
ExecStart=-/usr/bin/socat - PROXY:127.0.0.1:imap.free.fr:993,proxyport=8888

The content of this file can be accessed by opening service and then free-imap-tunnel:

TkUI main screenshot

Since Systemd features a lot of options, you may want to click on show only custom values button (top right) to hide unmodified configuration values:

TkUI main screenshot

The image above shows the parameters set up by user for the service (highlighted by the green arrow):

  • the Unit description
  • the parameter StandardInput
  • the list of command to execute (ExecStart)

Install does not show any value because no parameter was set. Once you double-click on Install, cme show the available parameters in the right part of the window. Parameters of Install can be edited there.

The green arrow means that the value is different from the default value.

To change a value (e.g. StandardInput), you:

  • double-click on StandardInput (right-click has the same effect)
  • click on any value in the "Edit value" widget
  • click on store button

TkUI main edit value

Once, this is done, you need to save the changes to the configuration by clicking on File->save menu.

Edit configuration with a shell like interface

If you have trouble running the graphical interface, you can use a shell like interface by running cme shell systemd-user command:

$ cme shell systemd-user [return]
cme: using Systemd model
 >:$ ls [return]
service socket
 >:$ cd service: [return]
Can't cd in a hash, please add an index (e.g. service:foo)
 >:$ cd service: [tab][tab]
service:                                service:glib-pacrunner                  service:gvfs-mtp-volume-monitor 
service:at-spi-dbus-bus                 service:"gmail-imap-tunnel@"            service:gvfs-udisks2-volume-monitor 
service:colord-session                  service:gnome-terminal-server           service:obex 
service:evolution-addressbook-factory   service:gvfs-afc-volume-monitor         service:"office365-imap-tunnel@" 
service:evolution-calendar-factory      service:gvfs-daemon                     service:pulseaudio 
service:evolution-source-registry       service:gvfs-goa-volume-monitor         service:systemd-exit 
service:evolution-user-prompter         service:gvfs-gphoto2-volume-monitor
service:"free-imap-tunnel@"             service:gvfs-metadata
 >:$ cd service:"free-imap-tunnel@"  [return]
 >: service:"free-imap-tunnel@" $ ls [return]
disable Unit Install Service
 >: service:"free-imap-tunnel@" $ cd Service  [return]
 >: service:"free-imap-tunnel@" Service $ ll [return]
name         value        type         comment
CPUAccounting [undef]      boolean
CPUShares    [undef]      uniline
<< snip >>
ExecStart    -/usr/bin/socat - PROXY:127.0.0.1:imap.free.fr:993,proxyport=8888 list
<< snip >>
 >: service:"free-imap-tunnel@" Service $ cd - Unit   [return]
 >: service:"free-imap-tunnel@" Unit $ ls Description [return]
Description
 >: service:"free-imap-tunnel@" Unit $ ll Description [return]
name         value        type         comment
Description  "Tunnel IMAPS connections to Free with corkscrew" uniline
 >: service:"free-imap-tunnel@" Unit $ set Description="Tunnel IMAPS connections to Free with Systemd"[return]
 >: service:"free-imap-tunnel@" Unit $ ll Description [return]
name         value        type         comment
Description  "Tunnel IMAPS connections to Free with Systemd" uniline

>: service:"free-imap-tunnel@" Unit $ changes [return]
service:"free-imap-tunnel@" Unit Description: 'Tunnel IMAPS connections to Free with corkscrew' -> 'Tunnel IMAPS connections to Free with Systemd'
 >: service:"free-imap-tunnel@" Unit $ exit [return]


Changes applied to systemd-user configuration:
- service:"free-imap-tunnel@" Unit Description: 'Tunnel IMAPS connections to Free with corkscrew' -> 'Tunnel IMAPS connections to Free with Systemd'

write back data before exit ? (Y/n) [return]

$

For more details, see the documentation on available cme shell commands

common tasks with cme command line

Upgrade your systemd configuration

Not yet provided. Unlike Ssh model, Systemd model currently contains no provision to upgrade older Systemd configuration because the author is not aware of such a need. Feel free to log a bug on github to require upgrade capabilities.

modification of configuration

You can use the modify subcommand of cme to perform configuration modifications with a command line:

 cme modify systemd-user 'service:"free-imap-tunnel@" Unit Description="Tunnel IMAPS connections to Free with Systemd"'
cme: using Systemd model

Changes applied to systemd-user configuration:
- service:"free-imap-tunnel@" Unit Description: 'Tunnel IMAPS connections to Free with System-d' -> 'Tunnel IMAPS connections to Free with Systemd'

The command used after systemd-user follows the syntax described in Config::Model::Loader documentation.

In a Perl program

Starting from Config::Model 2.086, cme() function can be used to modify Systemd configuration:

use strict;
use warnings;
use Config::Model qw/cme/;

cme('systemd-user)->modify('service:"free-imap-tunnel@" Unit Description="Tunnel IMAPS connections to Free with Systemd"');

For more details, see Systemd and cme documentation.