Since the new ubuntu versions migrated from upstart to systemd in order to unify basic Linux service behaviors across all distributions we now have to deal with systemd as a default service manager/supervisor. In this article I will describe basics of how to write your first service on this platform.
Services directory location:
It’s even more convinient to fetch them with a special journalctl utility which reads a systemd journal:
$ journalctl --since "2017-02-25 00:00:00"
Now let’s create a simple Ruby script which will run an infinite loop:
$ cd /home/username/
$ vim mydaemon.rb
$stdout.sync = true
loop.with_index do |_, i|
And start it as a daemon:
$ ruby mydaemon.rb &
Checking logs to make sure the daemon is running as expected:
$ tail -f mydaemon.log
And stop it:
$ kill *pid*
It’s time to add a systemd service which will start this daemon automatically and restart it whenever it was stopped or crashed.