Bug 256137 - service(8) "service -R" restarts local daemons in wrong order.
Summary: service(8) "service -R" restarts local daemons in wrong order.
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 13.0-RELEASE
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-05-25 01:13 UTC by HATANO Tomomi
Modified: 2022-01-13 18:29 UTC (History)
2 users (show)

See Also:


Attachments
Bugfix for service(8) with -R option. (436 bytes, patch)
2021-05-25 01:13 UTC, HATANO Tomomi
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description HATANO Tomomi 2021-05-25 01:13:52 UTC
Created attachment 225239 [details]
Bugfix for service(8) with -R option.

Many startup scripts depend on dummy dependencies,
such as NETWORKING, SERVERS, and so on.

These files are in /etc/rc.d,
but "service -R" doesn't see /etc/rc.d/[A-Z]* at all.

This results in wrong order of restarting.
(e.g. named after fahclient)

Attached patch may fix this issue.
Comment 1 MikeM 2022-01-10 23:56:41 UTC
I ran into this issue, but with nginx starting before unbound, and nginx did not start properly because DNS was not available.

More detail is n this thread:
https://forums.freebsd.org/threads/nginx-upgrade-to-freebsd-13-0-and-host-not-found-in-ocsp-msg.83400/

thx.
Comment 2 MikeM 2022-01-13 18:29:32 UTC
Some of the detail from the thread in the FreeBSD forum I cited...

==============================
 I notice that the start order of services is different in service -R than either service -r or rcorder /etc/rc.d/* /usr/local/etc/rc.d/*.

Some details... Note that lines containing services that don't matter in this comparison were replaced by {...} to keep things short.




rcorder /etc/rc.d/* /usr/local/etc/rc.d/*

Code:

{...}
/etc/rc.d/FILESYSTEMS
{...}
/usr/local/etc/rc.d/unbound
/etc/rc.d/local_unbound
/etc/rc.d/NETWORKING
{...}
/usr/local/etc/rc.d/nginx
/usr/local/etc/rc.d/php-fpm
{...}




service -r

Code:

{...}
/etc/rc.d/FILESYSTEMS
{...}
/usr/local/etc/rc.d/unbound
/etc/rc.d/local_unbound
/etc/rc.d/NETWORKING
{...}
/usr/local/etc/rc.d/nginx
{...}
/usr/local/etc/rc.d/php-fpm
{...}




service -R

Code:

Stopping nsd.
Stopping openntpd.
Stopping php_fpm.
Waiting for PIDS: 86331.
{...}
Stopping unbound.
Stopping nginx.
Performing sanity check on nginx configuration:
nginx: [warn] "ssl_stapling" ignored, host not found in OCSP responder "stg-e1.o.lencr.org" in the certificate "/usr/local/etc/certs/public/www.example.com.crt"
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
Starting nginx.
nginx: [warn] "ssl_stapling" ignored, host not found in OCSP responder "stg-e1.o.lencr.org" in the certificate "/usr/local/etc/certs/public/www.example..com.crt"
Obtaining a trust anchor...
Starting unbound.
{...}
Starting php_fpm.
{...}



Notice that in service -R, and only service -R, unbound is started after nginx.

So I guess my question becomes, why doesn't service -R follow the restart order that service -r and rcorder show?
==================================



--------------------------
or correct? operation it needs this patch

Code:

--- /usr/sbin/service    2021-04-09 09:25:01.000000000 +0300
+++ /tmp/service    2022-01-06 14:16:29.217498000 +0200
@@ -85,9 +85,10 @@
         skip="$skip -s nojail"
     fi
     [ -n "$local_startup" ] && find_local_scripts_new
-    files=`rcorder ${skip} ${local_rc} 2>/dev/null`
+    files=`rcorder ${skip} /etc/rc.d/* ${local_rc} 2>/dev/null`
 
     for file in `reverse_list ${files}`; do
+            [ "$file" != ${file#/etc/rc.d/} ] && continue
         if grep -q ^rcvar $file; then
             eval `grep ^name= $file`
             eval `grep ^rcvar $file`
@@ -98,6 +99,7 @@
         fi
     done
     for file in $files; do
+        [ "$file" != ${file#/etc/rc.d/} ] && continue
         if grep -q ^rcvar $file; then
             eval `grep ^name= $file`
             eval `grep ^rcvar $file`

-----------------------------------------


I applied the patch, and it seems to fix the issue I was seeing...

=================================
The patch looks to work quite well for my use case.

Here's the output produced (with irrelevant lines shown as {...} to keep it short...)

# service -R
Code:

{...}
Stopping nginx.
Waiting for PIDS: 4460.
{...}
Stopping unbound.
Waiting for PIDS: 68586.
Obtaining a trust anchor...
Starting unbound.
{...}
Performing sanity check on nginx configuration:
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
Starting nginx.
{...}
=====================================


There's some more detail in the cited thread, but the above is the important gist of it.

thx.