Skip to content
This repository has been archived by the owner on Dec 21, 2021. It is now read-only.

Add first version of integration with systemd #43

Merged
merged 18 commits into from
Feb 12, 2021

Conversation

soenkeliebau
Copy link
Member

@soenkeliebau soenkeliebau commented Feb 2, 2021

This is a first version of systemd integration.
Working so far are:

  • generating a unit file
  • enabling the service (create symlink)
  • starting the service
  • stopping the service
  • distinguish between session and systemd connection to systemd

I do not expect this version to be ready to merge, but it can serve as first basis for review.

I have more or less accidentally bundled a lot of clippy fixes in here as well, apologies!

fixes #11
fixes #9
fixes #6
fixes #5

Save changes to branch.

Working version (compiles and produces file - not a running service) - still needs environment variables.

Added restart policy.

Working version of unit file creation.

Store work

Added rough structure of systemd module / might be refactored into a crate at a later time.
@project-bot project-bot bot added this to In progress in Stackable Feb 2, 2021
@soenkeliebau
Copy link
Member Author

Not sure what issue the clippy action has looks a bit like the known bug when creating a PR from a remote repo.

@lfrancke lfrancke moved this from In progress to Review in progress in Stackable Feb 3, 2021
src/config/config_documentation/session.adoc Show resolved Hide resolved
src/config/config_documentation/session.adoc Outdated Show resolved Hide resolved
src/config/config_documentation/session.adoc Outdated Show resolved Hide resolved
src/config/mod.rs Show resolved Hide resolved
src/provider/mod.rs Outdated Show resolved Hide resolved
src/provider/systemdmanager/service.rs Outdated Show resolved Hide resolved
src/provider/systemdmanager/service.rs Outdated Show resolved Hide resolved
src/provider/systemdmanager/service.rs Outdated Show resolved Hide resolved
src/provider/systemdmanager/service.rs Outdated Show resolved Hide resolved
);
// Get a mutable reference to the first element of the command array as we might need to
// add the package directory to this to make it an absolute path
let binary = match command.get_mut(0) {
Copy link
Member

Choose a reason for hiding this comment

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

This match could be changed to a .... ok_or_else? I believe...

Copy link
Member Author

Choose a reason for hiding this comment

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

Unless I am mistaken that would not work with the early return?

@lfrancke
Copy link
Member

lfrancke commented Feb 7, 2021

Trying to build this right now I have one more comment: It'd be good if you could add a sentence to the README about the requirement for dbus headers etc.
In CentOS the required package is called dbus-devel

@lfrancke lfrancke added the type/enhancement New feature or request label Feb 9, 2021
@lfrancke lfrancke added this to the Milestone #1 milestone Feb 9, 2021
Copy link
Member

@lfrancke lfrancke left a comment

Choose a reason for hiding this comment

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

I really really promise that it's only minor stuff left now!

src/provider/systemdmanager/manager.rs Outdated Show resolved Hide resolved
src/provider/systemdmanager/manager.rs Outdated Show resolved Hide resolved
src/provider/systemdmanager/manager.rs Outdated Show resolved Hide resolved

// If no external file was created check if the file currently exists
if !linked_unit_file {
debug!("Target file [{:?}] already exists", &target_file);
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this in the wrong place? (Should be in the inner if?)
You never check wheter some file exists, here, do you? All you check if the option is "Some", no?

And can't you combine the two ifs?

if !linked_unit_file && target_file.exists {

Copy link
Member Author

Choose a reason for hiding this comment

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

I think the code is correct as it is, I've added a comment to address your question above as well, which hopefully explains what I am doing..

Copy link
Member Author

@soenkeliebau soenkeliebau Feb 11, 2021

Choose a reason for hiding this comment

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

Actually, doing some more thinking and testing, I think the entire block should be reworked a little, but it works for now.

Copy link
Member

Choose a reason for hiding this comment

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

I think I disagree.

When I see the debug statement "Target file already exists" it has not actually been checked yet if it exists.
There's nothing in that first if block other than the debug! statement.

This is what I'm proposing:

        if !linked_unit_file && target_file.exists() {
            // Target file already exists, remove if force is supplied, otherwise abort
            debug!("Target file [{:?}] already exists", &target_file);
            if force {
                self.delete_unit_file(&unit_name)?;
            } else {
                return Err(anyhow!(
                    "Target unit file [{:?}] exists and force parameter was not specified.",
                    target_file
                ));
            }
        }

Copy link
Member Author

Choose a reason for hiding this comment

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

I have pushed a commit that should hopefully fix the entire write / delete file topic.

src/provider/systemdmanager/manager.rs Outdated Show resolved Hide resolved
}
}
} else {
warn!("No unit definitions found, not starting anything!");
Copy link
Member

Choose a reason for hiding this comment

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

Missing context which pod we're talking about. May be worth starting a tracing span somewhere here in the state machine as well

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I have not paid special attention to log message context in this pull request in expectation of the larger log overhaul to add tracing spans and structured logging.

src/provider/states/terminated.rs Outdated Show resolved Hide resolved
src/provider/states/terminated.rs Outdated Show resolved Hide resolved
src/provider/systemdmanager/systemdunit.rs Outdated Show resolved Hide resolved
src/provider/systemdmanager/systemdunit.rs Show resolved Hide resolved
@lfrancke lfrancke self-assigned this Feb 11, 2021
Copy link
Member

@lfrancke lfrancke left a comment

Choose a reason for hiding this comment

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

Only a single comment left.
I'm afraid I didn't understand your answer.


// If no external file was created check if the file currently exists
if !linked_unit_file {
debug!("Target file [{:?}] already exists", &target_file);
Copy link
Member

Choose a reason for hiding this comment

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

I think I disagree.

When I see the debug statement "Target file already exists" it has not actually been checked yet if it exists.
There's nothing in that first if block other than the debug! statement.

This is what I'm proposing:

        if !linked_unit_file && target_file.exists() {
            // Target file already exists, remove if force is supplied, otherwise abort
            debug!("Target file [{:?}] already exists", &target_file);
            if force {
                self.delete_unit_file(&unit_name)?;
            } else {
                return Err(anyhow!(
                    "Target unit file [{:?}] exists and force parameter was not specified.",
                    target_file
                ));
            }
        }

# Conflicts:
#	src/bin/agent.rs
#	src/config/mod.rs
#	src/provider/mod.rs
Copy link
Member

@lfrancke lfrancke left a comment

Choose a reason for hiding this comment

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

Only typos left

src/provider/systemdmanager/manager.rs Outdated Show resolved Hide resolved
src/provider/systemdmanager/manager.rs Outdated Show resolved Hide resolved
src/provider/systemdmanager/manager.rs Outdated Show resolved Hide resolved
Stackable automation moved this from Review in progress to To be merged Feb 12, 2021
@soenkeliebau soenkeliebau merged commit 657a038 into stackabletech:main Feb 12, 2021
Stackable automation moved this from To be merged to Done Feb 12, 2021
@soenkeliebau soenkeliebau deleted the systemd branch February 12, 2021 12:08
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type/enhancement New feature or request
Projects
No open projects
2 participants