How to shutdown self hosted runners gracefully

Hi,

I have self hosted runners. How do i shutdown the self hosted runner gracefully? I could just remove the runner with configure.sh but what happens if at the same time an action runs? will github reschedule it on another runner? If not what should the protocol be here?

Thanks

@david-gang,

You can configure your self-hosted runner to run in interactive mode. In this mode, generally the runner is Offline status when it is not connected to GitHub.
To connect the runner to GitHub so that the workflow jobs can run on the runner, you need to execute ‘./run.sh’ (Linux and macOS) or ‘.\run.cmd’ (Windows) in the runner installation directory, and you will see the message like as below on machine’s terminal.

✔ Connected to GitHub
2020-08-13 07:07:49z: Listening for jobs

Keep the terminal open, then the runner will become Idle status to wait the workflow jobs to use it.
If you close the terminal or press Ctrl+C, the runner will stop the connection with GitHub and back to Offline status.

About your questions:

  1. How do i shutdown the self hosted runner gracefully?

    If you want only one job in the workflow runs on the specified runner, and after the job completed the runner can be back to Offline status automatically. You can use the ‘–once’ option when starting the runner.
    On Linux and macOS:

    ./run.sh --once
    

    On Windows:

    .\run.cmd --once
    
  2. I could just remove the runner with configure.sh but what happens if at the same time an action runs? will github reschedule it on another runner? If not what should the protocol be here?

    When a job is running on a self-hosted runner, if you shutdown the runner, the job will be cancelled. GitHub won’t assigned another runner to continue running the job.

@david-gang ,

How are things going?
Have you tried my above suggestion that run your self-hosted runner in interactive mode, and use the ‘–once’ option to let runner only run one job every time?
Is the suggestion helpful to you?
Please try it, and if you have any questions this topic, feel free to tell us.

That’s not a good solutoin as i deploy the self hosted runners to gcp. Essentially every runner acts in it’s own VM. I am not running anything interactively. I think that what i would need is autoscaling abilities from github actions itself.

@david-gang,

Unlike GitHub-hosted runners, GitHub does not provide any methods to discard or shutdown (Offline) the self-hosted runners after the job competed. There also are not any GitHub APIs to do this.

I think that what i would need is autoscaling abilities from github actions itself.

If your projects really need this feature, I recommend that you can directly report a feature request here. That will allow you to directly interact with the appropriate engineering team, and make it more convenient for the engineering team to collect and categorize your suggestions.