Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Starting a python script on a remote machine which starts a bash script

I have what I believe to be a fairly unique problem for a script I use to stand up webservers on remote machines.

I have a controller script which after checking a ledger initiates a "builder" script on a remote machine. Part of this builder script calls a bash script which starts a process I want to continue running after both scripts are finished.

My only problem is that the builder script seems to finish (gets to the last line) but doesn't seem to return control to the controller script.

For the record I am using subprocess.call in the controller script (to initiate a ssh call) to start the builder script on the remote machine. I have toyed with various ways of initiating the bash script in the builder script but it seems the builder won't return control to the controller until kill the processes spawned by the bash script.

Things I have tried:

pid=os.spawnl(os.P_NOWAIT,dest+'/start_background_script.sh')
pid=subprocess.Popen([dest+'/start_background_script.sh'])
os.system(dest+'/start_background_script.sh &')
pid=os.spawnl(os.P_NOWAIT,dest+'/start_background_script.sh')

The bash script is written to that you execute it and it backgrounds two processes and then returns control.

Any recommendations?

like image 439
Malforus Avatar asked Apr 14 '26 01:04

Malforus


1 Answers

Sound like a job for fabric to me.

Fabric wraps the handling of shell-calls on remote (and also local) machines for you.

like image 113
Don Question Avatar answered Apr 15 '26 18:04

Don Question



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!