简体   繁体   English

如何使 systemd 服务使用 conda env through.sh 运行 python 项目

[英]how do I make systemd service to run python project with conda env through .sh

I'm trying to run my code on startup through systemd I want it to run using the current environment cause it's a bit big and I don't want to reinstall all of that我正在尝试通过 systemd 在启动时运行我的代码我希望它使用当前环境运行,因为它有点大,我不想重新安装所有这些

I have a.sh file that activates the python environment and calls the starting script on a big project I then made a service that calls that sh我有一个激活 python 环境并在一个大项目上调用启动脚本的 .sh 文件然后我创建了一个调用该 sh 的服务

[Unit]
Description=service to start code 

[Service]
User=root
WorkingDirectory=/usr/bin
ExecStart=/home/administrator/Downloads/open_app/out_cam_app.sh



[Install]
WantedBy=multi-user.target

#https://transang.me/three-ways-to-create-a-startup-script-in-ubuntu/

but this fives these errors但这会解决这些错误

22 18:17:56 smart-fk systemd[1]: Started service to start 
22 18:17:56 smart-fk my_bas_Script.sh[1417930]: /path/to/my_bas_Script.sh: line 3: /root/anaconda3/bin/activa>
22 18:17:56 smart-fk out_cam_app.sh[1417931]: /path/to/my_bas_Script.sh: line 6: python: command not found
22 18:17:56 smart-fk out_cam_app.sh[1417932]: /path/to/my_bas_Script.sh: line 7: conda: command not found
22 18:17:56 smart-fk systemd[1]: my_Service.service: Main process exited, code=exited, status=127/n/a
22 18:17:56 smart-fk systemd[1]: my_Service.service: Failed with result 'exit-code'.

my bash script looks like this in case it's the problem (it works on its own tho)我的 bash 脚本看起来像这样,以防出现问题(它可以自行工作)

#!/bin/bash
source ~/anaconda3/bin/activate env_name 
cd path/to/python/project
python python_start_point.py
conda deactivate

I also tried making the service call the code directly and that made the code work stackover flow post that I used for that then start downloading some files, which I can't do on this machine so it failed cause of the connection time out我还尝试让服务直接调用代码,并使代码在我使用的stackover流帖子中工作,然后开始下载一些文件,我无法在这台机器上执行此操作,因此导致连接超时失败

What am I doing wrong here?我在这里做错了什么?

Remove the WorkingDirectory=/usr/bin and add the executable path to:删除WorkingDirectory=/usr/bin并将可执行路径添加到:

Environment="PATH=/sbin:/bin:/usr/sbin:/usr/bin"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM