

We’re shown which unit file has been loaded “/etc/systemd/system/htg.service”.The name of the service is “htg.service”, and the long description is the one that we provided in the unit file.The green dot means our service is up and running smoothly.The status of the service is displayed for us. You don’t want a malicious or mischievous user changing the unit file so that it executes a different program altogether.Īfter manually starting the service or after rebooting the computer, we can verify that our service is running correctly. The unit file doesn’t need to be executable, but the permissions on the unit file should restrict who can edit it. WantedBy: We have this set to “multi-user.target”, which means the service should be started as long as the system is in a state where multiple users can log in, whether or not a graphical user interface is available.If our service was a non-trivial program instead of a simple script, we would set this to “mixed” to ensure that any spawned processes were also terminated. We have this set to “process.” This causes systemd to use the SIGTERM signal on the main process only. KillMode: Defines how systemd should kill the process if we ask systemctl to stop the service.RestartSec: How long to wait before attempting to restart the service.Restart: When and if the service should be restarted.ExecStart: The path to the process that should be started.systemd will consider this service started as soon as the process specified by ExecStart has been forked. After: A list of unit names that should be started after this service has been successfully started, if they’re not already running.Wants: Our service wants-but doesn’t require-the network to be up before our service is started.Description: This is a text description of your service.

We need to create a unit file for our new service, but it is prudent to make sure none of the existing unit files have the name we want to give our new service. This holds certain attributes that systemd can use to locate and launch the program, and to define some of its behavior. sudo cp htg.sh /usr/local/binĪnd we need to make it executable: sudo chmod +x /usr/local/bin/htg.shĮach program that is started by systemd has a definition file, called a service unit file. We’ll copy the script to the /usr/local/bin directory. So, this script writes a timestamped message to the journal once per minute.
