Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running background command using & causes the step to halt and timeout #40

Closed
asymness opened this issue Mar 23, 2020 · 6 comments
Closed

Comments

@asymness
Copy link

asymness commented Mar 23, 2020

I am executing a command like this in the step:
python script.py &
echo Done

This causes the step to get stuck in progress after echoing Done and eventually timeout (after ~10 minutes) whereas it should be done in 10 seconds.
However, if I kill the process (python script.py) manually by SSH'ing to the server, the step completes execution successfully. How can I fix this problem and run background commands successfully?

Other variants I have tried:
nohup python script.py &
disown

@asymness
Copy link
Author

Fixed by redirecting all output:
nohup python script.py > nohup.out 2> nohup.err < /dev/null &

@kadukm
Copy link

kadukm commented Mar 29, 2020

@asymness thank you! I faced the same problem. Do you know why it works like this? I tried to find an answer to this question for several hours but found nothing.

@asymness
Copy link
Author

For some reason, the action keeps waiting for stdin, stdout, and stderr. That's why we need to redirect all three outputs to free the terminal. That's all I could gather from this...

@Saljooq
Copy link

Saljooq commented Apr 26, 2023

So I've had a very similar issue with docker compose. As per the suggestion I tried redirecting all three fds (input, output and error), but no luck, my github actions keep running and then timing out and failing.

Here's the script:

nohup sudo docker compose --env-file ./.config/.env up > nohup.out 2> nohup.err < /dev/null &

Any help would be appreciated :)

@mogendi
Copy link

mogendi commented Nov 16, 2023

@Saljooq moving nohup to a command directly under the list of commands on the action worked for me for some reason.

some something like:
.github/deploy.yaml

uses: appleboy/ssh-action@master
        with:
          key: ${{ secrets.KEY  }}
          host: ${{ secrets.HOSTNAME  }}
          username: ${{ secrets.USERNAME  }}
          script: |
            ./some_script

./some_script

nohup ./some_other_script > nohup.out 2> nohup.err < /dev/null &

I changed it to:
.github/deploy.yaml

uses: appleboy/ssh-action@master
        with:
          key: ${{ secrets.KEY  }}
          host: ${{ secrets.HOSTNAME  }}
          username: ${{ secrets.USERNAME  }}
          script: |
            nohup ./some_script > nohup.out 2> nohup.err < /dev/null &

@binc4t
Copy link

binc4t commented Dec 1, 2024

Fixed by redirecting all output: nohup python script.py > nohup.out 2> nohup.err < /dev/null &

wish I saw this earlier. Thank you bro💐

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants