Systemd socket activation support #2383

Closed
opened 2025-11-02 04:34:22 -06:00 by GiteaMirror · 5 comments
Owner

Originally created by @DevelAngel on GitHub (Oct 7, 2018).

  • 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.

Originally created by @DevelAngel on GitHub (Oct 7, 2018). <!-- 1. Please speak English, this is the language all of us can speak and write. 2. Please ask questions or configuration/deploy problems on our Discord server (https://discord.gg/NsatcWJ) or forum (https://discourse.gitea.io). 3. Please take a moment to check that your issue doesn't already exist. 4. Please give all relevant information below for bug reports, because incomplete details will be handled as an invalid report. --> - Gitea version (or commit ref): 1.5.1 - Git version: 2.18.0 - Operating system: Gentoo on ARM64 (Raspberry Pi 3B) - Database: - [x] PostgreSQL (version 10.4) - [ ] MySQL - [ ] MSSQL - [ ] SQLite - Can you reproduce the bug at https://try.gitea.io: - [ ] Yes (provide example URL) - [ ] No - [x] 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](https://www.freedesktop.org/software/systemd/man/systemd.socket.html) 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](https://github.com/DevelAngel707/gentoo-overlay-da707-go/tree/master/www-apps/gitea). There you can find the patch [here](https://github.com/DevelAngel707/gentoo-overlay-da707-go/blob/master/www-apps/gitea/files/gitea-1.5.1-systemd-socket-activation-support.patch): 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](https://github.com/DevelAngel707/gentoo-overlay-da707-go/blob/95081e6c6eddaba8e4a3f5501c3eb9c57cdc44a8/www-apps/gitea/gitea-1.5.1.ebuild#L15) (lastest version) and moved the content to [folder `vendor/github.com/coreos/go-sytemd`](https://github.com/DevelAngel707/gentoo-overlay-da707-go/blob/95081e6c6eddaba8e4a3f5501c3eb9c57cdc44a8/www-apps/gitea/gitea-1.5.1.ebuild#L35). After discussion (and first review of patch), I can prepare the commit for socket activation and a pull request.
GiteaMirror added the type/featuretype/proposal labels 2025-11-02 04:34:22 -06:00
Author
Owner

@clarfonthey commented on GitHub (Jan 7, 2019):

I would also love this.

@clarfonthey commented on GitHub (Jan 7, 2019): I would also love this.
Author
Owner

@mscherer commented on GitHub (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.

@mscherer commented on GitHub (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.
Author
Owner

@zeripath commented on GitHub (Nov 8, 2020):

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

@zeripath commented on GitHub (Nov 8, 2020): This is already supported and has been since gitea 1.11. #7274 et al.
Author
Owner

@andreymal commented on GitHub (Dec 11, 2020):

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.

@andreymal commented on GitHub (Dec 11, 2020): Could someone instruct on how to properly set up socket activation? When I created `gitea.socket` according to [the example](https://github.com/go-gitea/gitea/blob/master/contrib/systemd/gitea.service#L25), `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.
Author
Owner

@techknowlogick commented on GitHub (Dec 11, 2020):

@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/

@techknowlogick commented on GitHub (Dec 11, 2020): @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/
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#2383