From bcbd6f7eae4a6176ba9347ad808e3de0de6261ad Mon Sep 17 00:00:00 2001 From: xOtanix Date: Thu, 24 Oct 2024 22:26:57 +0300 Subject: [PATCH 1/2] add check gh runner status --- .../manifests/github_runner/service.pp | 22 +++++++++++++++++++ .../github_runner/actions-runner-check.sh.erb | 0 .../github_runner/actions-runner.service.erb | 21 ++++++++---------- 3 files changed, 31 insertions(+), 12 deletions(-) create mode 100644 modules/profile/templates/github_runner/actions-runner-check.sh.erb diff --git a/modules/profile/manifests/github_runner/service.pp b/modules/profile/manifests/github_runner/service.pp index 131d777..e1cbf2b 100644 --- a/modules/profile/manifests/github_runner/service.pp +++ b/modules/profile/manifests/github_runner/service.pp @@ -11,6 +11,7 @@ $github_runner_user = $user $github_runner_group = $group $systemd_file = '/etc/systemd/system/actions-runner.service' + $service_check_file = '/usr/local/bin/actions-runner-check.sh' file { $systemd_file: ensure => file, content => template('profile/github_runner/actions-runner.service.erb'), @@ -20,6 +21,14 @@ notify => Exec['daemon-reload'], } + file { $service_check_file: + ensure => file, + content => template('profile/github_runner/actions-runner-check.sh.erb'), + owner => $user, + group => $group, + mode => 'a+x', + } + exec { 'daemon-reload': command => '/usr/bin/systemctl daemon-reload', refreshonly => true, @@ -46,4 +55,17 @@ user => 'root', minute => '*/5', } + + cron { 'check-status': + command => [ + 'bash', + $service_check_file, + ].join(' '), + environment => [ + 'PATH=/bin:/usr/bin:/usr/sbin:/usr/local/bin', + "MAILTO=${mailto}" + ], + user => 'root', + minute => '*/5', + } } diff --git a/modules/profile/templates/github_runner/actions-runner-check.sh.erb b/modules/profile/templates/github_runner/actions-runner-check.sh.erb new file mode 100644 index 0000000..e69de29 diff --git a/modules/profile/templates/github_runner/actions-runner.service.erb b/modules/profile/templates/github_runner/actions-runner.service.erb index e9f7c68..32e1612 100644 --- a/modules/profile/templates/github_runner/actions-runner.service.erb +++ b/modules/profile/templates/github_runner/actions-runner.service.erb @@ -1,14 +1,11 @@ -[Unit] -Description=GitHub self-hosted runner -After=network.target +#!/bin/bash -[Service] -Type=simple -ExecStart=<%= @runner_package_directory %>/run.sh -WorkingDirectory=<%= @runner_package_directory %> -User=<%= @github_runner_user %> -Group=<%= @github_runner_group %> -Restart=on-failure +SERVICE="actions-runner" -[Install] -WantedBy=multi-user.target +# Check if the service is active +if ! systemctl is-active --quiet $SERVICE; then + ih-aws autoscaling mark-unhealthy +fi +if systemctl is-failed --quiet $SERVICE; then + ih-aws autoscaling mark-unhealthy +fi From 1a5a42947721a377f7762ed29e969189fd819db6 Mon Sep 17 00:00:00 2001 From: xOtanix Date: Thu, 24 Oct 2024 22:27:28 +0300 Subject: [PATCH 2/2] add check gh runner status --- .../github_runner/actions-runner-check.sh.erb | 11 ++++++++++ .../github_runner/actions-runner.service.erb | 21 +++++++++++-------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/modules/profile/templates/github_runner/actions-runner-check.sh.erb b/modules/profile/templates/github_runner/actions-runner-check.sh.erb index e69de29..32e1612 100644 --- a/modules/profile/templates/github_runner/actions-runner-check.sh.erb +++ b/modules/profile/templates/github_runner/actions-runner-check.sh.erb @@ -0,0 +1,11 @@ +#!/bin/bash + +SERVICE="actions-runner" + +# Check if the service is active +if ! systemctl is-active --quiet $SERVICE; then + ih-aws autoscaling mark-unhealthy +fi +if systemctl is-failed --quiet $SERVICE; then + ih-aws autoscaling mark-unhealthy +fi diff --git a/modules/profile/templates/github_runner/actions-runner.service.erb b/modules/profile/templates/github_runner/actions-runner.service.erb index 32e1612..e9f7c68 100644 --- a/modules/profile/templates/github_runner/actions-runner.service.erb +++ b/modules/profile/templates/github_runner/actions-runner.service.erb @@ -1,11 +1,14 @@ -#!/bin/bash +[Unit] +Description=GitHub self-hosted runner +After=network.target -SERVICE="actions-runner" +[Service] +Type=simple +ExecStart=<%= @runner_package_directory %>/run.sh +WorkingDirectory=<%= @runner_package_directory %> +User=<%= @github_runner_user %> +Group=<%= @github_runner_group %> +Restart=on-failure -# Check if the service is active -if ! systemctl is-active --quiet $SERVICE; then - ih-aws autoscaling mark-unhealthy -fi -if systemctl is-failed --quiet $SERVICE; then - ih-aws autoscaling mark-unhealthy -fi +[Install] +WantedBy=multi-user.target