Report this

What is the reason for this report?

Unable to get python app running from a remote and close connection

Posted on July 2, 2021

I have a bitbucket pipeline file bitbucket-pipelines.yml which executes the file deploy.sh on my DO droplet each time a new commit is made to the main branch.

On DO, deploy.sh in turn calls pull.sh which performs a set of actions:

  1. If it exists, kill the existing refgator-api.py process
  2. Change to the directory containing the repo
  3. Pull from the repo
  4. Change to the directory containing refgator-api.py
  5. Execute python3 refgator-api.py

It’s at this last step that my bitbucket pipeline will continue executing (consuming all my build minutes).

Is there any way that I can run the file refgator-api.py and exiting the session whilst still allowing it to run?

I’ve attempted using nohup and & as well as exit. Neither result in a state where the pipeline disconnects from the DO droplet and stops and the application is running on the droplet.

bitbucket-pipelines.yml

image: atlassian/default-image:latest

pipelines:
    default:
      - step:
          script:
              - cat ./deploy.sh | ssh -tt root@xxx.xxx.xxx.xxx
              - echo "Deploy step finished"

deploy.sh

echo "Deploy Script Started"
cd
sh pull.sh
echo "Deploy script finished execution"

pull.sh

## Kills the current process which is restarted later
kill -9 $(pgrep -f refgator-api.py)

## And change to directory containing the repo
cd eg-api

## Pull from the repo
export GIT_SSH_COMMAND="ssh -i ~/.ssh/id_rsa.pub"
GIT_SSH_COMMAND="ssh -v" git pull git@bitbucket.org:myusername/myrepo.git

## Change to directory containing the python file to execute
cd refgator-api
python3 refgator-api.py &



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
0

Hi there @christianmacedo,

I could suggest using Supervisor as a more robust solution. You can follow the steps on how to install Supervisor here:

https://www.digitalocean.com/community/tutorials/how-to-install-and-manage-supervisor-on-ubuntu-and-debian-vps

You could again put the python3 refgator-api.py and then specify the path to the script in the supervisor config file as described in the tutorial:

command=/path/to/your_script.sh

Hope that this helps! Regards, Bobby

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.