You are not logged in.

#1 2016-03-15 16:18:02

Utini
Member
Registered: 2015-09-28
Posts: 452
Website

"After=xxx.service" gets ignored in .service?

Hey there,

I have two instances of dnscrypt-proxy.service running. One should start first and use "dnsresolver1" and the backup.service should start AFTER the main one has started and use "dnsresolver2".
That way "dnsresolver1" is beeing used if it is online/up and if not then "dnsresolver2" will be used.
How ever, what actually happens is that the chosen "dnsresolver" is completely random, sometimes it will be "dnsresolver1" and sometimes "dnsresolver2" even though both "dnsresolvers" are online/up.

Here are the two .service files, maybe someone can spot the problem?

dnscrypt-proxy.service:

[Unit]
Requires=

[Install]
Also=

[Service]
ExecStart=
ExecStart=/usr/bin/dnscrypt-proxy --ephemeral-keys --resolver-name=cisco --local-address=127.0.0.1:40 --user=nobody

dnscrypt-proxy-backup.service:

[Unit]
Requires=
After=dnscrypt-proxy.service

[Install]
Also=

[Service]
ExecStart=
ExecStart=/usr/bin/dnscrypt-proxy --ephemeral-keys --resolver-name=dnscrypt.eu-nl --local-address=127.0.0.1:41 --user=nobody

Any ideas or suggestions?

Thanks !

Last edited by Utini (2016-03-15 16:18:53)


Setup 1: Thinkpad T14s G3, 14" FHD - R7 6850U - 32GB RAM - 2TB Solidigm P44 Pro NVME
Setup 2: Thinkpad X1E G1, 15.6" FHD - i7-8850H - 32GB RAM - NVIDIA GTX 1050Ti - 2x 1TB Samsung 970 Pro NVME
Accessories: Filco Majestouch TKL MX-Brown Mini Otaku, Benq XL2420T (144Hz), Lo(w)gitech G400, Puretrak Talent, Sennheiser HD800S + Meier Daccord FF + Meier Classic FF

Offline

#2 2016-03-15 16:36:19

branch
Member
Registered: 2014-03-16
Posts: 209

Re: "After=xxx.service" gets ignored in .service?

For "Type=simple" services (the default) there is no way to know when a demon has "started", ie. when it actually begins providing services. Systemd simply starts the second one immediately after starting the first, so they may initialize in a random order.

I would try using "Type=forking" and pass the "-d" switch to dnscrypt-proxy in the service files. This way systemd will wait until the first one forks prior to starting the second. If dnscrypt-proxy is well behaved then the first instance should fully initialize prior to forking.

Offline

#3 2016-03-15 17:50:56

Utini
Member
Registered: 2015-09-28
Posts: 452
Website

Re: "After=xxx.service" gets ignored in .service?

branch wrote:

For "Type=simple" services (the default) there is no way to know when a demon has "started", ie. when it actually begins providing services. Systemd simply starts the second one immediately after starting the first, so they may initialize in a random order.

I would try using "Type=forking" and pass the "-d" switch to dnscrypt-proxy in the service files. This way systemd will wait until the first one forks prior to starting the second. If dnscrypt-proxy is well behaved then the first instance should fully initialize prior to forking.

Wow thank your for that quick reply !

So my .service files should look as below?


dnscrypt-proxy.service:

[Unit]
Requires=
Type=forking

[Install]
Also=

[Service]
ExecStart=
ExecStart=/usr/bin/dnscrypt-proxy --ephemeral-keys --resolver-name=cisco --local-address=127.0.0.1:40 --user=nobody -d

dnscrypt-proxy-backup.service:

[Unit]
Requires=
Type=forking

[Install]
Also=

[Service]
ExecStart=
ExecStart=/usr/bin/dnscrypt-proxy --ephemeral-keys --resolver-name=dnscrypt.eu-nl --local-address=127.0.0.1:41 --user=nobody -d

Thanks again !


Setup 1: Thinkpad T14s G3, 14" FHD - R7 6850U - 32GB RAM - 2TB Solidigm P44 Pro NVME
Setup 2: Thinkpad X1E G1, 15.6" FHD - i7-8850H - 32GB RAM - NVIDIA GTX 1050Ti - 2x 1TB Samsung 970 Pro NVME
Accessories: Filco Majestouch TKL MX-Brown Mini Otaku, Benq XL2420T (144Hz), Lo(w)gitech G400, Puretrak Talent, Sennheiser HD800S + Meier Daccord FF + Meier Classic FF

Offline

#4 2016-03-24 20:04:28

Utini
Member
Registered: 2015-09-28
Posts: 452
Website

Re: "After=xxx.service" gets ignored in .service?

That didn't really work with the configuration as above:

sneida@_____:~$ sudo systemctl restart dnscrypt-proxy.service dnscrypt-proxy-backup.service
sneida@_____:~$ sudo systemctl status dnscrypt-proxy.service
* dnscrypt-proxy.service - DNSCrypt client proxy
   Loaded: loaded (/etc/systemd/system/dnscrypt-proxy.service; enabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/dnscrypt-proxy.service.d
           `-override.conf
   Active: inactive (dead) since Thu 2016-03-24 21:02:15 CET; 26s ago
     Docs: man:dnscrypt-proxy(8)
  Process: 8411 ExecStart=/usr/bin/dnscrypt-proxy --ephemeral-keys --resolver-name=dnscrypt.eu-nl --local-address=127.0.0.1:40 --user=nobody -d (code=exited, status=0/SUCCESS)
 Main PID: 8411 (code=exited, status=0/SUCCESS)

Mar 24 21:02:15 _____ systemd[1]: Started DNSCrypt client proxy.
Mar 24 21:02:15 _____ dnscrypt-proxy[8411]: [INFO] + DNS Security Extensions are supported
Mar 24 21:02:15 _____ dnscrypt-proxy[8411]: [INFO] + Provider supposedly doesn't keep logs
Mar 24 21:02:15 _____ dnscrypt-proxy[8413]: Starting dnscrypt-proxy 1.6.1
Mar 24 21:02:15 _____ dnscrypt-proxy[8413]: Ephemeral keys enabled - generating a new seed
Mar 24 21:02:15 _____ dnscrypt-proxy[8413]: Done
sneida@_____:~$ sudo systemctl start dnscrypt-proxy.service
sneida@_____:~$ sudo systemctl status dnscrypt-proxy.service
* dnscrypt-proxy.service - DNSCrypt client proxy
   Loaded: loaded (/etc/systemd/system/dnscrypt-proxy.service; enabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/dnscrypt-proxy.service.d
           `-override.conf
   Active: inactive (dead) since Thu 2016-03-24 21:03:04 CET; 2s ago
     Docs: man:dnscrypt-proxy(8)
  Process: 8506 ExecStart=/usr/bin/dnscrypt-proxy --ephemeral-keys --resolver-name=dnscrypt.eu-nl --local-address=127.0.0.1:40 --user=nobody -d (code=exited, status=0/SUCCESS)
 Main PID: 8506 (code=exited, status=0/SUCCESS)

Mar 24 21:03:04 _____ systemd[1]: Started DNSCrypt client proxy.
Mar 24 21:03:04 _____ dnscrypt-proxy[8506]: [INFO] + DNS Security Extensions are supported
Mar 24 21:03:04 _____ dnscrypt-proxy[8506]: [INFO] + Provider supposedly doesn't keep logs

When removing the "-d" option, both .services start again but still in a random order.

Last edited by Utini (2016-03-24 20:08:52)


Setup 1: Thinkpad T14s G3, 14" FHD - R7 6850U - 32GB RAM - 2TB Solidigm P44 Pro NVME
Setup 2: Thinkpad X1E G1, 15.6" FHD - i7-8850H - 32GB RAM - NVIDIA GTX 1050Ti - 2x 1TB Samsung 970 Pro NVME
Accessories: Filco Majestouch TKL MX-Brown Mini Otaku, Benq XL2420T (144Hz), Lo(w)gitech G400, Puretrak Talent, Sennheiser HD800S + Meier Daccord FF + Meier Classic FF

Offline

#5 2016-03-24 20:08:58

ugjka
Member
From: Latvia
Registered: 2014-04-01
Posts: 1,808
Website

Re: "After=xxx.service" gets ignored in .service?

Why did you remove After=dnscrypt-proxy.service ?


https://ugjka.net
paru > yay | webcord > discord
pacman -S spotify-launcher
mount /dev/disk/by-...

Offline

#6 2016-03-24 20:17:56

Utini
Member
Registered: 2015-09-28
Posts: 452
Website

Re: "After=xxx.service" gets ignored in .service?

ugjka wrote:

Why did you remove After=dnscrypt-proxy.service ?

Good question,

well I updated both .service and corrected some stuff. It seems to be working now, but it could be "random luck" as well big_smile

dnscrypt-proxy.service:

[Unit]
Requires=

[Install]
Also=

[Service]
ExecStart=
ExecStart=/usr/bin/dnscrypt-proxy --ephemeral-keys --resolver-name=dnscrypt.eu-nl --local-address=127.0.0.1:40 --user=nobody -d
Type=forking

dnscrypt-proxy-backup.service:

[Unit]
Requires=
After=dnscrypt-proxy.service

[Install]
Also=

[Service]
ExecStart=
ExecStart=/usr/bin/dnscrypt-proxy --ephemeral-keys --resolver-name=cisco --local-address=127.0.0.1:41 --user=nobody -d
Type=forking

Setup 1: Thinkpad T14s G3, 14" FHD - R7 6850U - 32GB RAM - 2TB Solidigm P44 Pro NVME
Setup 2: Thinkpad X1E G1, 15.6" FHD - i7-8850H - 32GB RAM - NVIDIA GTX 1050Ti - 2x 1TB Samsung 970 Pro NVME
Accessories: Filco Majestouch TKL MX-Brown Mini Otaku, Benq XL2420T (144Hz), Lo(w)gitech G400, Puretrak Talent, Sennheiser HD800S + Meier Daccord FF + Meier Classic FF

Offline

#7 2016-03-25 08:32:51

Utini
Member
Registered: 2015-09-28
Posts: 452
Website

Re: "After=xxx.service" gets ignored in .service?

Nope, it is still in a random order... any ideas?


Setup 1: Thinkpad T14s G3, 14" FHD - R7 6850U - 32GB RAM - 2TB Solidigm P44 Pro NVME
Setup 2: Thinkpad X1E G1, 15.6" FHD - i7-8850H - 32GB RAM - NVIDIA GTX 1050Ti - 2x 1TB Samsung 970 Pro NVME
Accessories: Filco Majestouch TKL MX-Brown Mini Otaku, Benq XL2420T (144Hz), Lo(w)gitech G400, Puretrak Talent, Sennheiser HD800S + Meier Daccord FF + Meier Classic FF

Offline

#8 2016-03-25 10:07:30

ugjka
Member
From: Latvia
Registered: 2014-04-01
Posts: 1,808
Website

Re: "After=xxx.service" gets ignored in .service?

Can you test this

I merged your 2 service files into one

I'm using oneshot's ability to have multiple ExecStart directives.
I'm using pid file so that systemd can track processes (Edit: It seems systemd have no problem tracking processes)

[Unit]
Description=Multi Dns Crypt

[Install]
WantedBy=multi-user.target

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/dnscrypt-proxy --ephemeral-keys --resolver-name=cisco --local-address=127.0.0.1:40 --user=nobody -d
ExecStart=/usr/bin/dnscrypt-proxy --ephemeral-keys --resolver-name=dnscrypt.eu-nl --local-address=127.0.0.1:41 --user=nobody -d

Last edited by ugjka (2016-03-25 11:44:22)


https://ugjka.net
paru > yay | webcord > discord
pacman -S spotify-launcher
mount /dev/disk/by-...

Offline

#9 2016-03-25 23:03:55

branch
Member
Registered: 2014-03-16
Posts: 209

Re: "After=xxx.service" gets ignored in .service?

A few questions:

1) How are you determining the start order?

2) Why do you expect the start order to affect which resolver is preferred?

3) What accesses these resolvers? Are they used as forwarders for a local DNS cache? If so, what one and how is it configured to access them?

Offline

#10 2016-03-25 23:33:55

Utini
Member
Registered: 2015-09-28
Posts: 452
Website

Re: "After=xxx.service" gets ignored in .service?

branch wrote:

A few questions:

1) How are you determining the start order?

2) Why do you expect the start order to affect which resolver is preferred?

3) What accesses these resolvers? Are they used as forwarders for a local DNS cache? If so, what one and how is it configured to access them?

1) By starting the "dnscrypt-proxy.service" first and afterwards the "backup.service".

2 & 3) Well I have dnsmasq configured to listen to both ports (of dnscrypt and dnscrypt-backup) and hoped it would use the ones in order of starting (in case the first one is online).

But I guess it won't just work like that? So far it will use either one randomly OR if one is down it will just use the other one.

ugjka wrote:

Can you test this

I merged your 2 service files into one

I'm using oneshot's ability to have multiple ExecStart directives.
I'm using pid file so that systemd can track processes (Edit: It seems systemd have no problem tracking processes)

[Unit]
Description=Multi Dns Crypt

[Install]
WantedBy=multi-user.target

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/dnscrypt-proxy --ephemeral-keys --resolver-name=cisco --local-address=127.0.0.1:40 --user=nobody -d
ExecStart=/usr/bin/dnscrypt-proxy --ephemeral-keys --resolver-name=dnscrypt.eu-nl --local-address=127.0.0.1:41 --user=nobody -d

Sorry, didn't have time yet to test it. Will try it tomorrow BUT:
Since "cisco" is backup and "dnscrypt.eu-nl" is main, shouldn't the "ExecStart" lines be swapped?

Thanks !


Setup 1: Thinkpad T14s G3, 14" FHD - R7 6850U - 32GB RAM - 2TB Solidigm P44 Pro NVME
Setup 2: Thinkpad X1E G1, 15.6" FHD - i7-8850H - 32GB RAM - NVIDIA GTX 1050Ti - 2x 1TB Samsung 970 Pro NVME
Accessories: Filco Majestouch TKL MX-Brown Mini Otaku, Benq XL2420T (144Hz), Lo(w)gitech G400, Puretrak Talent, Sennheiser HD800S + Meier Daccord FF + Meier Classic FF

Offline

#11 2016-03-26 00:04:45

branch
Member
Registered: 2014-03-16
Posts: 209

Re: "After=xxx.service" gets ignored in .service?

Utini wrote:

1) By starting the "dnscrypt-proxy.service" first and afterwards the "backup.service".

You said they still started in a random order, so I wanted to know how you determined which one had actually started first, ie. on boot when both were enabled. But it probably does not matter (see below).

Utini wrote:

2 & 3) Well I have dnsmasq configured to listen to both ports (of dnscrypt and dnscrypt-backup) and hoped it would use the ones in order of starting (in case the first one is online).

But I guess it won't just work like that? So far it will use either one randomly OR if one is down it will just use the other one.

I don't think dnsmasq uses the start order of the servers. In the common scenario both servers would be actual servers that are always up. You could test by manually starting each resolver in known order to see what dnsmasq does, but it probably does not even know whether they are up until it tries to use them.

Offline

#12 2016-03-26 10:12:02

ugjka
Member
From: Latvia
Registered: 2014-04-01
Posts: 1,808
Website

Re: "After=xxx.service" gets ignored in .service?

Utini wrote:

Sorry, didn't have time yet to test it. Will try it tomorrow BUT:
Since "cisco" is backup and "dnscrypt.eu-nl" is main, shouldn't the "ExecStart" lines be swapped?

Ah, yes swap them.


https://ugjka.net
paru > yay | webcord > discord
pacman -S spotify-launcher
mount /dev/disk/by-...

Offline

Board footer

Powered by FluxBB