首页 > 解决方案 > 使用 Systemctl 找不到 Python

问题描述

嗨,伙计们,我在systemctl中有一个错误,告诉我找不到 python。在下面的 .service 文件中,我运行 celery-beat。在我的 tasks.py 中,我有一个os.system用于运行 python 代码的代码片段。

# My .service
[Unit]
Description=Celery Service
After=network.target

[Service]
Type=forking
User=ubuntu
Group=ubuntu
WorkingDirectory=/home/ubuntu/my_project_folder
ExecStart=/bin/sh -c '/home/ubuntu/enviq/bin/celery -A projectdjango worker -l info -B --scheduler django_celery_beat.schedulers:DatabaseScheduler &'
ExecStop=/bin/kill -s TERM $MAINPID

[Install]
WantedBy=multi-user.target
# Error when execute sudo journalctl -xe
Apr 30 16:13:01 ip-172-31-17-187 sh[16228]: [2020-04-30 13:13:01,155: INFO/MainProcess] Received task: app_iq_option01.tasks.get_candles_tasks[d1d14df
Apr 30 16:13:01 ip-172-31-17-187 sh[16228]: sh: 1: python: not found
Apr 30 16:13:01 ip-172-31-17-187 sh[16228]: sh: 1: python: not found
# In this line I use the module os to call main_tasks.py
command = "python main_tasks.py {} {} {} '%s'".format(cred.email, cred.password, cred.max_samples)
command = command % coins
os.system(command)

当我在不使用 systemctl 的情况下通过终端运行 celery 的命令时,它工作正常。任何人都可以帮助我吗?我真的很感激!似乎 systemd 无法识别我的 virtualenv(它调用 venviq)。

标签: pythoncelerybeatsystemctl

解决方案


推荐阅读