当我从.service文件运行我的gunicorn python应用程序时,出现了FileNotFoundError:[Errno 2] No such file or directory:'bash'
错误。
但是,单独运行gunicorn命令(而不是从.service文件中运行)可以正常工作。
运行应用程序的gunicorn命令
gunicorn -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker -w 1 --bind <server_ip>:8080 wsgi
应用程序服务文件
[Service]
User=user
WorkingDirectory=/home/user/app
Environment="PATH=/home/user/app/app_venv/bin"
ExecStart=/home/user/app/app_venv/bin/gunicorn -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker --workers 1 --bind <server_ip>:8080 wsgi
生成错误的Python代码
import subprocess
cmd = ['bash', 'script.sh' , args.get('arg')]
try:
process = subprocess.Popen(cmd,
cwd=/path/to/bash_script,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
universal_newlines=True)
while process.poll() is None:
output = process.stdout.readline()
if(output==''):
break
emit('tg_output', output)
except subprocess.CalledProcessError as error:
pass