8000 Create Anubis FreeBSD rc.d script by pswilde · Pull Request #274 · TecharoHQ/anubis · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Create Anubis FreeBSD rc.d script #274

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

Merged
merged 2 commits into from
Apr 15, 2025
Merged

Create Anubis FreeBSD rc.d script #274

merged 2 commits into from
Apr 15, 2025

Conversation

pswilde
Copy link
Contributor
@pswilde pswilde commented Apr 15, 2025

I have added an rc.d script for FreeBSD so Anubis can be run as a daemon.
Typically, this file would be copied to /usr/local/etc/rc.d and variables set in /etc/rc.conf (i.e. to enable it, and set the environment file).
Tested and running well on my Forgejo Instance - https://forge.notnull.space/

Checklist:

  • Added a description of the changes to the [Unreleased] section of docs/docs/CHANGELOG.md
  • Added test cases to the relevant parts of the codebase
  • Ran integration tests npm run test:integration (unsupported on Windows, please use WSL)

add freebsd rc.d script so can be run as a freebsd daemon

Signed-off-by: Paul Wilde <31094984+pswilde@users.noreply.github.com>
@pswilde pswilde changed the title Create anubis.freebsd Create Anubis FreeBSD rc.d script Apr 15, 2025
command=/usr/sbin/daemon
procname=${anubis_bin}
pidfile=/var/run/anubis.pid
logfile=/var/log/anubis.log
Copy link
Contributor
@Xe Xe Apr 15, 2025

Choose a reason for hiding this comment

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

Is this where stdout/stderr is written?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, correct.
The daemon command has a -o flag which can write the output to a log file.
https://man.freebsd.org/cgi/man.cgi?daemon(8)

Signed-off-by: Paul Wilde <31094984+pswilde@users.noreply.github.com>
Copy link
Contributor
@Xe Xe 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!

@Xe Xe enabled auto-merge (squash) April 15, 2025 12:01
@Xe Xe merged commit 8689143 into TecharoHQ:main Apr 15, 2025
3 checks passed
start_precmd=anubis_precmd

anubis_precmd () {
export $(xargs < ${anubis_environment_file})
Copy link
@dlangille dlangille May 1, 2025

From man 8 rc.subr:

		   ${name}_env_file
			     A	file  to source	for environmental variables to
			     run command with.	Note: all the variables	 which
			     are  being	 assigned in this file are going to be
			     exported into the environment of command.

Might that be useful to you?

Copy link
Contributor Author
@pswilde pswilde May 1, 2025

Choose a reason for hiding this comment

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

Useful.
Do you mean removing the precmd and giving the anubis_env var values via rc.conf?
personally i prefer using an environment file (portability mainly) so the method created caters for this
however, I see no reason why those who prefer setting environment variables in rc.conf should be disadvantaged and there's no reason why both options can't be available, so yes, very useful indeed.
I suppose it's reasonable to have both in such a way that anubis_env can be set in rc.conf and if an environment file is specified too, the values can be added to anubis_env and continue to work as intended

Choose a reason for hiding this comment

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

To be clear, I have not tried anubis_env yet so it may not work as advertised.

Useful. Do you mean removing the precmd and giving the anubis_env var values via rc.conf?

No. I think the use of ${name}_env_file might mean line 27 can be removed - I have not tested this yet. I'm just on my first test deployment of Anubis

personally i prefer using an environment file (portability mainly) so the method created caters for this however, I see no reason why those who prefer setting environment variables in rc.conf should be disadvantaged and there's no reason why both options can't be available, so yes, very useful indeed. I suppose it's reasonable to have both in such a way that anubis_env can be set in rc.conf and if an environment file is specified too, the values can be added to anubis_env and continue to work as intended

From what I see, this should allow both, for example, the following two line in /etc/rc.conf achieve identical results:

e.g.

anubis_env='POLICY_FNAME=/usr/local/etc/anubis-freshports.json TARGET=http://localhost:8080'
anubis_env_file="/usr/local/etc/anubis.env"

where:

% cat /usr/local/etc/anubis.env
POLICY_FNAME=/usr/local/etc/anubis-freshports.json
TARGET=http://localhost:8080

Users can use either or a combination of both. Testing would reveal if specifying the same VAR in both places indicates a precedence (e.g. that one approach always overrides the other).

At present, I am using the rc.d script from the FreeBSD package - anubis.in - it passes in anubis_args to anubis. For example, I have these settings:

 [11:24 test-nginx01 dvl ~] % grep anubis /etc/rc.conf
anubis_enable="YES"
anubis_args="-target http://localhost:8080 -bind :8923 -difficulty 2 -cookie-domain=freshports.org -policy-fname=/usr/local/etc/anubis-freshports.json"

When started, I get this:

[11:24 test-nginx01 dvl ~] % ps auwwx | grep anubis  
www        20041  0.0  0.0   13856  2320  -  IsJ  19:52    0:00.00 daemon: /usr/local/sbin/anubis[20042] (daemon)
www        20042  0.0  0.0 1306896 24652  -  IJ   19:52    0:10.60 /usr/local/sbin/anubis -target http://localhost:8080 -bind :8923 -difficulty 2 -cookie-domain=freshports.org -policy-fname=/usr/local/etc/anubis-freshports.json

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great, thanks. This makes sense. I'll do some testing.
Yep, I'm aware of the ports version - and the creator of that one and I have already spoken. That one also has some better daemon usage so may be worth migrating a bit of that in too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is good stuff. I've tested and each variable can work with the other
${name}_env_file gets read first, and environment variables configured. Followed by ${name}_env, which only overrides matching env var key values.
${name}_args is of course more anubis specific as to what priority values have over environment variables, but this all appears to be fine so values in ${name}_args override matching keys in both environment vars.

Looking nice!
I've made some adjustments and put them in PR #427

@pswilde pswilde mentioned this pull request May 4, 2025
3 tasks
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.

3 participants
0