Options to prevent auto updating self-hosted runner

We’re trying to run self-hosted runners inside our kubernetes cluster, it worked fine until our image didn’t contain the latest runner:

Runner update in progress, do not shutdown runner.Downloading 2.161.0 runner
Waiting for current job finish running.
Generate and execute update script.
Runner will exit shortly for update, should back online within 10 seconds.

I know that runner will automatically update to latest version and exit for a while. However, this update would fail every time and exit, resulting in kubernetes spinning up another Pod, which finally we see an infinite loop.Is there an option to disable such behavior in ./run.sh?

Have you configured your self-hosted runner as a service? Configure the self-hosted runner as a service can avoid automatic update failures.
You can reference this earlier reported ticket: https://github.community/t5/GitHub-Actions/self-hosted-runner-update-protocol/td-p/37930

Thanks for your reply, but it seems that running as service didn’t help, is it something to do with container/kubernetes environment? This is output:

Runner update in progress, do not shutdown runner.
11/28/2019 7:04:38 PM Downloading 2.161.0 runner
11/28/2019 7:04:41 PM Waiting for current job finish running.
11/28/2019 7:04:41 PM Generate and execute update script.
11/28/2019 7:04:41 PM Runner will exit shortly for update, should back online within 10 seconds.
11/28/2019 7:04:44 PM /_work/_update.sh: line 96: /bin/mv: No such file or directory
11/28/2019 7:04:44 PM Runner listener exited with error code 3
11/28/2019 7:04:44 PM Runner listener exit because of updating, re-launch runner in 5 seconds.
11/28/2019 7:04:49 PM Starting Runner listener with startup type: service
11/28/2019 7:04:49 PM Started listener process
11/28/2019 7:04:49 PM events.js:177
11/28/2019 7:04:49 PM throw er; // Unhandled 'error' event
11/28/2019 7:04:49 PM ^
11/28/2019 7:04:49 PM
11/28/2019 7:04:49 PM Error: spawn /bin/Runner.Listener ENOENT
11/28/2019 7:04:49 PM at Process.ChildProcess._handle.onexit (internal/child_process.js:264:19)
11/28/2019 7:04:49 PM at onErrorNT (internal/child_process.js:456:16)
11/28/2019 7:04:49 PM at processTicksAndRejections (internal/process/task_queues.js:84:9)
11/28/2019 7:04:49 PM Emitted 'error' event at:
11/28/2019 7:04:49 PM at Process.ChildProcess._handle.onexit (internal/child_process.js:270:12)
11/28/2019 7:04:49 PM at onErrorNT (internal/child_process.js:456:16)
11/28/2019 7:04:49 PM at processTicksAndRejections (internal/process/task_queues.js:84:9) {
11/28/2019 7:04:49 PM errno: 'ENOENT',
11/28/2019 7:04:49 PM code: 'ENOENT',
11/28/2019 7:04:49 PM syscall: 'spawn /bin/Runner.Listener',
11/28/2019 7:04:49 PM path: '/bin/Runner.Listener',
11/28/2019 7:04:49 PM spawnargs: ['run', '--startuptype', 'service']
11/28/2019 7:04:49 PM }

We figured out there was something wrong with our WORKDIR settings, which cannot be root folder in this case.

I “fixed” this by prepending to container cmd “; sleep infinity”. So when “run.sh” stops for update (the restarts in background), the “sleep infinity” command keeps the container alive until the update successfully finishes and it continues to work.

My Dockerfile:

FROM krallin/ubuntu-tini:bionic

ARG RUNNER_DOWNLOAD_LINK="https://github.com/actions/runner/releases/download/v2.165.2/actions-runner-linux-x64-2.165.2.tar.gz"

ENV RUNNER_CONFIG_ARGS="--url https://github.com/foo/bar --token BAZ"

RUN apt update \
  && apt install -y curl wget htop ssh iputils-ping git \
  && apt clean && rm -rf /var/lib/apt/lists/* /tmp/*

RUN adduser --disabled-password --gecos '' github

USER github

RUN mkdir -p /home/github/runner

WORKDIR /home/github/runner

USER root

ADD $RUNNER_DOWNLOAD_LINK ./runner.tar.gz

RUN chown github ./*

USER github

RUN tar xf runner.tar.gz

CMD ["bash", "-c", "./config.sh ${RUNNER_CONFIG_ARGS}; ./run.sh; sleep infinity"]