#1) when a system has a separated /var, the unit will hang since it is looking
for /var/run to be present and it has been unmounted.
#2) when using Unattended-Upgrade::InstallOnShutdown "true"; the upgrade never
completes as the query to the online archive fails since the network is no
longer available.
#3) it is impossible to enable the unattended-upgrades.service unit. Here
is an example :
According to the doc[2], during shutdown, even if Before= or After= is used, the
unit being started will only start after the Shutdown of its dependencies. Prior
to the recent addition of local-fs.target network.target, the unit ran quickly
enough for the /var to be still mounted. But even without these dependencies,
InstallOnShutdown would fail with the following :
> 2017-03-10 13:40:42,803 INFO Starting unattended upgrades script
> 2017-03-10 13:40:42,803 INFO Allowed origins are: ['o=Ubuntu,a=zesty', 'o=Ubuntu,a=zesty-security']
> 2017-03-10 13:41:40,554 ERROR An error occurred: 'Cannot initiate the connection to 192.168.200.3:8000 (192.168.200.3). - connect (101: Network is unreachable)'
> 2017-03-10 13:41:40,555 ERROR The URI 'http://fr.archive.ubuntu.com/ubuntu/pool/main/i/init-system-helpers/init-system-helpers_1.47_all.deb' failed to download, aborting
When trying to switch the unit to an ExecStop=, we find that the Stop never
runs. This is caused by the fact that the unit is disabled (#3). Trying to
enable the unit leads to :
> # systemctl enable unattended-upgrades
> Synchronizing state of unattended-upgrades.service with SysV service script with /lib/systemd/systemd-sysv-install.
> Executing: /lib/systemd/systemd-sysv-install enable unattended-upgrades
> update-rc.d: error: unattended-upgrades Default-Start contains no runlevels, aborting.
Adding runlevels 2 3 4 5 fixes this then the unit can be enabled. So we get
to a unit that looks like this :
Before= is replaced by After= as, during shutdown otherwise the unit does not
run. RequiresMountsFor= is added as both /var/log and /var/run are needed in
order to run correctly.
RemainAfterExit=yes is added so the unit appears as started. There is no longer
a requirement to have an ExecStart present.
WantedBy is switched to multi-user.target as on the way up, we do nothing and we
are no longer depending on anything related to shutdown.
Now this only works IF /var is a separate FS. The reason for that is the
presence of DefaultDependencies=no. I don't think that it is required but was
there in the initial unit. Removing it in the final unit fixes the only
remaining issue. The unit is now :
Here is a recap of my work and current status :
#1) when a system has a separated /var, the unit will hang since it is looking
for /var/run to be present and it has been unmounted.
#2) when using Unattended- Upgrade: :InstallOnShutd own "true"; the upgrade never
completes as the query to the online archive fails since the network is no
longer available.
#3) it is impossible to enable the unattended- upgrades. service unit. Here
is an example :
> $ systemctl status unattended- upgrades. service upgrades. service - Unattended Upgrades Shutdown system/ unattended- upgrades. service; enabled; vendor preset: enabled) upgrade( 8)
> ● unattended-
> Loaded: loaded (/lib/systemd/
> Active: inactive (dead)
> Docs: man:unattended-
According to the doc[2], during shutdown, even if Before= or After= is used, the
unit being started will only start after the Shutdown of its dependencies. Prior
to the recent addition of local-fs.target network.target, the unit ran quickly
enough for the /var to be still mounted. But even without these dependencies,
InstallOnShutdown would fail with the following :
> 2017-03-10 13:40:42,803 INFO Starting unattended upgrades script a=zesty' , 'o=Ubuntu, a=zesty- security' ] fr.archive. ubuntu. com/ubuntu/ pool/main/ i/init- system- helpers/ init-system- helpers_ 1.47_all. deb' failed to download, aborting
> 2017-03-10 13:40:42,803 INFO Allowed origins are: ['o=Ubuntu,
> 2017-03-10 13:41:40,554 ERROR An error occurred: 'Cannot initiate the connection to 192.168.200.3:8000 (192.168.200.3). - connect (101: Network is unreachable)'
> 2017-03-10 13:41:40,555 ERROR The URI 'http://
When trying to switch the unit to an ExecStop=, we find that the Stop never
runs. This is caused by the fact that the unit is disabled (#3). Trying to
enable the unit leads to :
> # systemctl enable unattended-upgrades upgrades. service with SysV service script with /lib/systemd/ systemd- sysv-install. systemd- sysv-install enable unattended-upgrades
> Synchronizing state of unattended-
> Executing: /lib/systemd/
> update-rc.d: error: unattended-upgrades Default-Start contains no runlevels, aborting.
Adding runlevels 2 3 4 5 fixes this then the unit can be enabled. So we get
to a unit that looks like this :
> [Unit] Unattended Upgrades Shutdown cies=no target local-fs.target or=/var/ run /var/log man:unattended- upgrade( 8) /usr/share/ unattended- upgrades/ unattended- upgrade- shutdown multi-user. target
> Description=
> DefaultDependen
> After=network.
> RequiresMountsF
> Documentation=
>
> [Service]
> Type=oneshot
> RemainAfterExit=yes
> ExecStop=
> TimeoutStopSec=900
>
> [Install]
> WantedBy=
Before= is replaced by After= as, during shutdown otherwise the unit does not
run. RequiresMountsFor= is added as both /var/log and /var/run are needed in
order to run correctly.
RemainAfterExit=yes is added so the unit appears as started. There is no longer
a requirement to have an ExecStart present.
WantedBy is switched to multi-user.target as on the way up, we do nothing and we
are no longer depending on anything related to shutdown.
Now this only works IF /var is a separate FS. The reason for that is the cies=no. I don't think that it is required but was
presence of DefaultDependen
there in the initial unit. Removing it in the final unit fixes the only
remaining issue. The unit is now :
> [Unit] Unattended Upgrades Shutdown target local-fs.target or=/var/ run /var/log man:unattended- upgrade( 8) /usr/share/ unattended- upgrades/ unattended- upgrade- shutdown multi-user. target
> Description=
> After=network.
> RequiresMountsF
> Documentation=
>
> [Service]
> Type=oneshot
> RemainAfterExit=yes
> ExecStop=
> TimeoutStopSec=900
>
> [Install]
> WantedBy=
This works correctly and has been tested on :
- Xenial with and without /var as a separate FS
- Zesty with and without /var as a separate FS
InstallOnShutdown now also works as advertized.
I am now getting confirmation on that change since it is a rather sensible modification.