SystemD and JournalD services
This note documents how to use the SystemD service manager to enable unattended background execution of the server software, and how to use the JournalD service to view and manage the server's logged output.
The Linux operating system uses SystemD to configure and manage background executables in a standard way. It uses "unit" files to configure the process user, process group, standard output destination, and most importantly, the command to start the server.
The Service Manager unit file should be placed in
/usr. The code below can be used as a template for a typical setup. Here are some things of note:
- The "unit" name used in
- The Node.js software is installed by default to
- The main entry point to the Read Write Tools rwserve source code is installed by default to
/lib /node_modules /rwserve /dist /main.js
- The configuration file should be created and edited in the standard location, which for the DNS hostname
- The system user running the process is
rwserve, created with the command "
useradd --system --user-group rwserve".
WorkingDirectoryis not used by the server software but is still required by some Linux distros. The path pointed to must be accessible by the
rwserveuser, so in this example be sure to change the owner using "
chown rwserve:rwserve /srv".
- Standard log output is sent to the
Description=Read Write Tools
rwserve unit file properly edited and in place, the service can be instructed to start automatically each time the computer is booted. Use the
enable command like this:
systemctl enable rwserve
Three basic commands can be issued to the service to
start execution, obtain its current
systemctl start rwserve
systemctl status rwserve
systemctl stop rwserve
Each time the service is started, information is logged to the process's standard output, which is routed by the unit file to the system journal; also, during active operation, each request, process, and response is logged to the system journal as well. The command line utility
journalctl is used to filter and display these log messages.
The system journal contains messages from many software components, so in order to limit the output to just the
rwserve messages, the
-u option should be used.
journalctl --unit rwserve
Message are shown in timestamp order, from oldest to most recent. Oftentimes it is more desirable to see the tail end of the messages. Use the
-n to display the most recent N messages. To monitor the messages in real time, use the
journalctl --unit rwserve -n 100
journalctl --unit rwserve --follow
The system journal does not automatically rotate or purge messages and will continue to capture and store messages for all device units until all disk space is used up. This is annoying, but not cataclysmic, as the operating system and services will continue to run, albeit without the ability to create new files or log messages. To see how much space is being used by the journal use the
‑‑disk-space option. It is a good practice to periodically purge old messages using the journal's