Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 483456 - net-misc/chrony - suggestion for better systemd unit files
Summary: net-misc/chrony - suggestion for better systemd unit files
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Server (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Jeroen Roovers (RETIRED)
URL:
Whiteboard:
Keywords: PATCH
Depends on:
Blocks:
 
Reported: 2013-09-03 07:47 UTC by Stefan G. Weichinger
Modified: 2014-09-12 07:35 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stefan G. Weichinger 2013-09-03 07:47:47 UTC
Pacho Ramos <pacho@gentoo.org> lately pointed at how to write systemd unit files for gentoo ebuilds: (1)

The servicefile in the current chrony-ebuild still uses forking and has other issues ... I also took (2) as a template ... so I suggest the following 2 service-files.

# cat chronyd.service 
[Unit]
Description=Chrony Network Time Service
After=ntpdate.service network.target
Conflicts=ntpd.service

[Service]
ExecStart=/usr/sbin/chronyd -r -s -d
ControlGroup=cpu:/

[Install]
WantedBy=multi-user.target

# cat chrony-wait.service 
[Unit]
Description=Wait for chrony to synchronize system clock
After=chronyd.service
Requires=chronyd.service
Before=time-sync.target
Wants=time-sync.target

[Service]
Type=oneshot
# Wait up to ~10 minutes for chronyd to synchronize and the remaining
# clock correction to be less than 0.1 seconds
ExecStart=/usr/bin/chronyc waitsync 60 0.1
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target








Reproducible: Always




(1) http://my.opera.com/pacho/blog/2013/08/27/how-to-write-proper-systemd-unit-files

(2) http://permalink.gmane.org/gmane.comp.sysutils.systemd.devel/5749
Comment 1 Pacho Ramos gentoo-dev 2013-09-03 20:21:19 UTC
I am all for the no longer forking part, but really unsure about that "wait" service file :/. Is it really needed? How is that being handled by init.d script? Isn't checking for active internet connection enough?
Comment 2 Stefan G. Weichinger 2013-09-04 06:55:41 UTC
I just copied it from the mentioned link (2) ... 
AFAI understand it might be needed when another unit after it absolutely needs the synced time ... so we could depend on it.

I think the chronyd.service would be enough for now.

Please also check if "-d" is OK and not "-n" ... ->

http://chrony.tuxfamily.org/manual.html#Starting-chronyd

The difference is the logging.

Greets.
Comment 3 Pacho Ramos gentoo-dev 2013-09-21 14:07:59 UTC
Will fix existing unit then
Comment 4 Pacho Ramos gentoo-dev 2013-09-21 15:21:01 UTC
+*chrony-1.29-r1 (21 Sep 2013)
+
+  21 Sep 2013; Pacho Ramos <pacho@gentoo.org> +chrony-1.29-r1.ebuild,
+  +files/chronyd.service-r1:
+  Improve unit file (#483456 by Stefan G. Weichinger)
+
Comment 5 Mike Gilbert gentoo-dev 2014-09-07 20:43:50 UTC
I'm re-openening this because the current unit has a few problems:

1. Setting Type=simple means that systemd will not detect problems in early startup (like a bad config file), and will continue starting dependent units. Type=forking is actually better here.

2. Passing -r -s by default makes no sense; the default chrony.conf is not set up to support those flags.

3. ControlGroup is no longer supported.

4. Units providing NTP should Conflict with system-timesyncd.service.

If there are no objections, I would like to commit the unit below as a replacement.

[Unit]
Description=Chrony Network Time Service
After=ntpdate.service sntp.service network.target
Conflicts=ntpd.service systemd-timesyncd.service

[Service]
Type=forking
ExecStart=/usr/sbin/chronyd
PIDFile=/run/chronyd.pid

[Install]
WantedBy=multi-user.target
Comment 6 Jeroen Roovers (RETIRED) gentoo-dev 2014-09-08 09:30:21 UTC
(In reply to Mike Gilbert from comment #5)
> If there are no objections, I would like to commit the unit below as a
> replacement.

No objections here. Someone who likes/uses chrony+systemd might want to review this, though.
Comment 7 Mike Gilbert gentoo-dev 2014-09-09 01:48:21 UTC
(In reply to Jeroen Roovers from comment #6)
> No objections here. Someone who likes/uses chrony+systemd might want to
> review this, though.

I like systemd and have just started using chrony. ^_^

I'll wait a few days for feedback though.
Comment 8 Stefan G. Weichinger 2014-09-09 08:01:52 UTC
* I was using "simple" because 

http://wiki.gentoo.org/wiki/Project:Systemd/Ebuild_policy

said so.

* ControlGroup: yes, the related warning annoyed me for a long time ;-)

* -r -s : ok .. I think the options wouldn't hurt, but OK, it's cleaner this way.
If people adjust their config to use that, they can also set up and adjust a specific unit-file in /etc/systemd/system

Using your unit-file now for a test ... thanks
Comment 9 Mike Gilbert gentoo-dev 2014-09-09 14:46:26 UTC
(In reply to Stefan G. Weichinger from comment #8)
> * I was using "simple" because 
> 
> http://wiki.gentoo.org/wiki/Project:Systemd/Ebuild_policy
> 
> said so.
> 

It also says this:

"However, Type=forking might be used if it allows distinction between start failures and run-time failures, e.g. configuration file is checked before forking."

I checked, and this is indeed the case: chronyd will fail before forking on a config file error.
Comment 10 Mike Gilbert gentoo-dev 2014-09-09 14:51:20 UTC
(In reply to Stefan G. Weichinger from comment #8)
> * -r -s : ok .. I think the options wouldn't hurt, but OK, it's cleaner this
> way.

My main objection is to the -s flag, which resets the system clock to the hardware clock, and assumes the hardware clock is in *local* time by default. That's a horrible assumption to make, and it is not really the job of the NTP daemon in any case.

The -r flag causes warnings to appear by default:

Sep 04 01:33:27 naomi chronyd[11266]: 2014-09-04T05:33:27Z Could not open dump file ./50.7.68.4.dat
Sep 04 01:33:27 naomi chronyd[11266]: 2014-09-04T05:33:27Z Could not open dump file ./198.55.111.50.dat
Sep 04 01:33:27 naomi chronyd[11266]: 2014-09-04T05:33:27Z Could not open dump file ./138.236.128.36.dat
Comment 11 Stefan G. Weichinger 2014-09-09 17:13:08 UTC
I agree with your changes, thank you.
Comment 12 Mike Gilbert gentoo-dev 2014-09-12 04:27:01 UTC
+  12 Sep 2014; Mike Gilbert <floppym@gentoo.org> +files/chronyd.service-r2,
+  chrony-1.31.ebuild:
+  systemd unit improvements, bug 483456.

Not sure it is worth a revbump.
Comment 13 Jeroen Roovers (RETIRED) gentoo-dev 2014-09-12 05:14:49 UTC
(In reply to Mike Gilbert from comment #12)
> +  12 Sep 2014; Mike Gilbert <floppym@gentoo.org> +files/chronyd.service-r2,
> +  chrony-1.31.ebuild:
> +  systemd unit improvements, bug 483456.
> 
> Not sure it is worth a revbump.

1.31 was added not a day before that.
Comment 14 Stefan G. Weichinger 2014-09-12 07:35:50 UTC
could we also decide something about

https://bugs.gentoo.org/show_bug.cgi?id=499492

while you are at chrony-topics?