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

Systemd socket activation support #5035

Closed
2 of 7 tasks
DevelAngel opened this issue Oct 7, 2018 · 5 comments · Fixed by #7274
Closed
2 of 7 tasks

Systemd socket activation support #5035

DevelAngel opened this issue Oct 7, 2018 · 5 comments · Fixed by #7274
Labels
type/feature Completely new functionality. Can only be merged if feature freeze is not active. type/proposal The new feature has not been accepted yet but needs to be discussed first.

Comments

@DevelAngel
Copy link

  • Gitea version (or commit ref): 1.5.1
  • Git version: 2.18.0
  • Operating system: Gentoo on ARM64 (Raspberry Pi 3B)
  • Database:
    • PostgreSQL (version 10.4)
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
    • Not relevant

Description

I have a little home webserver with an ARM64 Raspberry PI 3B with Gentoo Linux where I run services like Nextcloud, Gitea, DjangoCMS, Prosody IM. The webserver nginx handles the HTTP (port 80) and HTTPS (port 443) connections using Let's encrypt certificates. I prefer filesystem sockets to let nginx communicate with other web applications like Gitea. But systemd socket activation works also with network sockets.

Systemd has a nice feature to start these web applications only when they are needed. To be able to use that feature, socket activation support is needed in the web application. DjangoCMS, for example, will shut down after 10 minutes without interaction to save resources. When a new connection arrives in nginx, DjangoCMS service will be started again. It would be nice to use that feature with Gitea, too.

My gitea.service file looks similar to the contrib version. I created a gitea.socket file which defines an unix filesystem socket, thus [server] PROTOCOL and HTTP_ADDR is not needed in settings.

Solution (Patch)

I patched the 1.5.1 version to integrate the systemd socket activation support. But I think, it needs some discussion before bringing it upstream. I have taken the www-apps/gitea 1.4.3 ebuild from the gentoo repository, which is used by the Gentoo portage package manager, and have modified it to fetch version 1.5.1 and integrate the patch. I pushed all changes to my portage overlay repository for gitea.

There you can find the patch here: Before doing the switch, the systemd socket activation is asked for listeners activation.Listeners(). If it does not return an error, at least one listener is defined and socket activation is used. If it returns an error code, do the normal switch statement as before.

The systemd socket activation needs the vendor code for github.com/coreos/go-systemd/activation. No further dependencies are needed, as I noticed. In my gentoo ebuild, I pull the go-systemd version 17 (lastest version) and moved the content to folder vendor/github.com/coreos/go-sytemd.

After discussion (and first review of patch), I can prepare the commit for socket activation and a pull request.

@lunny lunny added type/proposal The new feature has not been accepted yet but needs to be discussed first. type/feature Completely new functionality. Can only be merged if feature freeze is not active. labels Oct 7, 2018
@clarfonthey
Copy link
Contributor

I would also love this.

@mscherer
Copy link
Contributor

mscherer commented Nov 7, 2020

I would also be interested by the feature, but I think the patch would have more attention if it was a PR and not a url to go on a ebuild. From a quick look, I do not see anything problematic.

@zeripath
Copy link
Contributor

zeripath commented Nov 8, 2020

This is already supported and has been since gitea 1.11. #7274 et al.

@andreymal
Copy link

Could someone instruct on how to properly set up socket activation? When I created gitea.socket according to the example, gitea.service is succesfully triggered and started, but then everything just hangs without errors.

It would be nice to see a more detailed description in the documentation.

@techknowlogick
Copy link
Member

@andreymal please refrain from commenting on closed issues as comments will get lost on closed issues. If you have a support request please post on our forum https://discourse.gitea.io/

@go-gitea go-gitea locked and limited conversation to collaborators Dec 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type/feature Completely new functionality. Can only be merged if feature freeze is not active. type/proposal The new feature has not been accepted yet but needs to be discussed first.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants