当前位置:   article > 正文

Executable path is not absolute, ignoring: xxx

executable path is not absolute, ignoring:

最近在Linux服务器上面部署我写的应用程序,使用的是虚拟环境

具体Linux服务代码如下:

  1. [Unit]
  2. Description=Process Redis data on the SMS_Receive website.
  3. After=network.target
  4. [Service]
  5. User=ubuntu
  6. Group=www-data
  7. Environment="PATH=/var/SMS_Receive/venv/bin/"
  8. WorkingDirectory=/var/SMS_Receive_Service
  9. ExecStart=python Anti_Web_Scraping.py
  10. ExecReload=/bin/kill -s HUP $MAINPID
  11. ExecStop=/bin/kill -s TERM $MAINPID
  12. [Install]
  13. WantedBy=multi-user.target

运行服务之后报如下错误:

[/etc/systemd/system/SMS_Receive_Redis.service:9] Executable path is not absolute, ignoring: python Anti_Web_Scraping

具体截图如下:

之后参考了这个页面:

Your service definitions are like this:

  1. [Service]
  2. ExecStart=python /home/pi/projects/script1.py
  3. Restart=always

And this is the error message on each of them:

Executable path is not absolute, ignoring: python /home/pi/...

For systemd, the "executable" in this service definition is python, and that is clearly not an absolute path. The /home/pi/projects/script1.py is just an argument to this python executable, and caring about its proper form is the executable's job.

Any Python-specific environment variables like PYTHONPATH have no meaning at all for systemd: you must give it an absolute path for the executable in the service definition, each and every time.

Typically, the absolute path to the python interpreter is /usr/bin/python, but you can check:

  1. $ type python
  2. python is /usr/bin/python

So your service definitions should be like this:

  1. [Service]
  2. ExecStart=/usr/bin/python /home/pi/projects/script1.py
  3. Restart=always

页面地址在这里:Using systemd to prevent python scripts from crashing

主要是相对路径的问题,需要修改代码如下:

  1. [Unit]
  2. Description=Process Redis data on the SMS_Receive website.
  3. After=network.target
  4. [Service]
  5. User=ubuntu
  6. Group=www-data
  7. Environment="PATH=/var/SMS_Receive/venv/bin/"
  8. WorkingDirectory=/var/SMS_Receive_Service
  9. ExecStart=/usr/bin/env python Anti_Web_Scraping.py
  10. ExecReload=/bin/kill -s HUP $MAINPID
  11. ExecStop=/bin/kill -s TERM $MAINPID
  12. [Install]
  13. WantedBy=multi-user.target

上面只是加了一个/usr/bin/env 制定了使用用户虚拟环境来解释python脚本。当然也可以加 -p参数:

还可以加上-P参数来指定一些目录去寻找python这个程序, #!/usr/bin/env -S -P/usr/local/bin:/usr/bin -p的作用就是在/usr/local/bin和/usr/bin目录下寻找python。

/usr/bin/env -P ${Environmnet} python Anti_Web_Scraping.py

作者自己遇到的问题与该博主类似,只是我是执行 java -jar命令时遇到的错误。原理是一样的:

原命令:ExecStart=java -agentlib:linux -jar /opt/gsp/gspserver-encrypt.jar

修改后:ExecStart=/usr/bin/java -agentlib:linux -jar /opt/gsp/gspserver-encrypt.jar

欢迎大家私信博主,拉你进技术交流群

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/80025
推荐阅读
相关标签
  

闽ICP备14008679号