This shows you the differences between two versions of the page.
— | fuss:systemd [2024/12/03 15:25] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
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 '' | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ |
For the contact, copyright, license, warranty and privacy terms for the usage of this website please see the contact, license, privacy, copyright.