Systemd doesn't execute the script, yet it functions correctly when run directly.
Systemd doesn't execute the script, yet it functions correctly when run directly.
I'm working on a project that needs an automated command, and I'm planning to use systemd since I'm using Arch on a Pinephone. My setup looks like this: [Unit] Description=[to be filled] [Service] ExecStart=/path/to/script.sh User=[your username] [Install] WantedBy=multi-user.target Running the script manually works fine, but when I try to run it via systemd, I encounter this issue: × [something redacted].service - [something redacted] Loaded: loaded (/etc/systemd/system/[service].service; disabled; vendor preset: disabled) Active: failed (Result: exit-code) since Fri 2021-05-28 12:20:51 EDT; 2s ago Process: 5440 ExecStart=/path/to/script.sh (code=exited, status=1/FAILURE) Main PID: 5440 (code=exited, status=1/FAILURE) CPU: 168ms May 28 12:20:51 This seems to point at a permission or access problem. I added the "User=[my user]" line but it didn<|pad|>, so I'm still stuck. Any advice would be appreciated! The script runs perfectly without systemd.]
Your script is designed to interact with a service, likely attempting to establish a connection. Be aware that running it as root might prevent access if the service isn't available for that user, even though it should work normally. Consider using the --user flag with systemctl to run it as a regular user. Also, verify that your environment variables are correctly set.
Confirming the command details. #!/bin/bash pqiv --watch-files=changes-only --hide-info-box --fullscreen /path/to/image.png Adding "User" under [Service] behaves similarly to using --user flag. The update shows issues with bus connection and undefined paths when the --user option is applied.
This appears to be a similar issue to using sudo without the --user option. Adding the --machine flag might help as recommended. Running a graphical application inside a systemd service often causes problems, especially when executed as root or with a different user than the X11 owner. To ensure it starts automatically, make sure X11 is loaded beforehand. The easiest solution seems to be launching xorg as a user service and linking it to your service dependencies. Alternatively, you could place the application in .xinitrc or .xprofile for simple startup handling. I’m unsure about Wayland compatibility, but this might provide guidance.