And it doesn't print message in serial console. But when you start and stop this unit manually - it prints.
[ OK ] Stopped target Graphical Interface.
Stopping Accounts Service...
Stopping User Manager for UID 1000...
Stopping Session 1 of user ubuntu.
Stopping ACPI event daemon...
[ OK ] Stopped target Cloud-init target.
[ OK ] Stopped Execute cloud user/final scripts.
[ OK ] Stopped target Multi-User System.
Stopping Deferred execution scheduler...
Stopping LXD - container startup/shutdown...
Stopping D-Bus System Message Bus...
Stopping LSB: daemon to balance interrupts for SMP systems...
Stopping LSB: Set the CPU Frequency Scaling governor to "ondemand"...
Stopping LSB: MD monitoring daemon...
Stopping Regular background program processing daemon...
Stopping FUSE filesystem for LXC...
Stopping OpenBSD Secure Shell server...
Stopping LSB: Record successful boot for GRUB...
[ OK ] Stopped target Timers.
[ OK ] Stopped Timer to automatically refresh installed snaps.
[ OK ] Stopped Daily apt activities.
[ OK ] Stopped Daily Cleanup of Temporary Directories.
[ OK ] Stopped target Login Prompts.
Stopping Getty on tty1...
Stopping Serial Getty on ttyS0...
[ OK ] Stopped Apply the settings specified in cloud-config.
[ OK ] Stopped target Cloud-config availability.
Stopping Snappy daemon...
Stopping System Logging Service...
[ OK ] Stopped target System Time Synchronized.
Stopping LSB: automatic crash report generation...
[ OK ] Closed Load/Save RF Kill Switch Status /dev/rfkill Watch.
Stopping Authenticate and Authorize Users to Run Privileged Tasks...
[ OK ] Unmounted /var/lib/lxcfs.
[ OK ] Stopped System Logging Service.
[ OK ] Stopped Deferred execution scheduler.
[ OK ] Stopped OpenBSD Secure Shell server.
[ OK ] Stopped Accounts Service.
[ OK ] Stopped Snappy daemon.
[ OK ] Stopped ACPI event daemon.
[ OK ] Stopped Authenticate and Authorize Users to Run Privileged Tasks.
[ OK ] Stopped Serial Getty on ttyS0.
[ OK ] Stopped Regular background program processing daemon.
[ OK ] Stopped Getty on tty1.
[ OK ] Stopped User Manager for UID 1000.
[ OK ] Stopped Session 1 of user ubuntu.
[ OK ] Stopped D-Bus System Message Bus.
[ OK ] Stopped FUSE filesystem for LXC.
[ OK ] Stopped LXD - container startup/shutdown.
[ OK ] Stopped LSB: MD monitoring daemon.
[ OK ] Stopped LSB: Record successful boot for GRUB.
[ OK ] Stopped LSB: daemon to balance interrupts for SMP systems.
[ OK ] Stopped LSB: automatic crash report generation.
[ OK ] Stopped LSB: Set the CPU Frequency Scaling governor to "ondemand".
[ OK ] Stopped User Manager for UID 1000.
[ OK ] Removed slice User Slice of ubuntu.
Stopping Login Service...
[ OK ] Removed slice system-getty.slice.
[ OK ] Removed slice system-serial\x2dgetty.slice.
[ OK ] Stopped /etc/rc.local Compatibility.
Stopping Permit User Sessions...
[ OK ] Stopped Login Service.
[ OK ] Stopped Permit User Sessions.
[ OK ] Stopped target Remote File Systems.
[ OK ] Stopped target Remote File Systems (Pre).
Stopping Login to default iSCSI targets...
[ OK ] Stopped target User and Group Name Lookups.
[ OK ] Stopped target Basic System.
[ OK ] Stopped target Paths.
[ OK ] Stopped Forward Password Requests to Wall Directory Watch.
[ OK ] Stopped Trigger resolvconf update for networkd DNS.
[ OK ] Stopped Dispatch Password Requests to Console Directory Watch.
[ OK ] Stopped ACPI Events Check.
[ OK ] Stopped target Slices.
[ OK ] Removed slice User and Session Slice.
[ OK ] Stopped target Sockets.
[ OK ] Closed ACPID Listen Socket.
[ OK ] Closed UUID daemon activation socket.
[ OK ] Closed LXD - unix socket.
[ OK ] Closed Syslog Socket.
[ OK ] Closed D-Bus System Message Bus Socket.
[ OK ] Closed Socket activation for snappy daemon.
[ OK ] Stopped target System Initialization.
Stopping Network Time Synchronization...
[ OK ] Stopped target Encrypted Volumes.
Stopping Load/Save Random Seed...
[ OK ] Stopped target Swap.
[ OK ] Stopped Network Time Synchronization.
[ OK ] Stopped Load/Save Random Seed.
[ OK ] Stopped Create Volatile Files and Directories.
[ OK ] Unmounted /home.
[ OK ] Unmounted /boot.
[ OK ] Stopped Login to default iSCSI targets.
Stopping iSCSI initiator daemon (iscsid)...
[ OK ] Stopped iSCSI initiator daemon (iscsid).
[ OK ] Stopped target Network is Online.
[ OK ] Stopped target Network.
[ OK ] Stopped Initial cloud-init job (metadata service crawler).
Stopping Raise network interfaces...
[ OK ] Stopped Raise network interfaces.
[ OK ] Stopped target Network (Pre).
[ OK ] Stopped Initial cloud-init job (pre-networking).
[ OK ] Stopped target Local File Systems.
[ OK ] Started Unattended Upgrades Shutdown.
Unmounting /run/user/1000...
Unmounting /tmp...
[ OK ] Stopped Apply Kernel Variables.
[ OK ] Stopped Load Kernel Modules.
[ OK ] Unmounted /run/user/1000.
[ OK ] Unmounted /tmp.
[ OK ] Reached target Unmount All Filesystems.
[ OK ] Stopped target Local File Systems (Pre).
Stopping Monitoring of LVM2 mirrors... dmeventd or progress polling...
[ OK ] Stopped Remount Root and Kernel File Systems.
[ OK ] Stopped Create Static Device Nodes in /dev.
[ OK ] Reached target Shutdown.
Tested the fix. It works. Thanks!
quick fix:
sed -i "s#ExecStart= #RemainAfterExi t=yes\nExecStop =#;" /lib/systemd/ system/ unattended- upgrades. service
But now it seems that it doesn't run it on shutdown. I used the following debug service:
ExecStop=/bin/bash -c 'echo -e "\nhello# ####### ####### ####### \n" > /dev/ttyS0'
And it doesn't print message in serial console. But when you start and stop this unit manually - it prints.
[ OK ] Stopped target Graphical Interface. serial\ x2dgetty. slice.
Stopping Accounts Service...
Stopping User Manager for UID 1000...
Stopping Session 1 of user ubuntu.
Stopping ACPI event daemon...
[ OK ] Stopped target Cloud-init target.
[ OK ] Stopped Execute cloud user/final scripts.
[ OK ] Stopped target Multi-User System.
Stopping Deferred execution scheduler...
Stopping LXD - container startup/shutdown...
Stopping D-Bus System Message Bus...
Stopping LSB: daemon to balance interrupts for SMP systems...
Stopping LSB: Set the CPU Frequency Scaling governor to "ondemand"...
Stopping LSB: MD monitoring daemon...
Stopping Regular background program processing daemon...
Stopping FUSE filesystem for LXC...
Stopping OpenBSD Secure Shell server...
Stopping LSB: Record successful boot for GRUB...
[ OK ] Stopped target Timers.
[ OK ] Stopped Timer to automatically refresh installed snaps.
[ OK ] Stopped Daily apt activities.
[ OK ] Stopped Daily Cleanup of Temporary Directories.
[ OK ] Stopped target Login Prompts.
Stopping Getty on tty1...
Stopping Serial Getty on ttyS0...
[ OK ] Stopped Apply the settings specified in cloud-config.
[ OK ] Stopped target Cloud-config availability.
Stopping Snappy daemon...
Stopping System Logging Service...
[ OK ] Stopped target System Time Synchronized.
Stopping LSB: automatic crash report generation...
[ OK ] Closed Load/Save RF Kill Switch Status /dev/rfkill Watch.
Stopping Authenticate and Authorize Users to Run Privileged Tasks...
[ OK ] Unmounted /var/lib/lxcfs.
[ OK ] Stopped System Logging Service.
[ OK ] Stopped Deferred execution scheduler.
[ OK ] Stopped OpenBSD Secure Shell server.
[ OK ] Stopped Accounts Service.
[ OK ] Stopped Snappy daemon.
[ OK ] Stopped ACPI event daemon.
[ OK ] Stopped Authenticate and Authorize Users to Run Privileged Tasks.
[ OK ] Stopped Serial Getty on ttyS0.
[ OK ] Stopped Regular background program processing daemon.
[ OK ] Stopped Getty on tty1.
[ OK ] Stopped User Manager for UID 1000.
[ OK ] Stopped Session 1 of user ubuntu.
[ OK ] Stopped D-Bus System Message Bus.
[ OK ] Stopped FUSE filesystem for LXC.
[ OK ] Stopped LXD - container startup/shutdown.
[ OK ] Stopped LSB: MD monitoring daemon.
[ OK ] Stopped LSB: Record successful boot for GRUB.
[ OK ] Stopped LSB: daemon to balance interrupts for SMP systems.
[ OK ] Stopped LSB: automatic crash report generation.
[ OK ] Stopped LSB: Set the CPU Frequency Scaling governor to "ondemand".
[ OK ] Stopped User Manager for UID 1000.
[ OK ] Removed slice User Slice of ubuntu.
Stopping Login Service...
[ OK ] Removed slice system-getty.slice.
[ OK ] Removed slice system-
[ OK ] Stopped /etc/rc.local Compatibility.
Stopping Permit User Sessions...
[ OK ] Stopped Login Service.
[ OK ] Stopped Permit User Sessions.
[ OK ] Stopped target Remote File Systems.
[ OK ] Stopped target Remote File Systems (Pre).
Stopping Login to default iSCSI targets...
[ OK ] Stopped target User and Group Name Lookups.
[ OK ] Stopped target Basic System.
[ OK ] Stopped target Paths.
[ OK ] Stopped Forward Password Requests to Wall Directory Watch.
[ OK ] Stopped Trigger resolvconf update for networkd DNS.
[ OK ] Stopped Dispatch Password Requests to Console Directory Watch.
[ OK ] Stopped ACPI Events Check.
[ OK ] Stopped target Slices.
[ OK ] Removed slice User and Session Slice.
[ OK ] Stopped target Sockets.
[ OK ] Closed ACPID Listen Socket.
[ OK ] Closed UUID daemon activation socket.
[ OK ] Closed LXD - unix socket.
[ OK ] Closed Syslog Socket.
[ OK ] Closed D-Bus System Message Bus Socket.
[ OK ] Closed Socket activation for snappy daemon.
[ OK ] Stopped target System Initialization.
Stopping Network Time Synchronization...
[ OK ] Stopped target Encrypted Volumes.
Stopping Load/Save Random Seed...
[ OK ] Stopped target Swap.
[ OK ] Stopped Network Time Synchronization.
[ OK ] Stopped Load/Save Random Seed.
[ OK ] Stopped Create Volatile Files and Directories.
[ OK ] Unmounted /home.
[ OK ] Unmounted /boot.
[ OK ] Stopped Login to default iSCSI targets.
Stopping iSCSI initiator daemon (iscsid)...
[ OK ] Stopped iSCSI initiator daemon (iscsid).
[ OK ] Stopped target Network is Online.
[ OK ] Stopped target Network.
[ OK ] Stopped Initial cloud-init job (metadata service crawler).
Stopping Raise network interfaces...
[ OK ] Stopped Raise network interfaces.
[ OK ] Stopped target Network (Pre).
[ OK ] Stopped Initial cloud-init job (pre-networking).
[ OK ] Stopped target Local File Systems.
[ OK ] Started Unattended Upgrades Shutdown.
Unmounting /run/user/1000...
Unmounting /tmp...
[ OK ] Stopped Apply Kernel Variables.
[ OK ] Stopped Load Kernel Modules.
[ OK ] Unmounted /run/user/1000.
[ OK ] Unmounted /tmp.
[ OK ] Reached target Unmount All Filesystems.
[ OK ] Stopped target Local File Systems (Pre).
Stopping Monitoring of LVM2 mirrors... dmeventd or progress polling...
[ OK ] Stopped Remount Root and Kernel File Systems.
[ OK ] Stopped Create Static Device Nodes in /dev.
[ OK ] Reached target Shutdown.