Score:0

systemd service fails to start script in home directory

ax flag

I would like to start a python script (i.e. a Flask server) at boot of Ubuntu 22.04. I have created a file /lib/systemd/system/myService.service with following content:

[Unit]
Description=The service starts a Flask server

[Service]
User=myUsername
ExecStart=/home/myUsername/PycharmProjects/myProject/server/server.sh

[Install]
WantedBy=multi-user.target

server.sh contains the following content:

#!/bin/bash
eval "$(conda shell.bash hook)"
conda activate huggingface
python server.py

When I start the service, I'm getting the following error:

Mar 28 02:04:39 myComputer systemd[1]: Started myService.
Mar 28 02:04:39 myComputer  systemd[1713428]: myService.service: Failed to locate executable /home/myUsername/PycharmProjects/myProject/server/server.sh: Permission denied
Mar 28 02:04:39 myComputer  systemd[1713428]: myService.service: Failed at step EXEC spawning /home/myUsername/PycharmProjects/myProject/server/server.sh: Permission denied
Mar 28 02:04:39 myComputer  systemd[1]: myService.service: Main process exited, code=exited, status=203/EXEC
Mar 28 02:04:39 myComputer  systemd[1]: myService.service: Failed with result 'exit-code'.

When I directly execute server.sh it works, so the problem is the service. I think that the problem could be that I want to start the script in my home directory.

Is there a possibility to get the service to start the server.sh in my home directory? I don't want to move it outside of my home because other users have access to the computer and they should not have access to the files.

hr flag
So is the script's execute bit set? When you *"execute server.sh"* do you do so as `./server.sh` or as `bash server.sh` for example? Have you installed/configured `conda` in such a way that it is available outside of your interactive shell session?
BlackHawk avatar
ax flag
@steeldriver Yes, I did `chmod +x server.sh`. I'm executing it as `./server.sh`. I removed the conda command from server.sh script and there is still the same error, so I think that is not the problem.
hr flag
Where does your home directory reside? is it perhaps not mounted at this point (on a remote server for example, or encrypted and not mounted until you log in)?
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.