Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue Inquiry: Intention to Integrate gitea-actions-runner and github-act-runner as Service #1

Closed
oilrich25 opened this issue Dec 2, 2023 · 22 comments · Fixed by #2

Comments

@oilrich25
Copy link
Contributor

oilrich25 commented Dec 2, 2023

Problem Description:

I am currently in the process of self-hosted deployment and opt not to use Docker. Instead, I intend to deploy gitea-actions-runner and github-act-runner directly. However, I've encountered difficulties when attempting to run these two tools as service services, particularly on Windows systems, where an error code 1503 is thrown.

I noticed that a user has submitted a pull request for the official act_runner and has added support for running it as a service on Windows, Linux, and macOS. It appears that they utilized the "github.com/kardianos/service" framework for wrapping act_runner into a service.

Supplementary Information:

I also observed that gitlab-runner follows a similar approach by adopting the "github.com/kardianos/service" framework for encapsulation. This transformation enables gitlab-runner to function as a genuine service. The relevant code can be found at commands/multi.go and commands/service.go.

./gitlab-runner install           // install daemon  
./gitlab-runner start             //  start daemon

My Questions:

@ChristopherHX, are you interested in adding gitea-actions-runner and github-act-runner as service services? Have you considered adopting a similar approach, using the "github.com/kardianos/service" framework or other similar solutions, to simplify the deployment and runtime processes across different platforms? Thank you for your response.

@oilrich25
Copy link
Contributor Author

Packaged through the "github.com/kardianos/service" framework to become a real windows service service
232

@ChristopherHX
Copy link
Owner

are you interested in adding gitea-actions-runner and github-act-runner as service services?

I'm open to add this to both projects. Yes it would be great if some platforms have integrated service support. Till today I only self-hosted the linux binaries via a custom systemd script / ran from cli.

Have you considered adopting a similar approach, using the "github.com/kardianos/service" framework or other similar solutions, to simplify the deployment and runtime processes across different platforms?

I didn't look that much into golang native services support. As far as I know only windows has special reqirements for binaries to run as service.

In case "github.com/kardianos/service" would break building some binary platforms I would prefer to put it into a conditionally compiled file, liky the survey integration.

@oilrich25
Copy link
Contributor Author

are you interested in adding gitea-actions-runner and github-act-runner as service services?

I'm open to add this to both projects. Yes it would be great if some platforms have integrated service support. Till today I only self-hosted the linux binaries via a custom systemd script / ran from cli.

Have you considered adopting a similar approach, using the "github.com/kardianos/service" framework or other similar solutions, to simplify the deployment and runtime processes across different platforms?

I didn't look that much into golang native services support. As far as I know only windows has special reqirements for binaries to run as service.

In case "github.com/kardianos/service" would break building some binary platforms I would prefer to put it into a conditionally compiled file, liky the survey integration.

Yes, it supports multiple platforms, including windows, linux, and macos. Windows can start a native windows service through https://github.com/kardianos/service/blob/master/example/simple/main.go#L47.

Using github.com/kardianos/service will not break its structure. Simple and easy to use.

@oilrich25
Copy link
Contributor Author

"github.com/kardianos/service" framework does not break its build. I would prefer to integrate into the gitea-actions-runner and github-act-runner projects

@oilrich25
Copy link
Contributor Author

oilrich25 commented Dec 2, 2023

@ChristopherHX
Copy link
Owner

ChristopherHX commented Dec 2, 2023

"github.com/kardianos/service" framework does not break its build. I would prefer to integrate into the gitea-actions-runner and github-act-runner projects

We will see, github-act-runner compiles for a os like plan9 not all go packages compile for unusual go targets. Most notable the docker go package in 2021.

Obviously this can be enabled for windows/linux/macOS and would compile to them

@oilrich25
Copy link
Contributor Author

oilrich25 commented Dec 3, 2023

"github.com/kardianos/service" framework does not break its build. I would prefer to integrate into the gitea-actions-runner and github-act-runner projects

We will see, github-act-runner compiles for a os like plan9 not all go packages compile for unusual go targets. Most notable the docker go package in 2021.

Obviously this can be enabled for windows/linux/macOS and would compile to them

Great, you could try adding support for the "github.com/kardianos/service" framework to gitea-actions-runner for windows/linux/macOS?

As for github-act-runner, can you create a branch to indicate that service install only supports windows/linux/macOS?

The advantage of the "github.com/kardianos/service" framework is that it can be installed and uninstalled at any time. gitea-actions-runner adds this feature, which means that deployment on multiple machines does not require additional writing of cumbersome systemd scripts.

@ChristopherHX
Copy link
Owner

ChristopherHX commented Dec 3, 2023

See

I need to look later into a graceful stop / handling service failure..

svc install, svc start, svc stop and svc uninstall are available via these changes

We need to think about service description, name etc. e.g. allow to customize it.

You could also use this example to configure as service https://github.com/kardianos/service/tree/master/example/runner

@oilrich25
Copy link
Contributor Author

See

I need to look later into a graceful stop / handling service failure..

svc install, svc start, svc stop and svc uninstall are available via these changes

We need to think about service description, name etc. e.g. allow to customize it.

You could also use this example to configure as service https://github.com/kardianos/service/tree/master/example/runner

Thank you very much for your patch, but I seem to have encountered some problems. I will provide you with a detailed report later. I will help you conduct all-round testing on windows, linux, and macos M2

@oilrich25
Copy link
Contributor Author

oilrich25 commented Dec 4, 2023

The commands svc install, svc start, svc stop, and svc uninstall under Linux and Windows are working well based on my current testing. If there are any issues later, I will notify you promptly. However, there seem to be some problems under macOS.

BUG Reproduction on macOS:

oilrich25deMac-mini:gitea-actions-runner oilrich25$ ./act_runner svc install
Error: open /Library/LaunchDaemons/gitea-actions-runner.plist: permission denied 
oilrich25deMac-mini:gitea-actions-runner oilrich25$ sudo ./act_runner svc install

At this point, act_runner attempts to install the gitea-actions-runner.plist file in the /Library/LaunchDaemons/ directory.

At the same time, in the file /Users/oilrich25/gitea-actions-runner.err.log :

oilrich25deMac-mini:~ oilrich25$ sudo cat /Users/oilrich25/gitea-actions-runner.err.log 
Error: open github-act-runner-log.txt: permission denied
Error: open github-act-runner-log.txt: permission denied
Error: open github-act-runner-log.txt: permission denied

And in the file /Users/oilrich25/gitea-actions-runner.out.log :

oilrich25deMac-mini:~ oilrich25$ sudo cat /Users/oilrich25/gitea-actions-runner.out.log 
oilrich25deMac-mini:~ oilrich25$ 

After executing the start command:

oilrich25deMac-mini:gitea-actions-runner oilrich25$ sudo ./act_runner svc start

The content of /Users/oilrich25/gitea-actions-runner.err.log becomes:

oilrich25deMac-mini:~ oilrich25$ sudo cat /Users/oilrich25/gitea-actions-runner.err.log 
Error: open github-act-runner-log.txt: permission denied
Error: open github-act-runner-log.txt: permission denied
Error: open github-act-runner-log.txt: permission denied
Error: open github-act-runner-log.txt: permission denied
Error: open github-act-runner-log.txt: permission denied

@oilrich25
Copy link
Contributor Author

I also tried executing it directly through the command, but it seems to still have the same error.

oilrich25Mac-mini:gitea-actions-runner oilrich25$ ./act_runner svc run --working-directory /Users/oilrich25/Desktop/gitea-actions-runner
Error: open github-act-runner-log.txt: permission denied

Then I added sudo to execute, and the result was ok

oilrich25Mac-mini:gitea-actions-runner oilrich25$ sudo ./act_runner svc run --working-directory /Users/jinhengzhang/Desktop/gitea-actions-runner
INFO[0000] Starting runner daemon                       
time="2023-12-04T14:13:45+08:00" level=info msg="polling the remote server" arch=arm64 capacity=1 endpoint="http://192.168.31.102:3000/" os=darwin
time="2023-12-04T14:13:45+08:00" level=info msg="poller: request stage from remote server" func=pollTask
time="2023-12-04T14:13:50+08:00" level=info msg="poller: request stage from remote server" func=pollTask
time="2023-12-04T14:13:55+08:00" level=info msg="poller: request stage from remote server" func=pollTask
time="2023-12-04T14:14:00+08:00" level=info msg="poller: request stage from remote server" func=pollTask
time="2023-12-04T14:14:00+08:00" level=info msg="task 2284 repo is oilrich25/simple-go-action http://192.168.31.102:3000 http://192.168.31.102:3000/"
time="2023-12-04T14:14:04+08:00" level=info msg="poller: request stage from remote server" func=pollTask
time="2023-12-04T14:14:09+08:00" level=info msg="poller: request stage from remote server" func=pollTask      

@ChristopherHX
Copy link
Owner

I made the extra logfile optional and no longer stop failing open it. Seems like macOS has it's own log file, windows has no traditional log files.

This sounds like your service user / normal user has no permission to write to that file, did you ever ran the svc as root and later as regular user?

@oilrich25
Copy link
Contributor Author

I made the extra logfile optional and no longer stop failing open it. Seems like macOS has it's own log file, windows has no traditional log files.

This sounds like your service user / normal user has no permission to write to that file, did you ever ran the svc as root and later as regular user?

oilrich25Mac-mini:gitea-actions-runner oilrich25$ sudo ./act_runner svc run --working-directory /Users/jinhengzhang/Desktop/gitea-actions-runner
INFO[0000] Starting runner daemon                       
time="2023-12-04T14:13:45+08:00" level=info msg="polling the remote server" arch=arm64 capacity=1 endpoint="http://192.168.31.102:3000/" os=darwin
time="2023-12-04T14:13:45+08:00" level=info msg="poller: request stage from remote server" func=pollTask
time="2023-12-04T14:13:50+08:00" level=info msg="poller: request stage from remote server" func=pollTask
time="2023-12-04T14:13:55+08:00" level=info msg="poller: request stage from remote server" func=pollTask
time="2023-12-04T14:14:00+08:00" level=info msg="poller: request stage from remote server" func=pollTask
time="2023-12-04T14:14:00+08:00" level=info msg="task 2284 repo is oilrich25/simple-go-action http://192.168.31.102:3000 http://192.168.31.102:3000/"
time="2023-12-04T14:14:04+08:00" level=info msg="poller: request stage from remote server" func=pollTask
time="2023-12-04T14:14:09+08:00" level=info msg="poller: request stage from remote server" func=pollTask 

oilrich25Mac-mini:~ oilrich25$ ps aux |grep Runner.Worker
root             67209  37.0  1.2 411627248 104096 s006  R+    2:22下午   0:01.19 /Users/oilrich25/Desktop/gitea-actions-runner/actions-runner/bin/Runner.Worker spawnclient 142 145
root             67208   0.2  1.7 411208560 144288 s006  S+    2:22下午   0:00.89 pwsh actions-runner-worker.ps1 actions-runner/bin/Runner.Worker
oilrich25     67438   0.0  0.0 408495824   1152 s007  U+    2:22下午   0:00.00 grep Runner.Worker

@oilrich25
Copy link
Contributor Author

oilrich25 commented Dec 4, 2023

In summary, although the service is installed through sudo ./act_runner svc install, and the service is run through sudo ./act_runner svc start. But it seems that only act_runner is running under root, and actions-runner/bin/Runner.Worker is not running under root.

@oilrich25
Copy link
Contributor Author

oilrich25 commented Dec 4, 2023

By the way, ChristopherHX/gitea-actions-runner also has a bug that the action yaml does not support the setting of working-directory. That is, the working-directory setting is invalid.

for example:

name:Build

on:
   - push
   - pull_request

defaults:
   run:
     shell: bash
     working-directory: src

I will open another issue later to describe the problem.

@ChristopherHX
Copy link
Owner

But it seems that only act_runner is running under root, and actions-runner/bin/Runner.Worker is not running under root.

based on your psaux is pwsh also run as root, which don't have a Runner.Worker process? grep is running as your user

@oilrich25
Copy link
Contributor Author

oilrich25 commented Dec 4, 2023

But it seems that only act_runner is running under root, and actions-runner/bin/Runner.Worker is not running under root.

based on your psaux is pwsh also run as root, which don't have a Runner.Worker process? grep is running as your user

No, if I pass the command sudo ./act_runner svc run --working-directory /Users/oilrich25/Desktop/gitea-actions-runner can capture Runner.Worker and act_runner running under root

@oilrich25
Copy link
Contributor Author

If I simply run the command ./act_runner svc run --working-directory /Users/oilrich25/Desktop/gitea-actions-runner and capture only the console output Error: open github-act-runner-log.txt: permission denied, at this time act_runner is in exit status, so it cannot capture the Runner.Worker and act_runner running status.

@ChristopherHX
Copy link
Owner

If I simply run the command ./act_runner svc run --working-directory /Users/oilrich25/Desktop/gitea-actions-runner and capture only the console output Error: open github-act-runner-log.txt: permission denied, at this time act_runner is in exit status, so it cannot capture the Runner.Worker and act_runner running status.

Please pull my last change to the pr and rebuilt the binary. This is no longer a fatal error

@oilrich25
Copy link
Contributor Author

oilrich25 commented Dec 4, 2023

If I simply run the command ./act_runner svc run --working-directory /Users/oilrich25/Desktop/gitea-actions-runner and capture only the console output Error: open github-act-runner-log.txt: permission denied, at this time act_runner is in exit status, so it cannot capture the Runner.Worker and act_runner running status.

Please pull my last change to the pr and rebuilt the binary. This is no longer a fatal error

#cebafc3

oilrich25Mac-mini:gitea-actions-runner oilrich25$ sudo ./act_runner svc install
oilrich25Mac-mini:gitea-actions-runner oilrich25$ sudo ./act_runner svc start

oilrich25Mac-mini:~ oilrich25$ cat /var/log/gitea-actions-runner.out.log 

oilrich25Mac-mini:~ oilrich25$ cat /var/log/gitea-actions-runner.err.log 
time="2023-12-04T14:52:50+08:00" level=info msg="Starting runner daemon"
time="2023-12-04T14:52:50+08:00" level=fatal msg="invalid configuration" error="unexpected end of JSON input"
oilrich25Mac-mini:~ oilrich25$ 

@ChristopherHX
Copy link
Owner

So it cannot read .runner either due to permission denied.

Can you try a different more permissive folder for the service?

What are the owner / permissions of the .runner file

@oilrich25
Copy link
Contributor Author

oilrich25 commented Dec 4, 2023

So it cannot read .runner either due to permission denied.

Can you try a different more permissive folder for the service?

What are the owner / permissions of the .runner file

Based on cebafc3, add the following code to run in UserService mode and successfully solve the problem.

if runtime.GOOS == "darwin" {
svcConfig.EnvVars = map[string]string{
"PATH": "/opt/homebrew/bin:/opt/homebrew/sbin:/usr/bin:/bin:/usr/sbin:/sbin",
}
svcConfig.Option = service.KeyValue{
"KeepAlive": true,
"RunAtLoad": true,
"UserService": os.Getuid() != 0,
}
}

ok fix

oilrich25Mac-mini:gitea-actions-runner oilrich25$ ps aux|grep act_runner
oilrich25     68777   0.1  0.2 409821952  18416   ??  S     3:06下午   0:00.15 /Users/oilrich25/Desktop/gitea-actions-runner/act_runner svc run --working-directory /Users/oilrich25/Desktop/gitea-actions-runner
oilrich25     68988   0.0  0.0 408636112   1536 s006  S+    3:12下午   0:00.00 grep act_runner
oilrich25Mac-mini:gitea-actions-runner oilrich25$ ps aux|grep Runner.Worker
oilrich25     68991   0.0  0.0 408626896   1408 s006  S+    3:12下午   0:00.00 grep Runner.Worker
oilrich25Mac-mini:gitea-actions-runner oilrich25$ 
oilrich25Mac-mini:gitea-actions-runner oilrich25$ ps aux|grep Runner.Worker
oilrich25     68992  50.1  1.6 411181696 134544   ??  R     3:12下午   0:00.62 pwsh actions-runner-worker.ps1 actions-runner/bin/Runner.Worker
oilrich25     68994   0.0  0.0 408636112   1504 s006  S+    3:12下午   0:00.00 grep Runner.Worke

Note: Be sure to add "PATH": "/opt/homebrew/bin:/opt/homebrew/sbin:/usr/bin:/bin:/usr/sbin:/sbin",, otherwise it will cause ## [Error]exec: "pwsh": executable file not found in $PATH

Refer to https://github.com/gitlabhq/gitlab-runner/blob/main/commands/service_darwin.go#L12C1-L16C3 in gitlab-runner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants