【问题标题】:Cant start a pythonscript from systemd service无法从 systemd 服务启动 python 脚本
【发布时间】:2020-07-19 11:53:29
【问题描述】:

这是我的 systemd 单元文件。我在 pythonscript 中有一个日志记录初始化脚本。这里发生了一个找不到文件的错误。同时,python 似乎来自系统 python 目录,而不是来自我的环境。如何解决这个问题。

[Service]
User=nobody
Group=nogroup
ExecStart=/home/ubuntu/app/env/bin/python /home/ubuntu/app/backend/app.py --path=/tmp/app_1.sock

系统错误日志:

:     loghandler = TimedRotatingFileHandler('logs/mainserver.log', when="midnight", i
:   File "/usr/lib/python3.6/logging/handlers.py", line 202, in __init__
:     BaseRotatingHandler.__init__(self, filename, 'a', encoding, delay)
:   File "/usr/lib/python3.6/logging/handlers.py", line 57, in __init__
:     logging.FileHandler.__init__(self, filename, mode, encoding, delay)
:   File "/usr/lib/python3.6/logging/__init__.py", line 1032, in __init__
:     StreamHandler.__init__(self, self._open())
:   File "/usr/lib/python3.6/logging/__init__.py", line 1061, in _open
:     return open(self.baseFilename, self.mode, encoding=self.encoding)
: FileNotFoundError: [Errno 2] No such file or directory: '/logs/mainserver.log'

另外请告诉我的脚本从哪个目录运行..

【问题讨论】:

    标签: python python-3.x systemd


    【解决方案1】:

    我通过在[Service] 部分添加指令解决了这个问题

    WorkingDirectory=/home/ubuntu/app/backend/
    

    这工作没有任何错误。我认为现在 python env 是从我的aioenv 中使用的。否则它应该显示一些错误。还要记住do not put WorkingDirectory 在ExecStart= 之前 希望这会对某人有所帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-17
      • 1970-01-01
      • 1970-01-01
      • 2020-05-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多