文章内容

2019/1/5 15:46:14,作 者: 黄兵

Executable path is not absolute, ignoring: xxx

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

具体Linux服务代码如下:

[Unit]
Description=Process Redis data on the SMS_Receive website.
After=network.target
[Service]
User=ubuntu
Group=www-data
Environment="PATH=/var/SMS_Receive/venv/bin/"
WorkingDirectory=/var/SMS_Receive_Service
ExecStart=python Anti_Web_Scraping.py
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
[Install]
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:

[Service]
ExecStart=python /home/pi/projects/script1.py
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:

$ type python
python is /usr/bin/python

So your service definitions should be like this:

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

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

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

[Unit]
Description=Process Redis data on the SMS_Receive website.
After=network.target
[Service]
User=ubuntu
Group=www-data
Environment="PATH=/var/SMS_Receive/venv/bin/"
WorkingDirectory=/var/SMS_Receive_Service
ExecStart=/usr/bin/env python Anti_Web_Scraping.py
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
[Install]
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



黄兵个人博客原创。

转载请注明出处:黄兵个人博客 - Executable path is not absolute, ignoring: xxx

分享到:

发表评论

评论列表