meta data for this page
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
linux:systemd [2015/08/17 09:11] – niziak | linux:systemd [2024/02/09 19:24] (current) – niziak | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ==== start/ stop ==== | + | ====== systemd ====== |
+ | |||
+ | * [[https:// | ||
+ | |||
+ | ===== HowTo ===== | ||
+ | ==== start / stop ==== | ||
+ | Rerun all generators, reload all unit files and recreate dependency tree: | ||
<code bash> | <code bash> | ||
systemctl daemon-reload | systemctl daemon-reload | ||
Line 15: | Line 21: | ||
<code bash> | <code bash> | ||
+ | systemd-analyze blame | ||
systemd-analyze critical-chain | systemd-analyze critical-chain | ||
+ | systemd-analyze critical-chain | ||
+ | systemctl list-dependencies network.service | ||
systemctl --failed | systemctl --failed | ||
</ | </ | ||
- | ==== DefaultDependencies ==== | + | <code bash> |
- | Value for unit **DefaultDependencies** is set to **yes** by default. | + | systemd-cgtop |
- | it will add following dependencies: | + | </ |
- | * **Conflicts=shutdown.target** to stop service during shutdown | + | |
- | * **Conflicts=umount.target** to umount mounts durign shutdown | + | |
- | * **Requires=basic.target** and **After=basic.target** | + | |
==== emergency mode ==== | ==== emergency mode ==== | ||
Line 44: | Line 49: | ||
< | < | ||
+ | |||
+ | Enable in u-boot: | ||
+ | < | ||
+ | |||
+ | Enable debug console on tty9 | ||
+ | <code bash> | ||
+ | |||
+ | ==== Start service when MMC card is inserted ==== | ||
+ | Create directory " | ||
+ | List of devices: <code bash> | ||
+ | |||
+ | ==== Configuration ==== | ||
+ | |||
+ | === DefaultDependencies === | ||
+ | Value for unit **DefaultDependencies** is set to **yes** by default. | ||
+ | it will add following dependencies: | ||
+ | * **Conflicts=shutdown.target** to stop service during shutdown | ||
+ | * **Conflicts=umount.target** to umount mounts durign shutdown | ||
+ | * **Requires=basic.target** and **After=basic.target** | ||
+ | |||
+ | === Unit Types === | ||
+ | * .service plain service - for running daemons | ||
+ | * .socket | ||
+ | * .device | ||
+ | * .path filesystem triggers (when file is changed) | ||
+ | * .mount | ||
+ | * .automount | ||
+ | * .swap | ||
+ | * .target | ||
+ | * .timer | ||
+ | * .snapshot | ||
+ | * .slice | ||
+ | * .scope | ||
+ | |||
+ | === [Unit] === | ||
+ | * Requires | ||
+ | * Conflicts - negative dependencies, | ||
+ | |||
+ | * Requisite - similar to require, but if not met, service will be not started (fail immediately). Usefull to perform action when removable device is inserted. | ||
+ | * Requisite=!local-fs.target | ||
+ | |||
+ | * BindsTo - similar to require, but also declares to stop unit when other units dissapers (aslo nice for removable devices handling) | ||
+ | * PartOf - stops/ | ||
+ | |||
+ | * After - start service after other services are started completely. | ||
+ | * Before | ||
+ | |||
+ | |||
+ | === [Service] === | ||
+ | * Type | ||
+ | * Type=simple | ||
+ | * Type=forking - process will spawn child and exit. Child should live as daemon. | ||
+ | * PIDFile=/ | ||
+ | * Type=oneshot - process should exit. Systemd is not waiting for finish. Like batch file. | ||
+ | * usefull for setup some things, not starting daemons. See '' | ||
+ | * Multiple ExecStart= allowed, and will be executed sequentially | ||
+ | * Type=dbus | ||
+ | * Type=notify | ||
+ | * Type=idle | ||
+ | |||
+ | |||
+ | * ExecStart= - first argument MUST be full path to executable | ||
+ | * ExecStart=-/ | ||
+ | * Multple ExecStart= are allowed, and executed sequentially. If one command fails, other lines are not executed and unit is failed. | ||
+ | * ExecStartPre= - '' | ||
+ | * ExecStartPost= - will be executed only if service has started successfully | ||
+ | * ExecStop= | ||
+ | * ExecReload= | ||
+ | |||
+ | * Nice=-20 | ||
+ | * IOSchedulingClass=0 | ||
+ | * IOSchedulingPriority=0 | ||
+ | * StandardOutput=tty |none | journal+console | ||
+ | |||
+ | * Restart=always | ||
+ | * RestartSec=10s | ||
+ | |||
+ | * RemainAfterExit=Yes - keep service active status, even all process exits. usefull for '' | ||
+ | |||
+ | |||
+ | ==== tricks ==== | ||
+ | Condition doesn' | ||
+ | If service is not started by Condtiion it is still conflicting | ||
+ | |||
+ | === Remove startup console clearing === | ||
+ | <file | / | ||
+ | |||
+ | [Service] | ||
+ | TTYVTDisallocate=no | ||
+ | </ | ||
+ | |||
+ | === udev === | ||
+ | In udev rules.d add TAG+=" | ||
+ | < | ||
+ | SUBSYSTEM==" | ||
+ | SYMLINK+=" | ||
+ | TAG+=" | ||
+ | OPTIONS+=" | ||
+ | </ | ||
+ | And now device is visible from systemd: | ||
+ | <code bash> | ||
+ | systemctl -l -a | ||
+ | dev-input-event0.device | ||
+ | dev-input-lcd_sandwich_touchscreen.device | ||
+ | </ | ||
+ | You can create refer to device, e.g. create .wants directory | ||
+ | < | ||
+ | |||
+ | === udev: start service === | ||
+ | To start service if device is inserted: | ||
+ | <file | mu.rule> | ||
+ | ..., TAG+=" | ||
+ | </ | ||
+ | |||
+ | === do not mount crypted volumes === | ||
+ | After switching to systemd by command <code bash> | ||
+ | system boot stops and waits for password for encrypted partition (with user data - no needed to system start). | ||
+ | |||
+ | To prevent automount of crypted volumes, additional parameters ' | ||
+ | <file | / | ||
+ | / | ||
+ | </ | ||
+ | |||
+ | === Debian: Set network service timeout === | ||
+ | System startup can hang forever if there is no link on ethernet cable: | ||
+ | < | ||
+ | To set timeout, add file: | ||
+ | <file | / | ||
+ | [Service] | ||
+ | TimeoutStartSec=15 | ||
+ | </ | ||
+ | |||
+ | ====== Issues ====== | ||
+ | |||
+ | ===== init.d services not started ===== | ||
+ | |||
+ | < | ||
+ | systemd-sysv-generator[320]: | ||
+ | systemd-sysv-generator[320]: | ||
+ | systemd-sysv-generator[320]: | ||
+ | </ | ||
+ | |||
+ | Reason is that some init scripts are symlinked to files located in **/opt** directory, which is a different FS (in this case BTRFS subvolume), and it was not mounted when **systemd-sysv-generator** was started. | ||
+ | |||
+ | **Solution: | ||
+ | [[https:// | ||
+ | |||
+ | > Under systemd-enabled systems, there' | ||
+ | > You also need to make sure that your filesystem' | ||
+ | |||
+ | |||
+ | |||