LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-21-2017, 01:49 PM   #1
PoleStar
Member
 
Registered: Jul 2010
Posts: 231

Rep: Reputation: 2
rhel init.d script wont run upon shutdown


Quote:
#!/bin/bash

#
# TEST Start up the OpenSSH server daemon
#
# chkconfig: 345 85 15

# description: stop start script
#
# processname: TEST

### BEGIN INIT INFO
# Provides: TEST
# Default-Start: 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start/stop script
### END INIT INFO
Code:
[root@cycl3nwbt03 MW]# chkconfig  --list | grep TEST
TEST    0:off   1:off   2:on    3:on    4:on    5:on    6:off
[root@cycl3nwbt03 MW]#
I used
chkconfig --add TEST

i see this


Code:
[root@cycl3nwbt03 MW]# ls -l /etc/rc*.d/*TEST*
lrwxrwxrwx 1 root root 20 Jun 21 14:05 /etc/rc0.d/K15TEST -> ../init.d/TEST
lrwxrwxrwx 1 root root 20 Jun 21 14:05 /etc/rc1.d/K15TEST -> ../init.d/TEST
lrwxrwxrwx 1 root root 20 Jun 21 14:23 /etc/rc2.d/S85TEST -> ../init.d/TEST
lrwxrwxrwx 1 root root 20 Jun 21 14:23 /etc/rc3.d/S85TEST -> ../init.d/TEST
lrwxrwxrwx 1 root root 20 Jun 21 14:23 /etc/rc4.d/S85TEST -> ../init.d/TEST
lrwxrwxrwx 1 root root 20 Jun 21 14:23 /etc/rc5.d/S85TEST -> ../init.d/TEST
lrwxrwxrwx 1 root root 20 Jun 21 14:05 /etc/rc6.d/K15TEST -> ../init.d/TEST
[root@cycl3nwbt03 MW]#

So this script works with
Quote:
/etc/init.d/TEST stop
/etc/init.d/TEST start

TEST kicks in when I server comes up
But it does NOT kick in when server is going down.

Any ideas ?

Last edited by PoleStar; 06-21-2017 at 01:50 PM.
 
Old 06-21-2017, 07:34 PM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,700

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
What do you mean by not kick in? What version of RHEL are you running?

Normally you would see a stopping service TEST message during shutdown. Scripts stop in alphanumeric order and it depends on how your system is configured. On my CentOS 6 system I only have seven services from K01 to K15 so depending on how fast they shutdown you could miss the message.

Without seeing the entire script there could be other reasons.
 
Old 06-21-2017, 08:09 PM   #3
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524

Rep: Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015
You have the script set to "stop" on shutdown or reboot, which is usually what you want.
 
Old 06-22-2017, 12:44 PM   #4
PoleStar
Member
 
Registered: Jul 2010
Posts: 231

Original Poster
Rep: Reputation: 2
ok so I redid the whole thing
I built one CentOS 6.9 vm.
then copy sshd to TEST and made changes


Quote:
cat /etc/init.d/ TEST

#!/bin/bash
#
# sshd Start up the OpenSSH server daemon
#
# chkconfig: 2345 85 2

### BEGIN INIT INFO
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# This service starts up the OpenSSH server daemon.
### END INIT INFO
LOG=/tmp/TEST_LOG

RETVAL=0



start()
{
# Create keys if necessary

echo "#######################################################"
echo $0 @1 >> $LOG
echo "#######################################################"
return $RETVAL
}

stop()
{
eecho "#######################################################"
echo $0 @1 >> $LOG
echo "#######################################################"
return $RETVAL
}


case "$1" in
start)
rh_status_q && exit 0
start
;;
stop)
if ! rh_status_q; then
rm -f $lockfile
exit 0
fi
stop
;;
*)
echo $"Usage: $0 {start|stop|restart|reload|force-reload|condrestart|try-restart|status}"
RETVAL=2
esac
exit $RETVAL
added it in chkconfig

Quote:
[root@localhost init.d]#
ls -l /etc/rc*d/*TEST*
ls: cannot access /etc/rc*d/*TEST*: No such file or directory

[root@localhost init.d]# chkconfig --add TEST

[root@localhost init.d]# ls -l /etc/rc*d/*TEST*
lrwxrwxrwx. 1 root root 14 Jun 22 13:36 /etc/rc0.d/K02TEST -> ../init.d/TEST
lrwxrwxrwx. 1 root root 14 Jun 22 13:36 /etc/rc1.d/K02TEST -> ../init.d/TEST
lrwxrwxrwx. 1 root root 14 Jun 22 13:36 /etc/rc2.d/S85TEST -> ../init.d/TEST
lrwxrwxrwx. 1 root root 14 Jun 22 13:36 /etc/rc3.d/S85TEST -> ../init.d/TEST
lrwxrwxrwx. 1 root root 14 Jun 22 13:36 /etc/rc4.d/S85TEST -> ../init.d/TEST
lrwxrwxrwx. 1 root root 14 Jun 22 13:36 /etc/rc5.d/S85TEST -> ../init.d/TEST
lrwxrwxrwx. 1 root root 14 Jun 22 13:36 /etc/rc6.d/K02TEST -> ../init.d/TEST
[root@localhost init.d]#

rebooted the server and did not see any echo out on shutdown but saw echo out on start up.
log file recorded this

Quote:
[root@localhost ~]#
cat /tmp/TEST_LOG
/etc/rc3.d/S85TEST @1
[root@localhost ~]#

Last edited by PoleStar; 06-22-2017 at 12:46 PM.
 
Old 06-22-2017, 01:04 PM   #5
sgrlscz
Member
 
Registered: Aug 2008
Posts: 123

Rep: Reputation: 84
You never create a lock file. During shutdown, the stop action won't be called unless the /var/lock/subsys/<service> file exists.

To get it to work, near the top, add:

Code:
lockfile=/var/lock/subsys/TEST
Then in start, add:

Code:
touch $lockfile
Then at the end of stop, add:

Code:
rm -f $lockfile
 
1 members found this post helpful.
Old 06-22-2017, 01:36 PM   #6
PoleStar
Member
 
Registered: Jul 2010
Posts: 231

Original Poster
Rep: Reputation: 2
This solved the problem.
Thank you .. thank you!!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Init.d script not executing at shutdown and reboot roberbizimhatemo Linux - General 19 07-02-2019 04:35 AM
How to run fsck during a shutdown sequence, or how to run one-time init scripts? bgoodr Debian 5 11-28-2010 03:08 PM
Getting an /etc/init.d script to run at system shutdown forrie Linux - Server 6 05-05-2010 01:19 PM
init script does not run at the shutdown time procfs Linux - Newbie 4 02-16-2010 02:00 AM
Is a script, run at boot time from init.d, run with root authority? tmbrwolf53 Linux - Server 2 03-31-2007 08:15 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:27 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration