SYSTEMD.SERVICE(5) systemd.service SYSTEMD.SERVICE(5) systemd.service - service.service ".service" systemd . . systemd.unit(5) . [Unit] [Install]. [Service]. systemd.exec(5) systemd.kill(5) systemd.resource-control(5) . systemd-run(1) .service .scope . systemd "service@argument.service". "" argument "". dhcpcd@.service . " " %. systemd.unit(5) . : o Type=dbus Requires= After= dbus.socket. o .socket After= . .socket Sockets= Wants= After= . systemd.exec(5) systemd.resource-control(5). DefaultDependencies=no: o Requires= After= sysinit.target After= basic.target Conflicts= Before= shutdown.target. . . o ( "@" ) ( systemd.slice(5)) . . DefaultDependencies=no DefaultDependencies=no Slice=system.slice ( ) . systemd.resource-control(5). [Unit] [Install] systemd.unit(5). [Service] . . systemd.exec(5) systemd.kill(5) systemd.resource-control(5). [Service] : Type= . : simple exec forking oneshot dbus notify notify-reload idle: o simple ( ExecStart= Type= BusName= ) ( fork() execve() ). Type=exec . ExecStart= . ( systemd ) . systemctl start simple ( User= ). o exec simple . . ( : simple fork() exec fork() execve() .) systemctl start exec ( User= ). ( LoadCredential= systemd.exec(5) ). o forking . notify notify-reload dbus . ExecStart= fork() . . . UNIX . PIDFile= systemd . . o oneshot exec . . RemainAfterExit= . Type=oneshot Type= ExecStart=. RemainAfterExit= "" " " " " "" . ( RemainAfterExit=) . o dbus simple BusName= . BusName=. dbus.socket. . . . SIGTERM ( KillSignal=) . o notify exec "READY=1" sd_notify(3) . systemd . NotifyAccess= ( ) systemd. NotifyAccess= none main. notify-reload . o notify-reload notify : UNIX SIGHUP . sd_notify(3) "RELOADING=1" "MONOTONIC_USEC=" ( CLOCK_MONOTONIC clock_gettime(2)) . "READY=1". ExecReload= . ReloadSignal= . o idle simple . . 5 . Type=exec ( ) . ( execve()) ( IPC IPC -- ) . notify notify-reload dbus ( D-Bus) . notify/notify-reload ( sd_notify() ) -- forking : UNIX . simple . ( idle oneshot .) ( User= Group= libc NSS) IPC "" . simple . ExitType= . : main cgroup: o main () Type=. Type=oneshot. o cgroup cgroup . ExitType=main . ExitType= cgroup . . 250. RemainAfterExit= . no. GuessMainPID= systemd (PID) . Type=forking PIDFile= PID PID . . PID . yes. PIDFile= PID . Type= forking. /run/. /run/ $XDG_RUNTIME_DIR . PID . . PID : ( ) PID . PID . Type=notify Type=notify-reload Type=simple PID . BusName= D-Bus . Type= dbus. D-Bus. systemctl service-log-level/service-log-target . ExecStart= . Type= oneshot . Type=oneshot . . ExecStart= RemainAfterExit=yes ExecStop= . ( ExecStart= ExecStop= .) . ( "-") . Type=forking . ExecStartPre= ExecStartPost= ExecStart= . ExecStart=. ( Type=) . ( "-") . ExecStart= ExecStartPre= "-" . ExecStartPost= ExecStart= Type= ( Type=simple Type=idle ExecStart= Type=oneshot Type=forking "READY=1" Type=notify/Type=notify-reload BusName= Type=dbus). ExecStartPre= . ExecStartPre= . ExecStartPre= ExecStart= ExecStartPost= ( "-" ) ExecStopPost= ExecStop=. ExecStartPost= Before=/After=. ExecCondition= ExecStartPre=. ExecStart=. ( Type=) . ExecStartPre= : ExecCondition= 1 254 () . ExecCondition= 255 ( ) ( ). 0 SuccessExitStatus= . ExecStartPre= ExecCondition=. ExecCondition= ExecStopPost= . 243. ExecReload= . ExecStart= . . ExecStart=. : $MAINPID : ExecReload=kill -HUP $MAINPID ( ) . Type=notify-reload ExecReload= . dbus-broker(1) : ExecReload=busctl call org.freedesktop.DBus \ /org/freedesktop/DBus org.freedesktop.DBus \ ReloadConfig Type=notify-reload . "RELOADING=1" ExecReload= "READY=1". ExecReloadPost= . ExecReload=. 259. ExecStop= ExecStart=. ExecStart= . . KillMode= ( systemd.kill(5)). KillSignal= RestartKillSignal= . ( $MAINPID ). ( ) . KillMode= KillSignal= RestartKillSignal= . . ExecStop= . ExecStart= ExecStartPre= ExecStartPost= ( "-" ) . ExecStopPost= . . . $MAINPID systemd . . ExecStop= ExecStopPost= . . ExecStopPost= . ExecStopPost= . ExecStop= ExecStop= . ExecStart=. . . -- ExecStop= -- . . . . $SERVICE_RESULT $EXIT_CODE $EXIT_STATUS systemd.exec(5) . ExecStopPost= Before=/After=. RestartSec= ( Restart=). "5min 20s". 100ms. RestartSteps= RestartSec= RestartMaxDelaySec=. 0 . 0. : 3 5 . : RestartSec=10s RestartSteps=4 RestartMaxDelaySec=160s : 10 20 40 80 160 160 160 . 2. ratio (RestartMaxDelaySec / RestartSec)^(1 / RestartSteps). () RestartMaxDelaySec= RestartSteps + 1. RestartMaxDelaySec= RestartSec= . 254. RestartMaxDelaySec= RestartSteps=. RestartSec= "infinity" . "infinity". RestartSteps= RestartSec= . 254. TimeoutStartSec= . . TimeoutStartFailureMode=. "5min 20s". "infinity" . DefaultTimeoutStartSec= Type=oneshot ( systemd-system.conf(5)). Type=notify/Type=notify-reload "EXTEND_TIMEOUT_USEC=..." TimeoutStartSec=. TimeoutStartSec= TimeoutStartSec= "EXTEND_TIMEOUT_USEC=..." "READY=1". ( sd_notify(3)). ExecReload= Type=notify-reload. . systemctl reload. 188. TimeoutStopSec= . ExecStop=. ExecStop= SIGTERM. ExecStop= SIGTERM . TimeoutStopFailureMode=. . SIGKILL ( KillMode= systemd.kill(5)). "5min 20s". "infinity" . DefaultTimeoutStopSec= ( systemd-system.conf(5)). Type=notify/Type=notify-reload "EXTEND_TIMEOUT_USEC=..." TimeoutStopSec=. TimeoutStopSec= TimeoutStopSec= "EXTEND_TIMEOUT_USEC=..." ( sd_notify(3)). 188. TimeoutAbortSec= ( WatchdogSec=). TimeoutStopSec= . SIGKILL ( KillMode= systemd.kill(5)). . TimeoutAbortSec= . "5min 20s". TimeoutStopSec=. "infinity" . DefaultTimeoutAbortSec= ( systemd-system.conf(5)). Type=notify/Type=notify-reload SIGABRT ( ) "EXTEND_TIMEOUT_USEC=..." TimeoutAbortSec=. TimeoutAbortSec= TimeoutAbortSec= "EXTEND_TIMEOUT_USEC=..." ( sd_notify(3)). 243. TimeoutSec= TimeoutStartSec= TimeoutStopSec= . TimeoutStartFailureMode=, TimeoutStopFailureMode= TimeoutStartSec= TimeoutStopSec= . terminate abort kill. terminate. terminate KillSignal= ( SIGTERM systemd.kill(5)). FinalKillSignal= TimeoutStopSec=. abort WatchdogSignal= TimeoutAbortSec= FinalKillSignal=. . kill FinalKillSignal= . . 246. RuntimeMaxSec= . . Type=oneshot ( TimeoutStartSec= ). "infinity" () . Type=notify/Type=notify-reload "EXTEND_TIMEOUT_USEC=..." RuntimeMaxSec=. RuntimeMaxSec= RuntimeMaxSec= "EXTEND_TIMEOUT_USEC=..." "STOPPING=1" ( ). ( sd_notify(3)). 229. RuntimeRandomizedExtraSec= RuntimeMaxSec= 0 (). RuntimeMaxSec= . 250. WatchdogSec= . . sd_notify(3) "WATCHDOG=1" ( "ping "). SIGABRT ( WatchdogSignal=). Restart= on-failure on-watchdog on-abnormal always . WATCHDOG_USEC=. ping . NotifyAccess= ( ) systemd. NotifyAccess= main. 0 . . sd_watchdog_enabled(3) . sd_event_set_watchdog(3) . Restart= . ExecStartPre= ExecStartPost= ExecStop= ExecStopPost= ExecReload=. systemd ( ) . "ping keep-alive" . no on-success on-failure on-abnormal on-watchdog on-abort always. no () . on-success . : o 0 o Type=oneshot SIGHUP SIGINT SIGTERM SIGPIPE o SuccessExitStatus=. on-failure ( ) ( ) . on-abnormal ( ) . on-abort . on-watchdog . always . Type=oneshot always on-success . 1. Restart= +--------------------------------------+----+--------+------------+------------+-------------+----------+-------------+ | | no | always | on-success | on-failure | on-abnormal | on-abort | on-watchdog | |/ | | | | | | | | | | | | | | | | | +--------------------------------------+----+--------+------------+------------+-------------+----------+-------------+ | | | X | X | | | | | | | | | | | | | | +--------------------------------------+----+--------+------------+------------+-------------+----------+-------------+ | | | X | | X | | | | | | | | | | | | | +--------------------------------------+----+--------+------------+------------+-------------+----------+-------------+ | | | X | | X | X | X | | | | | | | | | | | +--------------------------------------+----+--------+------------+------------+-------------+----------+-------------+ | | | X | | X | X | | | +--------------------------------------+----+--------+------------+------------+-------------+----------+-------------+ | | | X | | X | X | | X | +--------------------------------------+----+--------+------------+------------+-------------+----------+-------------+ | | | X | | X | X | | | | | | | | | | | | |(OOM) | | | | | | | | +--------------------------------------+----+--------+------------+------------+-------------+----------+-------------+ RestartPreventExitStatus= ( ) systemctl stop . RestartForceExitStatus= ( ). StartLimitIntervalSec= StartLimitBurst= systemd.unit(5) . on-failure . ( ) on-abnormal . RestartMode= : o normal () / . 254. o direct / . ExecStopPost=. OnSuccess= OnFailure=. . . 254. o debug $DEBUG_INVOCATION=1 . systemd . normal . 257. 254. SuccessExitStatus= 0 Type=oneshot SIGHUP SIGINT SIGTERM SIGPIPE. . systemd.exec(5) ( "EXIT_" "EX_" ). signal(7) . 0 "SUCCESS" ( "0/SUCCESS" ) 1 "FAILURE" ( "1/FAILURE") . . . . 1. SuccessExitStatus= SuccessExitStatus=TEMPFAIL 250 SIGKILL 75 (TEMPFAIL) 250 SIGKILL . : systemd-analyze exit-status . 189. RestartPreventExitStatus= Restart=. . . . . ExecStartPre= ExecStartPost= ExecStop= ExecStopPost= ExecReload= ExecStart= ( Type= PIDFile= ...). 189. RestartForceExitStatus= Restart=. RestartPreventExitStatus=. Type=oneshot . 215. RootDirectoryStartOnly= . (true) RootDirectory= ( systemd.exec(5) ) ExecStart= ExecStartPre= ExecStartPost= ExecReload= ExecReloadPost= ExecStop= ExecStopPost= . (false) . false. NonBlocking= O_NONBLOCK . (true) >= 3 ( stdin stdout stderr) ( FileDescriptorStoreMax= ) O_NONBLOCK . systemd.socket(5) . false. ( Sockets= ) NonBlocking= O_NONBLOCK O_NONBLOCK . NonBlocking= . NotifyAccess= sd_notify(3). none () main exec all. none . main . exec Exec*=. all . Type=notify/Type=notify-reload WatchdogSec= ( ). NotifyAccess= main. sd_notify() 1 (PID 1) . main exec. sd_notify() NotifyAccess=all . sd_notify_barrier(). . sd_notify_barrier() . Sockets= . ( ) . . . : Service= .socket Sockets= .service . . ( ) . FileDescriptorStoreMax= "FDSTORE=1" sd_pid_notify_with_fds(3). . . RuntimeDirectory= memfd_create(2). 0 . ( sd_listen_fds(3) ). POLLHUP POLLERR ( FileDescriptorStorePreserve= ). NotifyAccess= ( ) systemd. NotifyAccess= main. fdstore systemd-analyze(1) . IPC . . ( ) . $FDSTORE . systemd.exec(5) . [1]. 219. FileDescriptorStorePreserve= no yes restart ( ). no restart () . yes . EPOLLHUP EPOLLERR. systemctl clean --what=fdstore ... . 254. USBFunctionDescriptors= USB FunctionFS[2] USB. ListenUSBFunction=. ep0 . 227. USBFunctionStrings= USB FunctionFS. USBFunctionDescriptors= . 227. OOMPolicy= (OOM) OOM systemd-oomd.service(8). . systemd-oomd.service . continue stop kill. continue (OOM killer) . stop . kill memory.oom.group 1 Control Group v2[3]. stop kill oom-kill Restart=. DefaultOOMPolicy= systemd-system.conf(5) Delegate= continue. OOMScoreAdjust= OOM . systemd.exec(5) . systemd-oomd.service(8). OOM systemd-oomd cgroup . 243. OpenFile= "path[:fd-name:options]" : o "path" AF_UNIX o "fd-name" ASCII ":" 255 o "options" "read-only" "append" "truncate" "graceful" rw "graceful" /. . . connect() . sd_listen_fds(3) . / ( ...). . . 253. ReloadSignal= UNIX . SIGHUP. Type=notify-reload . 253. RefreshOnReload= systemd.exec(5). extensions credentials . ("~") . extensions. . (ExtensionImages=/ExtensionDirectories= extensions LoadCredential=/ImportCredential=/ SetCredential= ( Encrypted) credentials) . yes . (ExecReload= Type=notify-reload) . 260. systemd.unit(5) systemd.exec(5) systemd.kill(5) . ExecStart= ExecStartPre= ExecStartPost= ExecReload= ExecStop= ExecStopPost= ExecCondition=. . "Quoting" systemd.syntax(7). . . "<" "<<" ">" ">>" "|" "&" . . : 2. +----------------------+---------------------------------------+ | | | +----------------------+---------------------------------------+ |"@" | | | | | | | | | | "@" | | | | | | | | | argv[0] | | | | | | | | | ( | | | | | | ) | | | | | | | | | | | | | | | "|" | | | | | | | | | | | | | | | | | | | | | | | | "-" argv[0]. | +----------------------+---------------------------------------+ |"-" | | | | | | | | | | "-" | | | | | | | | | | | | ( | | | | | | | | | | | | ) | | | | | | | | | | | | | | | . | +----------------------+---------------------------------------+ |":" | | | | | | | | | | ":" | | | | | | ( | | | | | | ). | +----------------------+---------------------------------------+ |"+" | | | | | | | "+" | | | | | | | | | | | | . | | | | | | | | | | | | User= | | | Group= | | | CapabilityBoundingSet= | | | | | | | | | | | | ( | | | PrivateDevices= PrivateTmp=) | | | | | | | | | | | | ( | | | | | | ExecStart= | | | ExecStop= ... ). | | | | | | | | | | | | | | | | | | | | | | | | DevicePolicy= | | | systemd.resource-control(5) | | | | | | . | +----------------------+---------------------------------------+ |"!" | | | | "+" | | | | | | | | | | | | | | | | | | . | | | | | | "+" | | | "!" | | | User= Group= | | | SupplementaryGroups= | | | | | | | | | | | | | | | | | | . | | | | | | | | | DynamicUser= | | | | | | | | | / | | | | | | | | | | | | | | | | | | | | | | | | . | +----------------------+---------------------------------------+ |"|" | "|" | | | | | | | | | | | | | | | User= . | | | | | | | | | | | | ("-c") | | | | | | . | | | | | | "@" | | | | | | "-" argv[0] | | | | | | | | | . | +----------------------+---------------------------------------+ "@" "|" "-" ":" "+"/"!" . "+" "!" . . () . /usr/local/bin/ /usr/bin/ sbin/ ( bin/ sbin/ ). "" . : systemd-path search-binaries-default. "%" systemd.unit(5). ";" "\;". . "${FOO}" ( ) . "$FOO" . . : Environment="ONE=one" 'TWO=two two' ExecStart=echo $ONE $TWO ${TWO} /bin/echo : "one" "two" "two" "two two". : Environment=ONE='one' "TWO='two two' too" THREE= ExecStart=/bin/echo ${ONE} ${TWO} ${THREE} ExecStart=/bin/echo $ONE $TWO $THREE /bin/echo "'one'" "'two two' too" "" "one" "two two" "too". ":" "$$". . ( ) . Environment= EnvironmentFile=. "Environment variables in spawned processes" systemd.exec(5) " " ( $USER $TERM). "|" . . : ExecStart=sh -c 'dmesg | tac' : ExecStart=echo one ExecStart=echo "two two" echo : "one" "two two" . Type=oneshot. : Type=oneshot ExecStart=:echo $USER ExecStart=-false ExecStart=+:@true $TEST /usr/bin/echo "$USER" (":" ) /usr/bin/false ( "-" ) /usr/bin/true ( "$TEST" argv[0]). : ExecStart=echo / >/dev/null & \; \ ls echo : "/" ">/dev/null" "&" ";" "ls". 3. /usr/sbin/foo-daemon. Type= Type=simple. systemd . [Unit] Description=Foo [Service] ExecStart=/usr/sbin/foo-daemon [Install] WantedBy=multi-user.target systemd systemd . ( ) Type=forking . ExecStop= systemd SIGTERM SIGKILL. systemd.kill(5) . . Type=notify/Type=notify-reload systemd Type=forking Type=dbus DBus . . 4. . Type=oneshot. . : [Unit] Description=Cleanup old Foo data [Service] Type=oneshot ExecStart=/usr/sbin/foo-cleanup [Install] WantedBy=multi-user.target systemd " " . " " "". . Type=oneshot ExecStart= . (Type=oneshot) . Type=oneshot Restart=always Restart=on-success . 5. "". . . systemd RemainAfterExit=yes systemd . Type=oneshot Type=simple. Type=oneshot systemd . Type=simple . . [Unit] Description=Simple firewall [Service] Type=oneshot RemainAfterExit=yes ExecStart=/usr/local/sbin/simple-firewall-start ExecStop=/usr/local/sbin/simple-firewall-stop [Install] WantedBy=multi-user.target systemctl start . 6. / ( ) . Type=forking . systemd . ( RemainAfterExit=no) . . systemd . $MAINPID ExecReload= ExecStop= . systemd . $MAINPID . PID systemd (PID) . PIDFile= . . systemd . : [Unit] Description=My Simple Daemon [Service] Type=forking ExecStart=/usr/sbin/my-simple-daemon -d [Install] WantedBy=multi-user.target systemd.kill(5) systemd . 7. DBus DBus Type=dbus BusName= . ( ). systemd . DBus : [Unit] Description=Simple DBus Service [Service] Type=dbus BusName=org.example.simple-dbus-service ExecStart=/usr/sbin/simple-dbus-service [Install] WantedBy=multi-user.target (bus-activatable) [Install] systemd SystemdService= DBus (/usr/share/dbus-1/system-services/org.example.simple-dbus-service.service): [D-BUS Service] Name=org.example.simple-dbus-service Exec=/usr/sbin/simple-dbus-service User=root SystemdService=simple-dbus-service.service systemd.kill(5) systemd . 8. systemd Type=simple systemd . systemd systemd . Type=notify Type=notify-reload . : [Unit] Description=Simple Notifying Service [Service] Type=notify-reload ExecStart=/usr/sbin/simple-notifying-service [Install] WantedBy=multi-user.target systemd systemd . sd_notify(3). systemd ' ' . systemd.kill(5) systemd . sd_notify(3) libsystemd(3) Interface Portability and Stability Promise[4] . sd_notify(3). systemd(1), systemctl(1), systemd-system.conf(5), systemd.unit(5), systemd.exec(5), systemd.resource-control(5), systemd.kill(5), systemd.directives(7), systemd-run(1) 1. https://systemd.io/FILE_DESCRIPTOR_STORE 2. USB (USB FunctionFS) https://docs.kernel.org/usb/functionfs.html 3. 2 https://docs.kernel.org/admin-guide/cgroup-v2.html 4. https://systemd.io/PORTABILITY_AND_STABILITY/ 3 . . : . systemd 260.2 SYSTEMD.SERVICE(5)