Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

sh: 1: rsync: not found

I made a python application and its running fine. So now i made a service still all fine. last part of my program was to sync some files to a different server, rsync command works when i run it as my own users. only when it runs with the server it doesnt work.:

import os
..
...
os.system("rsync --remove-source-files -p -e 'ssh -i ~/.ssh/id_rsa -o PubkeyAcceptedKeyTypes=+ssh-rsa -o HostKeyAlgorithms=+ssh-rsa' -avq --chmod=a+rwx /source remoteuser@serviceip:/destination/")

When I check journalctl I can see this error:

 python3[361897]: sh: 1: rsync: not found

Here my service:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

[Unit]
Description=Job Server Service
After=network.target

[Service]
WorkingDirectory=/home/myuser/project
Environment="PATH=/home/myuser/project/projectenv/bin"
ExecStart=/home/myuser/project/projectenv/bin/python3 /home/myuser/project/job_server.py
User=myuser
Group=myuser
Environment=PYTHONUNBUFFERED=1


[Install]
WantedBy=multi-user.target

First I thought its because the key file ~/.ssh/id_rsa is not accessable by the service but error message indicates it cant find rsync. is this because of the python virtual environment?

When I go into the virtual environment I can run the rsync without any issue. Can someone point me in the right direction?

source projectenv/bin/activate

>Solution :

In your service definition you set:

Environment="PATH=/home/myuser/project/projectenv/bin"

This makes the path only contain that directory. You probably want something more like:

Environment="PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/myuser/project/projectenv/bin"

i.e. something with paths to programs such as rsync.

There’s no real elegant way of appending to the path. various hacks I’ve seen would involve changing the execstart line to something like:

bash -c "PATH=/home/myuser/project/projectenv/bin:$PATH exec python3 /home/myuser/project/job_server.py"

instead of the line setting PATH explicitly.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading