Sample Header Ad - 728x90

systemd service hangs system on boot when update is pending

0 votes
0 answers
92 views
I have a Linux Mint 22 system (Wilma, based off Ubuntu 24.04) with the Mate interface. I am dual booting this with Windows 10. Windows 10 is hardly ever accessed so effectively it is a Linux box. I have a systemd service that kicks off a backup to an external USB drive on startup and another one on shutdown. I have backup running on both shutdown and startup. I found that if some large (eg video) files are being backed up on shutdown, the backup does not always complete so I run a backup on startup. If the shutdown backup completed, the startup backup will not delay anything. If the shutdown backup did not complete, the startup backup will finish the job. Normally things work just fine so the systemd setup is configured correctly. However, when there is a upgrade pending, the boot hangs. The upgrade does NOT have to be a kernel upgrade; it can be just a package upgrade. The boot does NOT hang if I remove the scripts so the issue is with the systemd service(s) initiation. The systemd elements have been properly enabled and started. I use a timer to initiate the startup backup since the boot process can have delayed power-up for the external USB drive. I use a oneshot service directly to initiate the shutdown backup. See below for my files. Questions: - Has anyone ever seen this issue before? Do you see anything wrong with my systemd setup? Is there something I am missing to ensure boots will always proceed even if an upgrade is pending? =============================================================== Startup systemd setup - using a timer cat /etc/systemd/system/backup_to_external_drive_on_startup.timer [Unit] Description=Kickoff backup script after delay to allow external drive to spin up [Timer] OnBootSec=5min Unit=backup_to_external_drive_on_startup.service [Install] WantedBy=timers.target cat /etc/systemd/system/backup_to_external_drive_on_startup.service [Unit] Description=Backup mardi home directory to an external drive RequiresMountsFor=/home/mardi /mnt/c988b046-5349-498e-ac96-d5fe46314205 Requires=home-mardi.mount mnt-c988b046\x2d5349\x2d498e\x2dac96\x2dd5fe46314205.mount After=network.target network-online.target local-fs.target home-mardi.mount mnt-c988b046\x2d5349\x2d498e\x2dac96\x2dd5fe46314205.mount [Service] User=mardi Group=mardi Type=oneshot ExecStart=/bin/bash /home/mardi/Scripts/backup_to_external_drive.sh Shutdown systemd setup - using a oneshot service directly cat /etc/systemd/system/backup_to_external_drive_on_startup.service [Unit] Description=Backup mardi home directory to an external drive RequiresMountsFor=/home/mardi /mnt/c988b046-5349-498e-ac96-d5fe46314205 Requires=home-mardi.mount mnt-c988b046\x2d5349\x2d498e\x2dac96\x2dd5fe46314205.mount After=network.target network-online.target local-fs.target home-mardi.mount mnt-c988b046\x2d5349\x2d498e\x2dac96\x2dd5fe46314205.mount [Service] User=mardi Group=mardi Type=oneshot ExecStart=/bin/true RemainAfterExit=true ExecStop=/bin/bash /home/mardi/Scripts/backup_to_external_drive.sh TimeoutSec=infinity [Install] WantedBy=multi-user.target The actual backup script triggered by each of the above cat /home/mardi/Scripts/backup_to_external_drive.sh #!/bin/bash # # Define the function to test the mount status # In bash, this must be placed before it is called by the script # it is not hoisted as in php # This function only works in systems with bach version .= 4.3 # the nameref capability is used to return a value from the function # and the nameref capability was only intorduced in bash 4.3 isItMounted() { mountPointShown=$(findmnt -lo target $1) declare -n functionReturnValue=$2 if [[ "${mountPointShown}" == "" ]] then functionReturnValue="NotMounted" else functionReturnValue="Mounted" fi } # Create an initial value to initialize the variable # that will hold the result of the isItMounted function returnValue='' homeMardiMount="/home/mardi/" isItMounted "${homeMardiMount}" returnValue homeMardiMountStatus=${returnValue} backupTargetMount="/mnt/c988b046-5349-498e-ac96-d5fe46314205" isItMounted "${backupTargetMount}" returnValue backupTargetMountStatus=${returnValue} # Use the function to determine what to do next if [[ "${homeMardiMountStatus}" == "NotMounted" ]] then printf "Error, Mardi's home directory is not mounted\n" printf "To: Mardi_Admin\nSubject: mardi backup failed at $(date)\nBackup for Linux Mint Mardi failed at $(date) because the home directory for Mardi is not mounted" | msmtp "Mardi_Admin" sleep 3s exit 98 elif [[ "${backupTargetMountStatus}" == "NotMounted" ]] then printf "Error, the External drive is not mounted\n" printf "To: Mardi_Admin\nSubject: mardi backup failed at $(date)\nBackup for Linux Mint Mardi failed at $(date) because the external disk is not mounted" | msmtp "Mardi_Admin" sleep 3s exit 99 else printf "Backup initialized. Both the home directory for Mardi and the external disk are mounted\n" rsync -h --progress --ignore-errors --stats -r -tgo -p -l -D --update --exclude={'.aptitude','.gvfs','.cache/dconf','.kde/share/apps/kwallet'} "${homeMardiMount}" "${backupTargetMount}" printf "To: Mardi_Admin\nSubject: mardi backup succeeded at $(date)\nBackup for Linux Mint Mardi succeeded at $(date)" | msmtp "Mardi_Admin" sleep 3s fi exit 0
Asked by Ramblin (1 rep)
Sep 25, 2024, 08:26 PM
Last activity: Sep 25, 2024, 09:55 PM