Custom systemd Unit and Unit File: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
No edit summary
Line 43: Line 43:


For more details on the content of the unit files, see [[systemd Concepts#Unit_File_Structure|systemd Concepts - Unit File Structure]].
For more details on the content of the unit files, see [[systemd Concepts#Unit_File_Structure|systemd Concepts - Unit File Structure]].
=Notify <tt>systemd</tt> of the existence of the new file==
<pre>
systemctl daemon-reload
</pre>
=Exercise the Service=
<pre>
systemctl start myservice
systemctl status hello
systemctl restart hello
systemctl stop hello
</pre>

Revision as of 05:55, 16 February 2016

External

Internal

Overview

This article describes the procedure to configure an arbitrary service myservice to be managed by systemd. It includes the creation of corresponding unit file and systemd configuration to start/stop the service automatically at boot/shutdown.

Important Note

This procedure was not tested step-by-step. When I have a concrete case that can be used for testing, revisit and update.

Create the Unit File

Create the /etc/systemd/system/myservice.service unit file. For more details on the location of the unit files, see systemd Concepts - Unit File Location.

touch /etc/systemd/system/myservice.service
chmod 644 /etc/systemd/system/myservice.service

Configure the Unit File

[Unit]
Description=MyService
After=network.target

[Service]
ExecStart=/opt/myservice/bin/myservice
Type=forking
PIDFile=/var/run/myservice.pid

[Install]
WantedBy=multi-user.target

For more details on the content of the unit files, see systemd Concepts - Unit File Structure.

Notify systemd of the existence of the new file=

systemctl daemon-reload

Exercise the Service

systemctl start myservice
systemctl status hello
systemctl restart hello
systemctl stop hello