[?BUG]/[FEATURE REQUEST]Auto shutdown server if idle

Server details:

OS - Raspberry Pi OS Bookworm 64 Bit
Device - Raspberry Pi 5 4GB
urbackup installed via the .deb package available on the official site.

How auto shutdown works - UrBackup creates a file called shutdown_now in /var/urbackup if it recognises it has been idle for some time. (My calculation shows this time interval to be around 30 min).
A systemd service file that is enabled at boot checks for this file and if found deletes the file, then executes a shutdown in 5 minutes.

Issue - UrBackup seems to create this file every minute. So if my script finds shutdown_now and deletes it and schedules a shutdown in 5 minutes, urbackup creates this file 5 times again in that interval. This is not an issue in the current cycle, however when the system is booted again, since the file exists in that location, the service file executes another shutdown. Unless this is caught by the user and cancelled, this will lead to a wrong shutdown. Another quirk here is that when the user accesses the /var/urbackup folder after a shutdown, I am unable to see the shutdown_now file. This means that some time between the service finding the file after boot and login, urbackup deletes this file.

Possible Solution -

  1. UrBackup server creates shutdown_now only once. The systemd service finds it, removes the file and executes the shutdown. On next boot, no file is found and no shutdown is scheduled.
  2. The systemd service file becomes active only after login. This might give the UrBackup server time to delete the shutdown_now file created in the last boot.
  3. Use shutdown now instead of 5m time delay. This is the least preferred solution as I have other services running that I would like to do certain things once a shutdown is scheduled. There is also the risk that if for some reason the service file is executed but shutdown is delayed by another service and urbackup is still active, this might cause the file to be created again and the next time it boots, it will detect the file and shutdown immediately. In other words, it’ll result in a boot loop.

Now I have 2 questions,

  1. Is there a reason why UrBackup Server creates this file every minute?
  2. How does UrBackup Server determine the system is idle?

As for the feature request, I’d like to be able to set the time delay that is considered as Idle before UrBackup generates the shutdown_now file.

@uroni - Please take a look at this if possible.

Regards,
alphamike-1612

Just change your service to delete the file when it starts?

The service is executed only if the file exists. If it exists, the file is deleted and the shutdown is scheduled. The problem here is that urbackup creates the file again before the system is able to shut down.

So on booting, the file is detected, service runs, the file is destroyed and a shutdown is scheduled. If the user doesn’t catch this scheduled shutdown and cancel it, the system is shutdown and requires a manual reboot.

Another possible workaround is to create a service file who’s sole purpose is to delete this file if it exists every time the system is shutdown. But this seems very clumsy.

I’d like to know the logic behind the creation of this file every minute past the time limit. Fixing it such that it’s created only once would make much more sense in my opinion.