This shows you the differences between two versions of the page.
Previous revision | |||
— | fuss:systemd [2025/09/16 20:36] (current) – office | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Making Changes to Daemon Files ====== | ||
+ | Whenever a daemon file is changed in ''/ | ||
+ | <code bash> | ||
+ | systemctl daemon-reload | ||
+ | </ | ||
+ | |||
+ | ====== Starting Programs on Virtual Terminals ====== | ||
+ | |||
+ | Most *nix derivates start a login program such as '' | ||
+ | |||
+ | The procedure with systemd is a little different and involves shutting down the tty services and creating a service file. The first thing to do is run: | ||
+ | <code bash> | ||
+ | systemctl | ||
+ | </ | ||
+ | |||
+ | and search (using forward-slash ''/'' | ||
+ | < | ||
+ | getty@tty1.service | ||
+ | getty@tty2.service | ||
+ | getty@tty6.service | ||
+ | </ | ||
+ | |||
+ | which means that '' | ||
+ | |||
+ | In order for '' | ||
+ | <code bash> | ||
+ | systemctl stop getty@tty1.service | ||
+ | systemctl disable getty@tty1.service | ||
+ | </ | ||
+ | |||
+ | Next, add the following contents to a file placed at ''/ | ||
+ | < | ||
+ | [Unit] | ||
+ | Description=htop on tty1 | ||
+ | |||
+ | [Service] | ||
+ | Type=simple | ||
+ | ExecStart=/ | ||
+ | StandardInput=tty | ||
+ | StandardOutput=tty | ||
+ | TTYPath=/ | ||
+ | Restart=always | ||
+ | RestartSec=2 | ||
+ | |||
+ | [Install] | ||
+ | WantedBy=getty.target | ||
+ | </ | ||
+ | where: | ||
+ | * ''/ | ||
+ | |||
+ | You can now enable and start the service via: | ||
+ | <code bash> | ||
+ | systemctl enable htop.service | ||
+ | systemctl start htop.service | ||
+ | </ | ||
+ | |||
+ | and '' | ||
+ | |||
+ | ====== Set Runlevel ====== | ||
+ | |||
+ | The SystemD version of '' | ||
+ | <code bash> | ||
+ | systemctl isolate multi-user.target | ||
+ | </ | ||
+ | |||
+ | and the '' | ||
+ | <code bash> | ||
+ | systemctl isolate graphical.target | ||
+ | </ | ||
+ | |||
+ | ====== Make Service Depend on Network Interface ====== | ||
+ | |||
+ | Given a service file and a network interface (for example, '' | ||
+ | |||
+ | In order to do so, issue the command: | ||
+ | < | ||
+ | systemctl list-units --no-pager | ||
+ | </ | ||
+ | |||
+ | that will list all the systemd units and look for '' | ||
+ | |||
+ | If it is a configured network interface, then something along the lines: | ||
+ | < | ||
+ | sys-devices-virtual-net-br0.device loaded active plugged | ||
+ | </ | ||
+ | will be printed by the previous command. | ||
+ | |||
+ | In order to modify the service file, add '' | ||
+ | < | ||
+ | [Unit] | ||
+ | BindsTo=sys-devices-virtual-net-br0.device | ||
+ | After=sys-devices-virtual-net-br0.device | ||
+ | </ | ||
+ | |||
+ | ====== Create a Custom Target ====== | ||
+ | |||
+ | A custom target can be created that will run at the end when all other services have completed. This is useful to ensure that running a program is the last thing that is performed as part of the boot up process. | ||
+ | |||
+ | Let's assume that the target name will be " | ||
+ | |||
+ | First, the target is defined by creating a target file at ''/ | ||
+ | < | ||
+ | [Unit] | ||
+ | Description=Microscope Target | ||
+ | Requires=multi-user.target | ||
+ | After=multi-user.target | ||
+ | AllowIsolate=yes | ||
+ | </ | ||
+ | |||
+ | Now, the " | ||
+ | |||
+ | < | ||
+ | [Unit] | ||
+ | Description=Microscope | ||
+ | After=microscope_clone.service | ||
+ | Before=microscope_button.service | ||
+ | |||
+ | [Service] | ||
+ | ExecStart=/ | ||
+ | Restart=always | ||
+ | RestartSec=10 | ||
+ | StandardOutput=syslog | ||
+ | StandardError=syslog | ||
+ | SyslogIdentifier=microscope | ||
+ | User=root | ||
+ | Group=root | ||
+ | Environment=PATH=/ | ||
+ | |||
+ | [Install] | ||
+ | WantedBy=microscope.target | ||
+ | |||
+ | </ | ||
+ | |||
+ | The service file starts '' | ||
+ | |||
+ | <code bash> | ||
+ | ln -sf / | ||
+ | </ | ||
+ | |||
+ | To make sure the changes are picked up, SystemD will be reloaded: | ||
+ | <code bash> | ||
+ | systemctl daemon-reload | ||
+ | </ | ||
+ | |||
+ | Finally, the final target can be re-mapped from the default '' | ||
+ | <code bash> | ||
+ | systemctl set-default microscope.target | ||
+ | </ | ||
+ | |||
+ | The machine can be now either be rebooted or the changes can be applied immediately by issuing: | ||
+ | <code bash> | ||
+ | systemctl isolate microscope.target | ||
+ | </ | ||
+ | |||
+ | ====== Attempting to Start a Service Indefinitely ====== | ||
+ | |||
+ | The following configuration: | ||
+ | < | ||
+ | [Unit] | ||
+ | StartLimitIntervalSec=0 | ||
+ | |||
+ | [Service] | ||
+ | RestartSec=10 | ||
+ | |||
+ | </ | ||
+ | when added to a service file, will have the effect of attempting to start the service successfully indefinitely by attempting a start the service every '' | ||
+ | |||
+ | ====== Custom Service Folders ====== | ||
+ | |||
+ | One of the cool thing that one could do would be to specify alternative directories to hold service files that are meant for groups of services pertaining to projects. Currently, the location to place service files using SystemD is ''/ | ||
+ | |||
+ | The solution is to specify an additional service file path at boot time. In order to do this, create the directory path ''/ | ||
+ | <code bash> | ||
+ | [Manager] | ||
+ | ManagerEnvironment=" | ||
+ | |||
+ | </ | ||
+ | where: | ||
+ | * ''/ | ||
+ | |||
+ | Note that the colon at the end '':'' | ||
+ | |||
+ | After a system reboot, service or unit files ca be placed in, following the example, the directory ''/ | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ |
For the contact, copyright, license, warranty and privacy terms for the usage of this website please see the contact, license, privacy, copyright.