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

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

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

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

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

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值