Systemd service life cycle
Tom H
tomh0665 at gmail.com
Sun Apr 10 11:08:17 UTC 2016
On Sun, Apr 10, 2016 at 12:15 AM, Ralf Mardorf <silver.bullet at zoho.com> wrote:
> On Sat, 9 Apr 2016 22:06:43 +0100, Colin Law wrote:
>>On 9 April 2016 at 21:59, Tom H wrote:
>>> It's for a unit that doesn't have any active processes after
>>> ExecStart runs. I've used it for setting up networking and
>>> firewalling, for example.
>>
>> Is not the tunnel an 'active process' though?
>
> Systemd considers the oneshot service as active after a process
> exited, if you use RemainAfterExit=true or RemainAfterExit=yes.
>
> A script might execute "ip link set * up; pon" or "dhcpcd *" and
> then exits. After the script exited PPPoE or DHCP are quasi active, OTOH
> a connection not necessarily is already established after a script
> exited with status 0.
Does "RemainAfterExit=yes" make more than a cosmetic difference for
something like "ip link set * up"?
For example:
# vi ubuntu-users.service
# cat ubuntu-users.service
[Unit]
Description=ubuntu-users test
[Service]
Type=oneshot
ExecStart=/sbin/ip -o ro get 8.8.8.8
# systemctl daemon-reload
# systemctl start ubuntu-users.service
# systemctl status ubuntu-users.service
● ubuntu-users.service - ubuntu-users test
Loaded: loaded (/etc/systemd/system/ubuntu-users.service; static;
vendor preset: enabled)
Active: inactive (dead)
Apr 10 11:42:17 localhost.localdomain systemd[1]: Starting ubuntu-users test...
Apr 10 11:42:17 localhost.localdomain ip[2366]: 8.8.8.8 via
192.168.1.1 dev wlp18s0 src 192.168.1.51 \ cache
Apr 10 11:42:17 localhost.localdomain systemd[1]: Started ubuntu-users test.
# vi ubuntu-users.service
# cat ubuntu-users.service
[Unit]
Description=ubuntu-users test
[Service]
Type=oneshot
ExecStart=/sbin/ip -o ro get 8.8.8.8
RemainAfterExit=true
# systemctl daemon-reload
# systemctl start ubuntu-users.service
# systemctl status ubuntu-users.service
● ubuntu-users.service - ubuntu-users test
Loaded: loaded (/etc/systemd/system/ubuntu-users.service; static;
vendor preset: enabled)
Active: active (exited) since Sun 2016-04-10 11:43:53 CEST; 2s ago
Process: 2412 ExecStart=/sbin/ip -o ro get 8.8.8.8 (code=exited,
status=0/SUCCESS)
Main PID: 2412 (code=exited, status=0/SUCCESS)
Apr 10 11:43:53 localhost.localdomain systemd[1]: Starting ubuntu-users test...
Apr 10 11:43:53 localhost.localdomain ip[2412]: 8.8.8.8 via
192.168.1.1 dev wlp18s0 src 192.168.1.51 \ cache
Apr 10 11:43:53 localhost.localdomain systemd[1]: Started ubuntu-users test.
</end>
The "status" output differs and is more verbose
Active: inactive (dead)
v/s
Active: active (exited) since Sun 2016-04-10 11:43:53 CEST; 2s ago
Process: 2412 ExecStart=/sbin/ip -o ro get 8.8.8.8 (code=exited,
status=0/SUCCESS)
Main PID: 2412 (code=exited, status=0/SUCCESS)
but does it really make a difference in the running of the unit?
More information about the ubuntu-users
mailing list