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

Enhancement: add support for unix socket listen #272

Merged
merged 2 commits into from
Feb 23, 2024

Conversation

ae-govau
Copy link
Contributor

What is the purpose of this change? What does it change?

Enhancement: add support for unix socket listen

Refactor main for easier testing, graceful termination and be able to prin the listening port after startup.

Add tests for both TCP and Unix socket listening.

The change to add unix socket listening was pretty simple, but the PR got bit bigger then I made some refactors to main.go to make it easier for testing (by removing use of gloabl variables).

Was the change discussed in an issue or in the forum before?

Yes. This is the rest-server part of restic/restic#4287

(it also includes the tiny change I proposed in #271)

Checklist

  • I have enabled maintainer edits for this PR
  • I have added tests for all changes in this PR
  • I have added documentation for the changes (in the manual)
  • There's a new file in changelog/unreleased/ that describes the changes for our users (template here)
  • I have run gofmt on the code in all commits
  • All commit messages are formatted in the same style as the other commits in the repo
  • I'm done, this Pull Request is ready for review

Copy link
Member

@MichaelEischer MichaelEischer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please split the PR into two parts. The signal handling improvement and the unix socket support don't belong together into the same PR. The changelog entries must also be renamed, see the comment below.

changelog/unreleased/print-resolved-listen-addr Outdated Show resolved Hide resolved
changelog/unreleased/graceful-shutdown-server Outdated Show resolved Hide resolved
changelog/unreleased/print-resolved-listen-addr Outdated Show resolved Hide resolved
@ae-govau
Copy link
Contributor Author

ae-govau commented Feb 4, 2024

Split PR as requestd. Note this PR currently has 2 commits, the first is also in separate PR #273 , but the test added in this PR for the new functionality needs it, so I've included it here.

Once #273 lands, I can rebase this one.

@MichaelEischer
Copy link
Member

Can you rebase the PR now that #273 is merged?

@ae-govau
Copy link
Contributor Author

Rebased. Tests are failing due to calens not supporting a syntax specified on a verbatim tag. Happy to either remove that here, else I've made a PR to calens to support: restic/calens#18

Copy link
Member

@MichaelEischer MichaelEischer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. There are just a few minor changelog tweaks remaining.

changelog/unreleased/pull-272 Outdated Show resolved Hide resolved
changelog/unreleased/pull-272 Outdated Show resolved Hide resolved
changelog/unreleased/pull-272 Outdated Show resolved Hide resolved
Copy link
Member

@MichaelEischer MichaelEischer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

@MichaelEischer MichaelEischer merged commit 0c73518 into restic:master Feb 23, 2024
5 checks passed
truecharts-admin referenced this pull request in truecharts/public Jul 26, 2024
…8c23 by renovate (#24421)

This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [restic/rest-server](https://github.com/restic/rest-server) | minor
| `0.12.1` -> `0.13.0` |

---

> [!WARNING]
> Some dependencies could not be looked up. Check the Dependency
Dashboard for more information.

---

### Release Notes

<details>
<summary>restic/rest-server (restic/rest-server)</summary>

###
[`v0.13.0`](https://github.com/restic/rest-server/blob/HEAD/CHANGELOG.md#Changelog-for-rest-server-0130-2024-07-26)

[Compare
Source](https://github.com/restic/rest-server/compare/v0.12.1...v0.13.0)

\============================================

The following sections list the changes in rest-server 0.13.0 relevant
to users. The changes are ordered by importance.

## Summary

- Chg [#&#8203;267](https://github.com/restic/rest-server/issues/267):
Update dependencies and require Go 1.18 or newer
- Chg [#&#8203;273](https://github.com/restic/rest-server/issues/273):
Shut down cleanly on TERM and INT signals
- Enh [#&#8203;271](https://github.com/restic/rest-server/issues/271):
Print listening address after start-up
- Enh [#&#8203;272](https://github.com/restic/rest-server/issues/272):
Support listening on a unix socket

## Details

- Change
[#&#8203;267](https://github.com/restic/rest-server/issues/267):
Update dependencies and require Go 1.18 or newer

Most dependencies have been updated. Since some libraries require newer
language
features, support for Go 1.17 has been dropped, which means that
rest-server now
    requires at least Go 1.18 to build.


[https://github.com/restic/rest-server/pull/267](https://github.com/restic/rest-server/pull/267)

- Change
[#&#8203;273](https://github.com/restic/rest-server/issues/273): Shut
down cleanly on TERM and INT signals

Rest-server now listens for TERM and INT signals and cleanly closes down
the
    http.Server and listener when receiving either of them.

This is particularly useful when listening on a unix socket, as the
server will
    now remove the socket file when it shuts down.


[https://github.com/restic/rest-server/pull/273](https://github.com/restic/rest-server/pull/273)

- Enhancement
[#&#8203;271](https://github.com/restic/rest-server/issues/271): Print
listening address after start-up

When started with `--listen :0`, rest-server would print `start server
on :0`

The message now also includes the actual address listened on, for
example `start
server on 0.0.0.0:37333`. This is useful when starting a server with an
    auto-allocated free port number (port 0).


[https://github.com/restic/rest-server/pull/271](https://github.com/restic/rest-server/pull/271)

- Enhancement
[#&#8203;272](https://github.com/restic/rest-server/issues/272):
Support listening on a unix socket

It is now possible to make rest-server listen on a unix socket by
prefixing the
socket filename with `unix:` and passing it to the `--listen` option,
for
    example `--listen unix:/tmp/foo`.

This is useful in combination with remote port forwarding to enable a
remote
    server to backup locally, e.g.:

        rest-server --listen unix:/tmp/foo &
ssh -R /tmp/foo:/tmp/foo user@host restic -r
rest:http+unix:///tmp/foo:/repo backup


[https://github.com/restic/rest-server/pull/272](https://github.com/restic/rest-server/pull/272)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Renovate
Bot](https://github.com/renovatebot/renovate).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC44LjEiLCJ1cGRhdGVkSW5WZXIiOiIzOC44LjEiLCJ0YXJnZXRCcmFuY2giOiJtYXN0ZXIiLCJsYWJlbHMiOlsiYXV0b21lcmdlIiwidXBkYXRlL2RvY2tlci9nZW5lcmFsL25vbi1tYWpvciJdfQ==-->
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Aug 6, 2024
Changelog for rest-server 0.13.0 (2024-07-26)
============================================

The following sections list the changes in rest-server 0.13.0 relevant
to users. The changes are ordered by importance.

Summary
-------

 * Chg #267: Update dependencies and require Go 1.18 or newer
 * Chg #273: Shut down cleanly on TERM and INT signals
 * Enh #271: Print listening address after start-up
 * Enh #272: Support listening on a unix socket

Details
-------

 * Change #267: Update dependencies and require Go 1.18 or newer

   Most dependencies have been updated. Since some libraries require newer language
   features, support for Go 1.17 has been dropped, which means that rest-server now
   requires at least Go 1.18 to build.

   restic/rest-server#267

 * Change #273: Shut down cleanly on TERM and INT signals

   Rest-server now listens for TERM and INT signals and cleanly closes down the
   http.Server and listener when receiving either of them.

   This is particularly useful when listening on a unix socket, as the server will
   now remove the socket file when it shuts down.

   restic/rest-server#273

 * Enhancement #271: Print listening address after start-up

   When started with `--listen :0`, rest-server would print `start server on :0`

   The message now also includes the actual address listened on, for example `start
   server on 0.0.0.0:37333`. This is useful when starting a server with an
   auto-allocated free port number (port 0).

   restic/rest-server#271

 * Enhancement #272: Support listening on a unix socket

   It is now possible to make rest-server listen on a unix socket by prefixing the
   socket filename with `unix:` and passing it to the `--listen` option, for
   example `--listen unix:/tmp/foo`.

   This is useful in combination with remote port forwarding to enable a remote
   server to backup locally, e.g.:

   ```
   rest-server --listen unix:/tmp/foo &
   ssh -R /tmp/foo:/tmp/foo user@host restic -r rest:http+unix:///tmp/foo:/repo backup
   ```

   restic/rest-server#272


Changelog for rest-server 0.12.1 (2023-07-09)
============================================

The following sections list the changes in rest-server 0.12.1 relevant
to users. The changes are ordered by importance.

Summary
-------

 * Fix #230: Fix erroneous warnings about unsupported fsync
 * Fix #238: API: Return empty array when listing empty folders
 * Enh #217: Log to stdout using the `--log -` option

Details
-------

 * Bugfix #230: Fix erroneous warnings about unsupported fsync

   Due to a regression in rest-server 0.12.0, it continuously printed `WARNING:
   fsync is not supported by the data storage. This can lead to data loss, if the
   system crashes or the storage is unexpectedly disconnected.` for systems that
   support fsync. We have fixed the warning.

   restic/rest-server#230
   restic/rest-server#231

 * Bugfix #238: API: Return empty array when listing empty folders

   Rest-server returned `null` when listing an empty folder. This has been changed
   to returning an empty array in accordance with the REST protocol specification.
   This change has no impact on restic users.

   restic/rest-server#238
   restic/rest-server#239

 * Enhancement #217: Log to stdout using the `--log -` option

   Logging to stdout was possible using `--log /dev/stdout`. However, when the rest
   server is run as a different user, for example, using

   `sudo -u restic rest-server [...] --log /dev/stdout`

   This did not work due to permission issues.

   For logging to stdout, the `--log` option now supports the special filename `-`
   which also works in these cases.

   restic/rest-server#217
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 this pull request may close these issues.

2 participants