Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run python script as service, needed virtualenv (ubuntu)

I need to leave running a Python script in a remote server. All OK so far. The problem is I need using virtualenv because I have no sudo privileges and I only can install and use pip packages using virtualenv. To ripple the curl, my script need a docker container running, so it's needed two terminals running.

I access through ssh and I can run it, but execution keeps attached to my terminals. I've tried using background execution but docker container ignore it and Python script stops when I close terminal. I also tried to put all my instructions (boot docker container, activate virtualenv and then run Python script) in a bash script but it neither works, I get the following error activating virtualenv:

source: not found

The question is: is there any way to leave my script running as daemon or service?

(There is no problem with privileges, I can ask admin for doing all needed steps)

Thanks in advance!

like image 274
Carlos Avatar asked Oct 24 '25 16:10

Carlos


1 Answers

There are python-daemon and python-service packages that you may use to create python-based daemons and/or services.

Though I suppose it might be enough just to use nohup python path/to/script.py &.

like image 65
Linards Kalvans Avatar answered Oct 26 '25 04:10

Linards Kalvans



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!