Apologies in advance for any mangling of terminology, syntax, conventions, etc. I'm still a fairly novice Linux user. I am working on Steam Deck running the latest SteamOS (3.5.17).
I managed to successfully setup a startup and shutdown service using systemd which synchronizes game saves between the Steam Deck and a SAMBA shared network drive I have setup on a Raspberry Pi. I have the drive set to automount (via fstab) at "/home/deck/mnt/xtra/". Each service runs the bash script called "sync_saves.sh" at startup and shutdown respectively.
The problem is that I also want to store the script "sync_saves.sh" on the network drive and run it from there so that I can update it more easily. The script reads a config file (also on the network) that is updated frequently from various computers. I don't want them each to have their own local version because keeping them in sync manually becomes a real pain. However, while I can run the script directly from the network drive, the service doesn't run if the script is on the network drive. If there are any errors, I'm not seeing them when I run:
systemctl --user status ss_lin_startup The two services are defined in files named ss_lin_startup.service and ss_lin_shutdown.service. Here are their contents:
ss_lin_startup.service
[Unit] Description=SyncSaves Startup [Service] #ExecStart=/home/deck/mnt/xtra/scripts/SyncSaves/sync_saves.sh #network drive, doesn't work ExecStart=/home/deck/Documents/scripts/SyncSaves/sync_saves.sh #local drive, works [Install] WantedBy=default.target ss_lin_shutdown.service
[Unit] Description=SyncSaves Shutdown [Service] Type=oneshot RemainAfterExit=true #ExecStop=/home/deck/mnt/xtra/scripts/SyncSaves/sync_saves.sh #network drive, doesn't work ExecStop=/home/deck/Documents/scripts/SyncSaves/sync_saves.sh #local drive, works [Install] WantedBy=default.target I got them working (when script is stored on local drive) by putting a link to the service files in "/home/deck/.config/systemd/user/" and running the following commands:
systemctl --user daemon-reload systemctl --user enable ss_lin_startup.service systemctl --user enable ss_lin_shutdown.service If it matters, the service files are stored at "/home/deck/Documents/scripts/SyncSaves/services" linked in the folder "/home/deck/.config/systemd/user/". The Steam Deck desktop environment offers the option to drag and drop files as either move, copy or link, which is the method I used to create the links.
Is there a way to get this working? Am I going about it the right way? Alternatively, is there a way for me to automate copying the script "sync_saves.sh" from the network drive to the local drive on boot?
I've been Googling for several hours and the only hints I've come up with are as follows:
-I saw somewhere that systemd doesn't like when services are located on different partitions (from the system partition presumably), but I'm not sure if I understood that correctly or if the implications apply here or if it matters where the scripts they invoke are stored.
-In most of the discussions on this topic, the services are placed or linked in "/etc/systemd/system/" and the command to enable them is "systemctl enable your_service.service" without the --user flag and sometimes with sudo. In my initial testing on the Raspberry Pi, I used that approach, but had issues on Steam Deck.
UPDATE:
I figured out a part of the problem, but still don't have a solution. I suspected this might happen, but not sure how to remedy it. I ran
systemctl --user -l status ss_lin_startup.service and got more details output. It says "Failed to locate executable ...sync_saves.sh". So what is likely happening (in the startup at least) is that the drive isn't mounted yet. I've seen people use different arguments in the service file to make sure the command runs after network startup (i.e. Wants=network-online.target, After=network-online.target), but when I use those I get something like "target not found".
FINAL UPDATE:
I came up with a work around which was to write an update script (which pulls the latest version of sync_saves.sh and config files from the network drive) and then a script to run the update script and then the sync script. With that it is working as intended. I'm not sure how much progress can be made here as there doesn't seem to be a lot of information out there about the idiosyncrasies of the SteamOS.