The systemd WorkingDirectory=
setting defines on which directory the service will be launched, same as when you use cd
to change a directory when you're working in the shell.
That doesn't mean that all the other paths (including that from ExecStart=
) will now be relative to it, so you still need to fully specify the path to your script in that directive:
ExecStart=/home/someuser/somescript.sh
Perhaps you were thinking of the RootDirectory=
directive instead? That directory uses the chroot
command to switch the root of the filesystem seen by the process by the directory you specify, so from your use of /
for the location of the script, that looks like maybe what you wanted... However, using RootDirectory=
requires that you have a system image, with binaries and libraries under it. Like, you need to have a /bin/sh
to run your shell script, and a /lib
with a libc, etc. Typically you can't just use RootDirectory=
to just about any directory that you like...
So my advice here in order to fix the issue you're seeing is to just update the ExecStart=
to list the full path to your script.
/
in front ofsomescript.sh
. I don't suppose you putsomescript.sh
in the root of the filesystem?/home/someuser
. It's needs to run in this directory. I tried to do it withWorkingDirectory
but it can't find the script./home/someuser
, then tell the system that it is there. Look closely atExecStart=/somescript.sh
: where does this say the script is? (Hint: where is/home
located?)/home/someuser/somescript.sh
will not work for me), I tried to useWorkingDirectory
to change the directory before executing it. Do you have some idea how can I do it?ExecStart=/home/someuser/somescript.sh
and is the way to do it; otherwise there might be another error not related to the service.