![systemd 服务无法在主目录中启动脚本](https://linux22.com/image/951621/systemd%20%E6%9C%8D%E5%8A%A1%E6%97%A0%E6%B3%95%E5%9C%A8%E4%B8%BB%E7%9B%AE%E5%BD%95%E4%B8%AD%E5%90%AF%E5%8A%A8%E8%84%9A%E6%9C%AC.png)
我想在 Ubuntu 22.04 启动时启动一个 python 脚本(即 Flask 服务器)。我创建了一个/lib/systemd/system/myService.service
包含以下内容的文件:
[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
包含以下内容:
#!/bin/bash
eval "$(conda shell.bash hook)"
conda activate huggingface
python server.py
当我启动服务时,出现以下错误:
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'.
当我直接执行时server.sh
,它可以工作,所以问题出在服务上。我认为问题可能是我想在我的主目录中启动脚本。
是否有可能让服务启动我主目录中的 server.sh?我不想将其移出我的家,因为其他用户可以访问计算机,而他们不应该访问这些文件。
答案1
我遇到了和我解决的问题完全一样的问题sudo setenforce 0