Custom systemd Unit and Unit File: Difference between revisions
Jump to navigation
Jump to search
Line 5: | Line 5: | ||
=Overview= | =Overview= | ||
This article describes the procedure to configure an arbitrary service <code> | This article describes the procedure to configure an arbitrary service <code>minecraft</code> to be managed by <code>systemd</code>. It includes the creation of corresponding [[Systemd_Concepts#Unit_Files|unit file]] and <code>systemd</code> configuration to start and stop the service automatically at boot, respectively shutdown. | ||
=Create the Unit File= | =Create the Unit File= |
Revision as of 22:29, 19 August 2023
Internal
Overview
This article describes the procedure to configure an arbitrary service minecraft
to be managed by systemd
. It includes the creation of corresponding unit file and systemd
configuration to start and stop the service automatically at boot, respectively shutdown.
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
Process Started and Stopped by Auxiliary Scripts
[Unit] Description=MyService After=network.target [Service] Type=oneshot ExecStart=/opt/myservice/bin/myservice start ExecStop=/opt/myservice/bin/myservice stop RemainAfterExit=yes [Install] WantedBy=multi-user.target
For more details on the content of the unit files, see systemd Concepts - Unit File Structure.
Daemon Process that Forks and Creates Its Own PID 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 unit file
systemctl daemon-reload
Enable at Boot
systemctl enable myservice.service
Exercise the Service
systemctl start myservice systemctl status hello systemctl restart hello systemctl stop hello