0

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

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

[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)

#!/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 thatthen start downloading some files , which I can't do on this machine so it failed cause of the connection time out

What am I doing wrong here ?

Mai
  • 114
  • 1
  • 11
  • 1
    I’m voting to close this question because From the tag: systemd questions should be for *programming questions* using systemd or its libraries. Questions about *configuring the daemon* (including writing unit files) are better directed to Unix & Linux: https://unix.stackexchange.com. – Rob Sep 24 '22 at 22:11
  • 2
    I really try to use this community the right way, but this harsh community votes me down instead of telling me how to fix it whenever I do something they believe is remotely wrong. do you really think the whole question is invalid because of a tag that needs to be fixed ? – Mai Sep 25 '22 at 08:36
  • The tag is not what makes your question off topic. – Rob Sep 25 '22 at 09:07

1 Answers1

1

Remove the WorkingDirectory=/usr/bin and add the executable path to:

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

Niraj Nandane
  • 1,318
  • 1
  • 13
  • 24