I hope you are all having a great day. I have been tearing my hair out trying to do something I initially thought would be simple, run rclone to sync my files to Google at shutdown. I know most people suggest automatically running an rclone script with cron, but I do not work any normal hours or have my computer on all day, so a scheduled job would not work well. I have rclone running perfectly well, I can manually run backup scripts.
I am trying to do this with systemd following these instructions How to Run a Script Before Shutdown Under Systemd
After solving a few issues I am now stuck because systemd cannot find the rclone.conf file. My rclone.conf is located here:
/home/barry/.config/rclone/rclone.conf
but systemd is looking for rclone.conf under /root, so it fails. I guess I need to put some instructions in the script or unit file, but I am not sure what to do. Simple script for testing:
#!/bin/bash
rclone sync -v --create-empty-src-dirs /$HOME/Documents Google:Documents
Unit File:
[Unit]
Description=Execute custom script before system poweroff
DefaultDependencies=no
Before=shutdown.target
[Service]
Type=oneshot
ExecStart=/usr/lib/systemd/system-shutdown/backup.sh
TimeoutStartSec=0
[Install]
WantedBy=shutdown.target
Systemctl status with error "NOTICE: Config file "/root/.config/rclone/rclone.conf" not found - using defaults"
arry@barryubuntu:~$ systemctl status execute-before-shutdown.service
× execute-before-shutdown.service - Execute custom script before system poweroff
Loaded: loaded (/etc/systemd/system/execute-before-shutdown.service; enabled; preset: enabled)
Active: failed (Result: exit-code) since Fri 2025-02-14 18:48:01 -05; 2min 22s ago
Process: 10732 ExecStart=/usr/lib/systemd/system-shutdown/backup.sh (code=exited, status=1/FAILURE)
Main PID: 10732 (code=exited, status=1/FAILURE)
CPU: 70ms
Feb 14 18:48:01 barryubuntu systemd[1]: Starting execute-before-shutdown.service - Execute custom script before system poweroff...
Feb 14 18:48:01 barryubuntu backup.sh[10733]: NOTICE: Config file "/root/.config/rclone/rclone.conf" not found - using defaults
Feb 14 18:48:01 barryubuntu backup.sh[10733]: CRITICAL: Failed to create file system for "Google:/Documents": didn't find section in config file
Feb 14 18:48:01 barryubuntu systemd[1]: execute-before-shutdown.service: Main process exited, code=exited, status=1/FAILURE
Feb 14 18:48:01 barryubuntu systemd[1]: execute-before-shutdown.service: Failed with result 'exit-code'.
Feb 14 18:48:01 barryubuntu systemd[1]: Failed to start execute-before-shutdown.service - Execute custom script before system poweroff.
Ok, if there is a better way to do this than with systemd, I will be happy to follow it! Thanks