python - 使用 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)。
解决方案
推荐阅读
- java - 在 JFreechart 中将 unix 时间转换为日期?
- excel - AutoFilter Array 不适用于更多元素 VBA
- javascript - 单击“订阅”按钮后关闭弹出表单
- c# - ASP.NET Core CRUD 工具:未找到但实际安装的命令
- javascript - 我可以在 chartjs 选项上使用三元,尤其是在图例上?
- javascript - 什么关键字用于通过双击网页上的单词来创建自定义工具提示?
- azure-digital-twins - Azure 数字孪生和租户
- python - 如何将我当前的 django 应用程序转换为 REST API?
- javascript - 强制重新加载使用 AJAX 刷新内容的整个页面
- python - 只接受一个范围内的输入