0

So I have these 2 files:

/etc/init.d
    - service1
    - service2

service2 is like:

#!/bin/sh
# chkconfig: 2346 95 45
# description: desc
# processname: service2

### BEGIN INIT INFO
# Provides:          service2
# Required-Start:    service1
# Required-Stop:     service1
# Default-Start:     2 3 4 6
# Default-Stop:      0 6
# Short-Description: desc
# Description:       long desc
### END INIT INFO
export JAVA_HOME="/opt/java/jre"
export PATH=$JAVA_HOME/bin:$PATH
/opt/do/something.sh $*

I want, on normal boot and reboot, service2 to start after service1 ends (take about 12 minutes, it's an app-server), but they start almost at the same time and this breaks service2.

Why is service system ignoring the dependencies I set up? Is there something wrong? Is there a way to check the correctness of boot order execution?

I'm on RHEL7 and both services have been added succesfully with

chkconfig --add <service_name>

Thank you

Stefano Lazzaro
  • 175
  • 1
  • 6

1 Answers1

1

As Michael Hampton mentioned in the comments, you should convert your old-style init scripts to systemd units.

However, you may have your reasons to keep using old-style SysVinit scripts.

There may be one problem in your script: I seem to recall that there used to be a requirement that there must be no blank lines before the ### BEGIN INIT INFO line.

I cannot find that requirement in the current LSB standards document but I think I once solved a similar problem by removing blank lines from before the INIT INFO section. If my memory is correct, this might explain why your dependencies are not followed.

Also, the dependencies in SysVinit scripts don't necessarily refer to the actual services, but just the scripts themselves: the RHEL7 systemd will fire up the service2 script immediately after service1 script has finished, regardless of whether the actual service process started by the service1 has completed its start-up or not. So, if your services take a non-trivial time to start up, the scripts should explicitly wait until the service has completely started up before exiting.

telcoM
  • 4,448
  • 15
  • 25
  • Blank line removed, same result. But it definitely is the case that service1 script ends waaay before than the process is completed, so service2 will always start too earlier. Thank you! – Stefano Lazzaro Aug 02 '18 at 14:47