简体   繁体   中英

How do I restart a python script running inside of a screen using a bash script?

Okay here's my situation:

On a server I have a screen session (which was initiated using screen -S python-script ) running a python script inside of it.

I make changes to this project by pushing to a git repo. When I want to have the changes reflected on the project, I ssh into the server, screen -x python-script and then Ctrl-c to send keyboard interrupt, then git pull origin master and then ./run_script.py

I want to do something clever and make my project able to update and restart itself. Another small python server would live on this remote server and listen for a request from my project, this python server would then use subprocess to run a bash script which would update and restart my project.

It's a bit convoluted I know, and I'd really like some suggestions if there's a better way to do what I'm wanting.

Right now if I could formulate a bash script to do what I'm looking for, then I know this would work (probably..).

1) Use nohup instead of screen, redirect stdout to a rotative log if you're interested in the outputs. Store the PID somewhere.

2) Set a 'deployment' branch on your repo.

3) Set a cronjob on the server to pull 'deployment' branch each x minutes.

4) Use a githook to trigger an start/stop each time there's a new commit on your 'deployment' branch. Use the stored pid to kill it.


EDIT:

If you need to kill via Ctrl + C, just send SIGINT with kill then wait for the pid to die.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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