1

Context

In my .devcontainer.json file I have postCreateCommand and postStartCommand jobs that point to startup.sh script. My idempotent .startup.sh script start github's self-hosted runner with nohup process - that way the runner runs in background and don't stop it accidentally.

.devcontainer.json

"postCreateCommand": ".devcontainer/scripts/startup.sh",
"postStartCommand": ".devcontainer/scripts/startup.sh"

startup.sh

echo "Configure GitHub Runner"
./config.sh remove --token $SELF_HOSTED_RUNNER_TOKEN
./config.sh --url https://github.com/$GITHUB_REPOSITORY --unattended --token $SELF_HOSTED_RUNNER_TOKEN --name $RepositoryName --labels "self-hosted,Linux,X64,$RepositoryName"

echo "Start GitHub Runner"
nohup ./run.sh & > _diag/runner.log

Problem

When I create a new GitHub Codespace, my runners appear in Offline mode. However, when I run my startup.sh script from within my GitHub Codespace manually then it appears Idle as expected.

Question

How to start GitHub self-hosted runner on devcontainer startup so, it's in Idle state every time I start/restart my codespace?

Lukasz Dynowski
  • 11,169
  • 9
  • 81
  • 124

1 Answers1

1

I found the cause of this insane behavior. Apparently, github self-hosted runner doesn't like to be run as a background process! The problem was & in nohup command.

I ended up running my startup.sh script only with postStartCommand and, github's self hosted runner run.sh script without nohup

Don't

nohup ./run.sh &

Do

./run.sh
Lukasz Dynowski
  • 11,169
  • 9
  • 81
  • 124