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

feat: Use override.conf files for systemd unit config #1596

Draft
wants to merge 4 commits into
base: trunk
Choose a base branch
from

Conversation

cpswan
Copy link
Member

@cpswan cpswan commented Dec 5, 2024

Fixes #1567 though we have more work to do to make the upgrade experience smoother

- What I did

  • introduced override.conf files for systemd units
  • edited install.sh to put in place (and not overwrite) override.conf
  • modified universal.sh to place config into override.conf and not disrupt existing config.

- How to verify it

We'll have to do a pre-release once this is merged

- Description for the changelog

feat: Use override.conf files for systemd unit config

@cpswan cpswan requested a review from XavierChanth December 5, 2024 14:38
@cpswan cpswan self-assigned this Dec 5, 2024
@cpswan cpswan marked this pull request as draft December 5, 2024 14:38
@cpswan
Copy link
Member Author

cpswan commented Dec 5, 2024

Making draft until we've had a chance to discuss in arch - particularly that this change will impact config stored in existing systemd unit files.

@cpswan cpswan marked this pull request as ready for review December 5, 2024 16:00
@cpswan
Copy link
Member Author

cpswan commented Dec 5, 2024

@XavierChanth if you want to merge this then please go ahead. If not put it back to draft and I'll take another pass at how to migrate existing config.

# The line below runs the sshnpd service, with the options set in
# /etc/systemd/system/sshnpd.d/override.conf.
# You can edit that config with: sudo systemctl edit sshnpd
ExecStart=/usr/local/bin/sshnpd -a "$device_atsign" -m "$manager_atsign" -d "$device_name" "$delegate_policy" "$s" "$u" "$v" "$additional_args"
Copy link
Member

Choose a reason for hiding this comment

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

One thing I've been meaning to address, which may be suitable as part of this changeset is that when we use policy only the manager configuration will be -m "" which prevents the daemon from starting.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can change it to: $( [ -n "$manager_atsign" ] && "-m $manager_atsign" || "" ), and have a similar wrapper for policy.

Copy link
Member

Choose a reason for hiding this comment

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

This can also be done in a later PR

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 was thinking this should actually be something like ${manager_atsign:+-m "$manager_atsign"}, but it turns out that systemd doesn't support parameter expansion

One option might be to wrap our command line inside a shell invocation, but I'm wary of creating a deeper process tree.

Copy link
Member

Choose a reason for hiding this comment

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

Seems like the safest option is to allow sshnpd to try to pull those from the environment if they aren't explicitly passed.

@XavierChanth
Copy link
Member

@XavierChanth if you want to merge this then please go ahead. If not put it back to draft and I'll take another pass at how to migrate existing config.

I think we should improve the upgrade / migration path before we merge.

@XavierChanth XavierChanth marked this pull request as draft December 5, 2024 18:07
dest="$systemd_dir/$unit_name"
cp "$script_dir/systemd/$unit_name" "$dest"
if [ -f "$systemd_unit" ]; then
# migrate old config from systemd unit file to override.conf
Copy link
Member Author

Choose a reason for hiding this comment

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

This has been the focus of my testing for the past few days - making sure that we can migrate existing config into the new approach.

launchd_plist="$HOME/Library/LaunchAgents/com.atsign.sshnpd.plist"
if [ -f "$launchd_plist" ]; then
echo "launchd config already in place"
# TODO: restart service?
Copy link
Member Author

Choose a reason for hiding this comment

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

@XavierChanth what would be the appropriate command here?

Copy link
Member

Choose a reason for hiding this comment

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

From what I grok in the launchctl man page it's supposed to be this:

launchctl disable gui/$UID/com.atsign.sshnpd
launchctl enable gui/$UID/com.atsign.sshnpd

And I get a success code from both commands, but neither is actually stopping or starting the service...

Copy link
Member

Choose a reason for hiding this comment

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

Ah, that doesn't work.. but this works:

launchctl kickstart -k gui/$UID/com.atsign.sshnpd

-k says to kill the running instance first.

Copy link
Member

Choose a reason for hiding this comment

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

Confirmed by checking process ids for sshnpd

@XavierChanth
Copy link
Member

systemd part LGTM

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.

upgrading sets /etc/systemd/system/sshnpd.service back to template so reconfiguration required
2 participants