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

add better daemon support #37

Merged
merged 7 commits into from
Jul 30, 2024
Merged

add better daemon support #37

merged 7 commits into from
Jul 30, 2024

Conversation

mazunki
Copy link
Contributor

@mazunki mazunki commented Jul 29, 2024

As I mentioned in issue #36 , I wanted to add support for running the service in the background. This PR does just that, and also adds some cleaner shutdown to the controller. I've added some better logging statements and better --help documentation.

Keep in mind the logger is using the same logger as it used to on the terminal, meaning the rich colours we see may be interpreted weirdly by some editors when viewing them. That said, I feel like if that's an issue for some people, that's the user's editor's issue, and not really our fault. If this is a problem, we may choose to add some configuration to it (as we might want to do with the verbosity, fwiw).

The main changes is that amdfan daemon by default now redirects the output to /var/log/amdfan.log. This can be reverted with --no-logfile or --stdout, or a manual logfile can be set with --logfile=.

After some discussion with some init-smart people, I decided that it's better to explicitly request the daemon to run in the background with --background. By default it will stay running in the foreground, as expected by most init systems.

Some commits include more details

Closes: #36

the main intention with this is to have different defaults for when the
amdfan is run as a service vs when a user wants to simply run it on the
terminal

additionally, the daemon now supports forking itself off in the
background, which is the expected behaviour on some process managers,
such as openrc. on that note, this is a good read:
https://jdebp.uk/FGA/unix-daemon-design-mistakes-to-avoid.html

Signed-off-by: Mazunki Hoksaas <rolferen@gmail.com>
with this, we are closing down the application safely, and additionally
adding support for some nice interfacing

Signed-off-by: Mazunki Hoksaas <rolferen@gmail.com>
@@ -39,10 +39,12 @@ These are all addressed in Amdfan, and as long as I’ve still got some AMD card
Usage: amdfan [OPTIONS] COMMAND [ARGS]...

Options:
--help Show this message and exit.
-v, --version Show the version and exit.
Copy link
Owner

Choose a reason for hiding this comment

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

liking this, was thinking of adding it as well, but got sidetracked with work. I pulled down your branch and and just messing with it locally.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep, i feel you. i've had some time to tinker lately, which is why i've overhauled a bunch of things. i hope it doesn't feel like i'm gutting the project :P

also the order of the parameters for the --stdout / --no-logfile were
causing the daemon to not be able to start up with any commands as the
stdout kwarg was being passed to the function when it was expecting
no_logfile.
@mcgillij
Copy link
Owner

Looks good, I pushed up a couple minor changes to deal with the flake8 issues being reported: https://github.com/mcgillij/amdfan/actions/runs/10153195863/job/28076076158#step:5:12

There was a pretty significant bug though with the order of the parameters preventing any of the daemon commands from working.

image

So I just changed the order so it would start up.

@@ -95,9 +95,10 @@ class FileDescriptorOpt(click.ParamType):
show_default=True,
)
@click.option(
"--stdout",
Copy link
Owner

Choose a reason for hiding this comment

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

This line breaks the daemon from the cli, moving it down a line fixes it. I pushed up a commit to get this working.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah, i should've tested that before i blindly added it after reading the pr notes, lol. i thought "hm, the flag name may suggest there's no logging at all, instead of stdout-ing it". i kinda wish --no-${opt} was supported by click natively tbh. good catch

@mcgillij mcgillij merged commit 3b6811c into mcgillij:main Jul 30, 2024
2 checks passed
@mazunki
Copy link
Contributor Author

mazunki commented Jul 31, 2024

nice :)

anything else we should change before updating the version? maybe the min_speed thingie, or the QA issue we briefly talked about? once the version is released i'll bump the ebuild on gentoo, as the current version there is broken

@mcgillij
Copy link
Owner

I have a local branch started to cut a new release, but if you want to get anything else prior lemme know. Otherwise I'll push it up tonight if I have time, after work.

@mazunki
Copy link
Contributor Author

mazunki commented Jul 31, 2024

I think that's fine. I kind of want to modify how we load the logger and add to the monitor output, so to make it more configurable (also including an option to test the config file before attempting to reload the service), but I think we can do that at another time

@mcgillij
Copy link
Owner

yeah being able to validate the config would be nice

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.

[feat] backgrounding the daemon
2 participants