1

I am trying to do a CI script on GitLab where it connects to my VPS, Git Pulls and then runs the python script and exits, while leaving my python script running 24/7 (until the next pipeline run/commit).

How do I do get it do make my python script run 24/7?

script:
    - 'apt-get update -y && apt-get install openssh-client -y && apt-get install sshpass -y '
    - sshpass -p "password" ssh -o StrictHostKeyChecking=no root@host "cd repo/ && git pull && python3 main.py"

This is my current script, however, when main.py is run, the pipeline is left in limbo since the script is eternally running.

How do I make it so the pipeline script runs the script and exits, leaving it on tmux or something like that?

1 Answer 1

1

Check first if this is a tty allocation issue, as in here.

ssh -t -o ...
    ^^

Also consider calling just one script (which does the cd, git pull and python3)

That way you can test the script locally (on 'host'), and then call it remotely (through ssh)


From the OP Kevin A. in the comments:

my code goes through a loop that reruns the code every 45mins or so, so the script is constantly running. It's a web scraper constantly updating a cloud database.

The idea is to get GitLab CI to ignore waiting for the script to finish running, its just is to, stop previous script running, git pull and run the script again

Another approach would be to make the script scrap one-time (and exit), but call said script through a GitLab scheduled pipeline.
That way, no more freeze.

Sign up to request clarification or add additional context in comments.

9 Comments

Ill try it. Is it worth the effort to go through the effort of making my program into a docker container? It's a web scraper so it would run on loop and I'm using GitLab so would that allow me to easily build and run it each time I have a new commit?
I've run it using ssh -t -o... but the GitLab CI seems to be waiting for the script to finish running, and not running the script then exiting (allowing the script to run indefinitely, until next push)
@KevinA. just for testing, if you replace the python3 call by a simple echo, does it work? Or even a python3 call like python3 -c "print('test')"
@KevinA. Try and replace your main.py with that one echo (to confirm it works), and then restore bit by bit main.py original content to understand what call/command is triggering the freeze.
@KevinA. Yes, you can use a cron-like syntax.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.