user4948798
user4948798

Reputation: 2086

GitHub action self-host runner as service fails

I have installed GitHub self-hosted runner on my Ubuntu system. Getting below error when i try to configure it as service.

$ sudo ./svc.sh start
Failed to start actions.runner._services.Linux-Host01.service: Unit actions.runner._services.Linux-Host01.service is not loaded properly: Exec format error.
See system logs and 'systemctl status actions.runner._services.Linux-Host01.service' for details.
Failed: failed to start actions.runner._services.Linux-Host01.service
$ systemctl status actions.runner._services.Linux-Host01.service
● actions.runner._services.Linux-Host01.service - GitHub Actions Runner (_services.Linux-Host01)
   Loaded: error (Reason: Exec format error)
   Active: inactive (dead)
$ cat /etc/systemd/system/actions.runner._services.Linux-Host01.service
[Unit]
Description=GitHub Actions Runner (_services.Linux-Host01)
After=network.target

[Service]
ExecStart=/home/admin.user/actions-runner/runsvc.sh
User=admin.user
WorkingDirectory=/home/admin.user/actions-runner
KillMode=process
KillSignal=SIGTERM
TimeoutStopSec=5min

[Install]
WantedBy=multi-user.target
$ sudo journalctl -u actions.runner._services.Linux-Host01.service -f

Aug 04 08:40:47 Linux-Host01 systemd[1]: /etc/systemd/system/actions.runner._services.Linux-Host01.service:7: Invalid user/group name or numeric ID: admin.user

Additionally have provided executable permission to actions.runner._services.Linux-Host01.service but still it results same error.

What is wrong here?

Upvotes: 2

Views: 15565

Answers (4)

Daniel Viglione
Daniel Viglione

Reputation: 9407

The issue can be the value of the environment variable $SUDO_USER. Inside svc.sh, it captures it:

run_as_user=${arg_2:-$SUDO_USER}

And then uses sed to inject the user value into the systemd service file:

sed "s/{{User}}/${run_as_user}/g;

This becomes an issue if you performed all the installation of the runner as root and then $SUDO_USER evaluates to a nonroot user. For example, if you are automating the script in the user_data script of an EC2 Instance, make sure to change the ownership of the actions-runner directory to the user that evaluates to $SUDO_USER. In my case, since I use the SSM Agent to connect to ec2 instances, it will be ssm-user (if you use amazon linux 2023, it would be ec2-user and if you use ubuntu, then it would be ubuntu as user).

chown ssm-user -R /actions-runner
./svc.sh install
./svc.sh start

Upvotes: 0

Muasya
Muasya

Reputation: 104

This simply means you've not installed the runner

  1. sudo ./svc.sh install // install the runner
  2. sudo ./svc.sh start // then start it

Remember, this is the best way to go about it than using the ./run.sh script, as the runner will always be running in the background.

Use sudo ./svc.sh status to confirm that the runner is up and running.

Upvotes: 7

user4948798
user4948798

Reputation: 2086

I have changed User=admin.user to User=uid in the /etc/systemd/system/actions.runner._services.Linux-Host01.service file and then executed

systemctl daemon-reload

Now action service started and it is running fine.

Upvotes: 1

euTIMER
euTIMER

Reputation: 751

Good morning,

First of all stop the service:

sudo ./svc.sh stop

Then make sure you have given permissions to the user:

sudo usermod -a -G <USER>

Now try to start the service:

sudo ./svc.sh start

And tell me if this works when check the status.

If not works please do the same but sudo permissions:

sudo su

And then try again all without sudo command because you are actually on root.

Have a great day!

Upvotes: 0

Related Questions