Getting started with GSoC 2016 with Cockpit

Harish Anand
2 min readMay 8, 2016

I have been selected for Google Summer of code’ 2016 program under Fedora Project. My project is about building a systemd timer interface for the Cockpit Project and my mentors are Peter Volpe and Dominik Perpeet. The following are the updates for this week.

Conceptual idea to develop Timer

  1. Creation of Timers

Timers can be created by having a .timer file and .service file in /etc/systemd/system/. Major properties we need for the interface are

1. OnBootUSec (Monotonic timer): to let users start a process after the specified time from boot.

2. TimersCalendar: to let users set a calendar time for starting a process.

Finding out if SetUnitProperties() of Manager Object in DBus can set these properties.

var systemd_client = cockpit.dbus("org.freedesktop.systemd1", { superuser: "try" });
var systemd_manager =systemd_client.proxy("org.freedesktop.systemd1.Manager",
"/org/freedesktop/systemd1");
s = cockpit.variant("s","Test");
systemd_manager.SetUnitProperties("vmtoolsd.service",false,[["Description",s]]).
fail(function (error) {
console.log(error);
}).
done(function (result) {
console.log(result);
})

gave this error

DBusError {problem: null, name: “org.freedesktop.DBus.Error.PropertyReadOnly”, message: “Cannot set property Description, or unknown property.”}

Also systemd timer properties cannot be set as it is read only.

Solution : A feature request has to be filed to systemd for having a method to set timer property via Dbus. https://github.com/harishanand95/cockpit_test_timer/wiki/Feature-Request:-Request-to-have-timer-properties-set-via-D--Bus

var systemd_client = cockpit.dbus("org.freedesktop.systemd1", { superuser: "try" });
var systemd_manager = systemd_client.proxy("org.freedesktop.systemd1.Timer",
"/org/freedesktop/systemd1/unit/systemd_2dtmpfiles_2dclean_2etimer");
systemd_manager.TimersMonotonic
systemd_manager.TimersCalendar

Connect to timer dbus ( foobar.service is the file then dbus usually is /org/freedesktop/systemd1/unit/foobar_2eservice and foobar.timer has /org/freedesktop/systemd1/unit/foobar_2etimer)

As an example, I tried out both systemd_manager.TimersMonotonic and systemd_manager.TimersCalendar on different timers and its values were

[Array[3]]=[ 0:“OnBootUSec”, 1:900000000 , 2:900000000] and [Array[3]]= [ 0:“OnCalendar”, 1:“*-*-* 06:16:00”, 2:0] respectively.

Feature request describes about making 2 frequently used timer properties to be made available via new timer dbus methods setbootusec() and setcalendar().

setbootusec() may take as input integer usec value as input. Here it is 900000000.

setcalendar() may take as input 2 strings “OnCalendar”, “*-*-* 06:16:00”.

2. Modification of timers

Timer modification needs modifying already set properties. One approach I found is mentioned here.

Create the directory /etc/systemd/system/foobar.d/ and place .conf file to override or add new options to service. systemd will parse these .conf files and apply them on top of the original unit.

I was able to create and change Description parameter (read only) value of a loaded service through this method. But this method required the command systemctl daemon-reload after creating the .conf file to reflect changes. Also I couldn’t find any Dbus method that does daemon-reload.

Modification of timers approach: https://wiki.archlinux.org/index.php/systemd#Drop-in_snippets

Trello image : https://trello.com/c/1B2lZViZ/74-timers-and-cron

Also I’m learning JavaScript during this community bonding phase as I’m a beginner to it.

--

--