Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.user > #186251

dhcp restart with bad config

From Jonathan de Boyne Pollard <J.deBoynePollard-newsgroups@NTLWorld.COM>
Newsgroups linux.debian.user
Subject dhcp restart with bad config
Date 2017-08-31 22:00 +0200
Message-ID <ukDN7-1yc-3@gated-at.bofh.it> (permalink)
References <ukDN7-1yc-5@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

Bonno Bloksma:

> There is the strange fact that it seems the config is tested twice but 
> I guess systemd will try to start a service twice before giving up.
>
I recommend less guessing and more reading your own posts.  (-: You 
yourself posted the very script fragment where /the script itself/ runs 
the test command twice:

> test_config()
> {
>          if ! /usr/sbin/dhcpd -t $OPTIONS -q -cf "$DHCPD_CONF" > /dev/null 2>&1; then
>                  echo "dhcpd self-test failed. Please fix $DHCPD_CONF."
>                  echo "The error was: "
>                  /usr/sbin/dhcpd -t $OPTIONS -cf "$DHCPD_CONF"
>                  exit 1
>          fi
> }

See where that runs |/usr/sbin/dhcpd| in test mode twice?  The first 
time, dhcpd writes the error message to the syslog; the second time 
|dhcpd| writes the error message to its standard error.  Both lots of 
output end up in the journal.

 From the LSB: prefix to the service name in the very log output that 
you posted, we can deduce that systemd is running your van Smoorenburg 
|rc| script as a service, wrapping it in a nonce service unit 
<https://unix.stackexchange.com/a/233581/5132>.  The test performed by 
the van Smoorenburg |rc| script is considered to /be a part of your 
service/.  By the time that the script is running, and executing the 
startup test, systemd thinks that your service is already running.  The 
stop and start actions of systemd encompass the script as a whole, and 
operate outwith the configuration validation test, not within it.

Put another way: There is no customizable mechanism to make the very 
execution of the start, stop, and restart commands in systemd dependent 
from first testing some arbitrary service-specific condition.  There's 
no way to tell systemd "only actually execute the restart command at all 
if this shell script first returns true".  When running restart, systemd 
will stop your service, start it again, and the test in the script will 
/only then/ run as part of your service's initialization.

The best that you have are mechanisms that cause a startup to abort, by 
failing an ExecStartPre command.  But for those you must actually write 
a proper service unit file. |systemd-sysv-generator| employs a 
one-size-fits-all approach, and will not generate such service-specific 
special-case stuff in the nonce units that it generates for van 
Smoorenburg |rc| scripts.  You need a bona fide human being to actually 
write a service unit file.  Even then, that is not enough.  A restart 
will still stop the service /before/ the ExecStartPre tests are run, and 
you won't get what you want. restart is stop /then/ start.

Back to linux.debian.user | Previous | Next | Find similar | Unroll thread


Thread

dhcp restart with bad config Jonathan de Boyne Pollard <J.deBoynePollard-newsgroups@NTLWorld.COM> - 2017-08-31 22:00 +0200

csiph-web