SYSTEMD.SERVICE(5) systemd.service SYSTEMD.SERVICE(5) systemd.service -- .service , <<.service>>, , systemd. , . . systemd.unit(5), . [Unit] [Install]. [Service]. systemd.exec(5), , , systemd.kill(5), , , , systemd.resource-control(5), , . SysV init, systemd , SysV ( , <<.service>>); . systemd-sysv-generator(8). systemd-run(1) .service .scope . systemd , <<@.service>>. <<>>, <<>>. 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= ). o forking, , , -- dbus . , ExecStart=, fork(), . , . , , . UNIX. , PIDFile=, systemd . , . o oneshot simple. , . , . RemainAfterExit=. Type=oneshot , Type=, ExecStart=. , RemainAfterExit=, <>, <> <> <>, , . , , , ( RemainAfterExit=) , <<>>. o dbus simple; , BusName=, , . , BusName=. , , dbus.socket. , , . , . , , , - , . , , , SIGTERM ( - , KillSignal=). o notify exec. , - <> sd_notify(3) . systemd -. , NotifyAccess= (. ) , systemd. NotifyAccess= none, main. , , notify-reload. o notify-reload notify. , : SIGHUP UNIX , , . - sd_notify(3). <> <> ( CLOCK_MONOTONIC clock_gettime(2)) , . , -, <>. ExecReload= . ReloadSignal=, . . o idle simple. , , . . , , , ' , . Type=notify , , ( , ). , ( , 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/. 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=, , , , . - ( <<->>) , , , . ExecStart= , ExecStartPre=, <<->>, . ExecStartPost= , ExecStart=, Type= ( Type=simple, ExecStart= Type=oneshot, Type=forking, <> Type=notify/Type=notify-reload, BusName= Type=dbus). , ExecStartPre= . , , ExecStartPre=, , . , - , ExecStartPre=, ExecStart= ExecStartPost=, ( <<->>, . ) , , ExecStopPost=. ExecStop= . , ExecStartPost= Before=/After=. ExecCondition= ' , ExecStartPre=, , ExecStart=, , , , . 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=, ExecReload= , , . , dbus-broker(1) : ExecReload=busctl call org.freedesktop.DBus \ /org/freedesktop/DBus org.freedesktop.DBus \ ReloadConfig 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>>. 100 . RestartSteps= , RestartSec= RestartMaxDelaySec=. 0 . 0. , RestartMaxDelaySec=. 254. RestartMaxDelaySec= RestartSteps=. , RestartSec=, <> . <>. , RestartSteps=. 254. TimeoutStartSec= . , , , . TimeoutStartFailureMode=. , <<5min 20s>>. <> . DefaultTimeoutStartSec= , , Type=oneshot. (. systemd-system.conf(5)). Type=notify/Type=notify-reload <>, TimeoutStartSec=. TimeoutStartSec=, TimeoutStartSec=, , <> , <>. (. sd_notify(3)). 188. TimeoutStopSec= . -, ExecStop=. , ExecStop= , SIGTERM. ExecStop=, SIGTERM . TimeoutStopFailureMode=. -, . , SIGKILL (. KillMode= systemd.kill(5)). , , <<5min 20s>>. <> . DefaultTimeoutStopSec= (. systemd-system.conf(5)). Type=notify/Type=notify-reload <>, TimeoutStopSec=. TimeoutStopSec=, TimeoutStopSec=, , <> , (. sd_notify(3)). 188. TimeoutAbortSec= , (. WatchdogSec=). TimeoutStopSec=, , . SIGKILL (. KillMode= systemd.kill(5)). . TimeoutAbortSec= , , . , , <<5min 20s>>. , TimeoutStopSec=. <> . DefaultTimeoutAbortSec= (. systemd-system.conf(5)). Type=notify/Type=notify-reload SIGABRT ( , ), <>, TimeoutAbortSec=. TimeoutAbortSec=, TimeoutAbortSec=, , <> , (. 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, . <> ( ), . Type=notify/Type=notify-reload <>, RuntimeMaxSec=. RuntimeMaxSec=, RuntimeMaxSec=, , <> , <> ( ). (. sd_notify(3)). 229. RuntimeRandomizedExtraSec= RuntimeMaxSec= 0 ( ). RuntimeMaxSec=, . 250. WatchdogSec= . . sd_notify(3) <> ( << '>>). , SIGABRT ( , WatchdogSignal=). Restart= on-failure, on-watchdog, on-abnormal always, . , , WATCHDOG_USEC=. ', . , NotifyAccess= (. ), , systemd. NotifyAccess= , main. 0, , . , ' . . sd_watchdog_enabled(3), . sd_event_set_watchdog(3) . Restart= , , , . , , ExecStartPre=, ExecStartPost=, ExecStop=, ExecStopPost= ExecReload=. systemd (, ), . << '>> , . 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 | +--------------------------------------------------------+----+--------+------------+------------+-------------+----------+-------------+ , , RestartPreventExitStatus= (. ) systemctl stop . , RestartForceExitStatus= (. ). , , StartLimitIntervalSec= StartLimitBurst=, . systemd.unit(5), . on-failure , . , ( ) on-abnormal. RestartMode= -, : o normal ( ), . o direct, , . ExecStopPost=. OnSuccess= OnFailure= . , , , . direct, . 254. SuccessExitStatus= , , , , 0 Type=oneshot, SIGHUP, SIGINT, SIGTERM SIGPIPE. , , . . << >> (<>) systemd.exec(5), ( <> <>). . signal(7), . , ' , , , , 0 ' <> ( , <<0/SUCCESS>> ) 1 ' <> ( , <<1/FAILURE>>) . , , . , '. , -- . 1. SuccessExitStatus= SuccessExitStatus=TEMPFAIL 250 SIGKILL 75 (TEMPFAIL), 250 SIGKILL . : systemd-analyze exit-status. 189. RestartPreventExitStatus= , , , , , Restart=. . . , , , . : RestartPreventExitStatus=1 6 SIGABRT , 1 6 SIGABRT . -- '. , , . , , ExecStartPre=, ExecStartPost=, ExecStop=, ExecStopPost= ExecReload=, , , ExecStart= ( Type=, PIDFile=, ...) . 189. RestartForceExitStatus= , , , Restart= . RestartPreventExitStatus=. 215. RootDirectoryStartOnly= . (true), , RootDirectory= (. systemd.exec(5), ), , ExecStart=, ExecStartPre=, ExecStartPost=, ExecReload=, 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() ' , , , , PID 1 , , , . , , , main exec. , sd_notify() , ' , , , NotifyAccess=all. , ' , sd_notify_barrier(). . sd_notify_barrier() , , ' . Sockets= , . , , , , ( , , ), . , . , , , . , , Service= .socket Sockets= .service, . -- '. , (, ) . FileDescriptorStoreMax= , <> 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, , ' ( ). . systemctl clean --what=fdstore ..., . 254. USBFunctionDescriptors= , USB FunctionFS[2] USB. ListenUSBFunction=. ep0 , . 227. USBFunctionStrings= , FunctionFS USB. USBFunctionDescriptors=, . 227. OOMPolicy= ' (OOM) OOM systemd-oomd.service(8). Linux, ', , ' , ' '. , systemd-oomd.service , ' , , , , . : continue, stop kill. continue, OOM, , . stop, , . kill, OOM, memory.oom.group 1; . Control Group v2[3]. DefaultOOMPolicy= systemd-system.conf(5), , Delegate=, continue. OOMScoreAdjust= , OOM Linux. . systemd.exec(5), . systemd-oomd.service(8); OOM-, , , systemd-oomd cgroup, ' . 243. OpenFile= <<[:--:]>>, o <<>> AF_UNIX ; o <<-->> , ' ; - ASCII, <<:>>; , 255 ; ' , , ; o <<>> ; <>, <>, <>, <>; , rw; <>, . . , . , connect(). . sd_listen_fds(3), , . , ( , ). ; , . , , . 253. ReloadSignal= UNIX, . SIGHUP. , Type=notify-reload, . . 253. systemd.unit(5), systemd.exec(5) systemd.kill(5), . ExecStart=, ExecStartPre=, ExecStartPost=, ExecReload=, ExecStop= ExecStopPost=. ' , ( ). : <<\;>>. , <<>> (<>) systemd.syntax(7). , , . , , . , , <<<>>, <<<<>>, <<>>> <<>>>>, <<|>>, <<&>>. , . : 2. +----------------------+------------------------------------------------+ | | | +----------------------+------------------------------------------------+ |"@" | | | | | | | | | | <<@>>, | | | | | | | | | argv[0] | | | | | | ( | | | | | | ), | | | | | | . | +----------------------+------------------------------------------------+ |"-" | | | | | | | | | | <<->>, | | | , | | | | | | | | | | | | | | | ( | | | | | | | | | | | | | | | | | | ), | | | , | | | | | | | | | | | | | | | | | | . | +----------------------+------------------------------------------------+ |":" | | | | | | | | | | <<:>>, | | | | | | | | | ( | | | | | | << | | | >> ). | +----------------------+------------------------------------------------+ |"+" | | | | | | | | | | <<+>>, | | | | | | | | | | | | . | | | | | | | | | , | | | | | | User=, Group=, | | | CapabilityBoundingSet= | | | | | | | | | | | | | | | ( PrivateDevices=, | | | PrivateTmp=), | | | | | | | | | | | | ( | | | | | | - | | | ExecStart=, ExecStop=, ...). | | | , , | | | | | | | | | , | | | | | | | | | , | | | DevicePolicy=; | | | . systemd.resource-control(5), | | | | | | | | | . | +----------------------+------------------------------------------------+ |"!" | | | | <<+>>, | | | | | | | | | , | | | | | | | | | | | | | | | . , | | | <<+>>, | | | <> | | | | | | | | | User=, | | | Group= SupplementaryGroups=, | | | | | | , | | | | | | | | | | | | | | | . , | | | | | | | | | DynamicUser=, | | | | | | | | | / | | | | | | | | | , | | | | | | | | | | | | | | | | | | . | +----------------------+------------------------------------------------+ |"!!" | | | | | | | <>, , | | | | | | , | | | | | | | | | | | | , | | | | | | AmbientCapabilities=. | | | | | | | | | , | | | | | | | | | | | | , | | | , | | | | | | | | | , | | | | | | | | | , | | | | | | | | | | | | . | | | , | | | <> | | | , | | | | | | | | | | | | , | | | | | | SystemCallFilter= | | | CapabilityBoundingSet= | | | | | | , | | | | | | | | | | | | | | | | | | , | | | | | | | | | . | | | , | | | | | | , | | | | | | | | | | | | | | | , | | | AmbientCapabilities= | | | | | | | | | . | | | | | | | | | | | | , <> | | | | | | | | | . | +----------------------+------------------------------------------------+ <<@>>, <<->>, <<:>> <<+>>/<>/<> - . , <<+>>, <>, <>. . () , , . /usr/local/bin/, /usr/bin/, /bin/ , /usr/bin/ /bin/, sbin/ , bin/ sbin/. , , - <<>> . . : systemd-path search-binaries-default. <<%>>, systemd.unit(5). . <<${}>>, , ; ( ) , , , . <<$FOO>>, , ; , -- . , . : Environment="ONE=one" 'TWO=two two' ExecStart=echo $ONE $TWO ${TWO} /bin/echo : <>, <>, <> <>. : 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=. , << >> (<>) systemd.exec(5), << >> ( , , $USER, $TERM). , . , . : ExecStart=sh -c 'dmesg | tac' : ExecStart=echo one ; echo "two two" echo , : "one" "two two", . , Type=oneshot. : Type=oneshot ExecStart=:echo $USER ; -false ; +:@true $TEST /usr/bin/echo <<$USER>> (<<:>> ), /usr/bin/false ( , <<->> ) /usr/bin/true ( <<$TEST>> argv[0]). : ExecStart=echo / >/dev/null & \; \ ls echo ' : "/", ">/dev/null", "&", ";" "ls". 2. , /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/notify-reload, systemd, Type=forking, , Type=dbus, DBus, . . . 3. oneshot , , . Type=oneshot. , . : [Unit] Description= [Service] Type=oneshot ExecStart=/usr/sbin/foo-cleanup [Install] WantedBy=multi-user.target , systemd , <<>>, , , . <<>> -- <<>>. , , . Type=oneshot , ExecStart=. (Type=oneshot), . Type=oneshot not Restart=always Restart=on-success. 4. , , , , , <<>>. . , , , . 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 . 5. ( , ). Type=forking . systemd , , . , ( RemainAfterExit=no), . . , , systemd . $MAINPID ExecReload=, ExecStop= . , systemd , , . $MAINPID . , PID, systemd PID . , PIDFile= . , . , systemd , . , : [Unit] Description= [Service] Type=forking ExecStart=/usr/sbin/my-simple-daemon -d [Install] WantedBy=multi-user.target , systemd.kill(5), , , systemd . 6. DBus , DBus, Type=dbus BusName= . ( ). systemd , . DBus: [Unit] Description= DBus [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 . 7. , systemd Type=simple , -- systemd , . , systemd , systemd . , , Type=notify Type=notify-reload. : [Unit] Description= [Service] Type=notify ExecStart=/usr/sbin/simple-notifying-service [Install] WantedBy=multi-user.target , systemd, systemd , , . , , sd_notify(3). systemd , <<>>, . , systemd.kill(5), , , systemd . . 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 FunctionFS https://docs.kernel.org/usb/functionfs.html 3. Control Group v2 https://docs.kernel.org/admin-guide/cgroup-v2.html Yuri Chornoivan ; , GNU General Public License Version 3 . . , , : . systemd 255 SYSTEMD.SERVICE(5)