Skip to content

cjdns: Improving systemd unit description #20177

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

Closed
wants to merge 4 commits into from

Conversation

spacekitteh
Copy link
Contributor

Motivation for this change

Makes cjdns actually require networking.

@mention-bot
Copy link

@spacekitteh, thanks for your PR! By analyzing the history of the files in this pull request, we identified @ehmry, @joachifm and @edolstra to be potential reviewers.

@spacekitteh spacekitteh changed the title Improving systemd unit description cjdns: Improving systemd unit description Nov 5, 2016
@groxxda
Copy link
Contributor

groxxda commented Nov 5, 2016

Why is the bindsTo needed?

@spacekitteh
Copy link
Contributor Author

spacekitteh commented Nov 5, 2016

Because it requires networking to be up before it can create a connection. If you have a slow-starting network connection, then cjdns will fail if it's started too soon after starting networking.

If networking goes down, then having cjdns running is pointless; I'm also not sure if it can even re-establish a connection after losing the network yet.

It's also a security thing - if networking goes down and cjdns doesn't properly reauthenticate peers when it's re-established, an attacker could perform a MITM.

@groxxda
Copy link
Contributor

groxxda commented Nov 7, 2016

networking.target gives no guarantee that networking is up. You might want to depend on network-online.target

@groxxda
Copy link
Contributor

groxxda commented Nov 7, 2016

systemctl list-dependencies sleep.target --reverse --type=target --all 
sleep.target
● ├─systemd-hibernate.service
● │ └─hibernate.target
● ├─systemd-hybrid-sleep.service
● │ └─hybrid-sleep.target
● └─systemd-suspend.service
●   └─suspend.target

Depending on sleep.target should suffice, since the other three will pull in sleep.target

@spacekitteh
Copy link
Contributor Author

spacekitteh commented Nov 8, 2016

networking.target gives no guarantee that networking is up. You might want to depend on network-online.target

Yeah, I changed it to that. It still seems to have issues. Apparently network-online.target comes up before the connection is properly established (for my hardware), so the service tries rebooting (too quickly) and hits the start up rate limit. But due to having a "Restart=" option set, combined with rate limiting being different from the default, it doesn't attempt any further restarts.

Then the same thing happens with the cjdns-resume.service. I can't figure this out - I don't understand why rate limiting combined with restart means don't restart after being rate limited!

@spacekitteh
Copy link
Contributor Author

I guess I could just disable start rate limiting. I'll give that a try.

@spacekitteh
Copy link
Contributor Author

Well, it works now. \o/ I squashed the commits.

Copy link
Contributor

@MostAwesomeDude MostAwesomeDude left a comment

Choose a reason for hiding this comment

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

LGTM

I haven't tested but the submitter says that it works for them, so that works for me.

@grahamc
Copy link
Member

grahamc commented Nov 10, 2016

@groxxda what do you think of the current state?

@groxxda
Copy link
Contributor

groxxda commented Nov 10, 2016

I don't use cjdns so I cannot say anything about the issues @spacekitteh experienced.
At least the upstream service file does not require network-online, and I don't understand why this is needed here.

I don't know why ordering after network-online does not work, that may be a bug in the networking module. Of course I'd favor fixing the real issue and not working around it in clients with unlimited restarts, but that's just my opinion.
If it was broken before and works like this, it's clearly an improvement..

@spacekitteh
Copy link
Contributor Author

Is it good to merge?

@edolstra
Copy link
Member

Note my comment about systemd unit descriptions.

@spacekitteh
Copy link
Contributor Author

@edolstra Where?

${config.systemd.package}/bin/systemctl systemctl reset-failed cjdns.service
${config.systemd.package}/bin/systemctl restart cjdns.service
";
postStop = "${config.systemd.package}/bin/systemctl systemctl reset-failed cjdns-restart.service";
Copy link
Member

@Mic92 Mic92 Nov 10, 2016

Choose a reason for hiding this comment

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

systemctl systemctl should have no effect in:

${config.systemd.package}/bin/systemctl systemctl reset-failed cjdns-restart.service

Copy link
Member

@Mic92 Mic92 Nov 10, 2016

Choose a reason for hiding this comment

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

I also think reset-failed is not needed: StartLimitInterval = 0 in the other unit already does the job - so it will restart on its own eventually when it crashed. I first thought why the hack restart is needed at all for cjdns but apparently this is compliant with upstream:

https://github.com/cjdelisle/cjdns/blob/master/contrib/systemd/cjdns-resume.service

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoops, I forgot to remove that line


script =
"
${config.systemd.package}/bin/systemctl systemctl reset-failed cjdns.service
Copy link
Member

Choose a reason for hiding this comment

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

same as below

@@ -241,10 +258,13 @@ in
| ${pkg}/bin/cjdroute
''
);


onFailure = ["cjdns-restart.service"];
Copy link
Member

Choose a reason for hiding this comment

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

Why is that needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Becuase cjdns requires the network to actually be online.

Copy link
Member

Choose a reason for hiding this comment

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

From understanding this is the job of Restart = "always";, which does the same, right?

@Mic92
Copy link
Member

Mic92 commented Nov 10, 2016

I don't think an attacker can perform an MITM: cjdns does end-to-end authentication based on addresses.

@Mic92
Copy link
Member

Mic92 commented Nov 10, 2016

@cjdelisle is it possible to implement a signal handler for SIGUSR2 to reconnect to its peers? That would make the cjdns-restart.service cleaner IMHO.

after = ["sleep.target" "network-online.target"];

script =
"
Copy link
Member

Choose a reason for hiding this comment

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

Looks like this should either be a single-line string, or use

script = ''
  double single quotes
'';

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After rethinking I just deleted the -restart service altogether.

@grahamc
Copy link
Member

grahamc commented Nov 28, 2016

Merged in 016fa06, thank you for your effort and time on this :)

@spacekitteh
Copy link
Contributor Author

\o/

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.

None yet

7 participants