forked from pub-solar/os
Hendrik Sokolowski
60ca29289e
* move tunnel for nextcloud-web into separate file * add script to check for running backups and shutdown server otherwise
51 lines
978 B
Nix
51 lines
978 B
Nix
{ pkgs, ... }:
|
|
|
|
let
|
|
shutdownWaitMinutes = 15;
|
|
shutdownScript = pkgs.writeScript "shutdown" ''
|
|
STATUS_FILES="/media/internal/backups-pub-solar/status"
|
|
|
|
running=""
|
|
|
|
for f in $STATUS_FILES; do
|
|
declare started
|
|
declare finished
|
|
|
|
started=$(source $f ; echo ''${BACKUP_STARTED})
|
|
finished=$(source $f ; echo ''${BACKUP_FINISHED})
|
|
|
|
if [ -z "''${finished}" ]; then
|
|
echo "backup $(dirname $f) still running"
|
|
running="yes"
|
|
break
|
|
fi
|
|
done
|
|
|
|
if [ -n "''${running}" ] && [ "''${running}" = "yes" ]; then
|
|
echo "backups are still running"
|
|
exit 1
|
|
fi
|
|
|
|
echo "WARNING: System will be shut down within the next 15 minutes" | wall
|
|
|
|
sleep 10
|
|
|
|
shutdown -P +${builtins.toString shutdownWaitMinutes}
|
|
'';
|
|
in
|
|
{
|
|
systemd.services."shutdown-after-backup" = {
|
|
enable = true;
|
|
serviceConfig = {
|
|
ExecStart = shutdownScript;
|
|
};
|
|
};
|
|
|
|
systemd.timers."shutdown-after-backup" = {
|
|
enable = true;
|
|
serviceConfig = {
|
|
OnCalendar = "3..9:*";
|
|
};
|
|
};
|
|
}
|