Writing a unit file for a daemon
In this recipe, we will take the daemon we wrote in Chapter 6, Spawning Processes and Using Job Control, and make it a service under systemd. This daemon is what systemd calls a forking daemon because it does just that. It forks. This is traditionally how daemons have worked, and they are still widely used. Later in this chapter, in the Making the new daemon a systemd service section, we will modify it slightly to log to systemd's journal. But first things first, let's make our existing daemon into a service.
Getting ready
In this recipe, you'll need the file my-daemon-v2.c
that we wrote in Chapter 6, Spawning Processes and Using Job Control. If you don't have that file, there is a copy of it in this chapter's directory on GitHub at https://github.com/PacktPublishing/Linux-System-Programming-Techniques/blob/master/ch7/my-daemon-v2.c.
Apart from my-daemon-v2.c
, you'll need the GCC compiler, the Make tool, and the...