I have created customized scripts to start httpd and postgres (For CentOS 6) in /etc/init.d. However for it to work even after reboot, I have to put the script in /etc/rc.d/rc0.d, rc1.d, etc.
[root@dev3-pdx rc.d]# ls -lrt
total 60
-rwxr-xr-x 1 root root 20199 Oct 4 2017 rc.sysinit
-rwxr-xr-x 1 root root 220 Oct 4 2017 rc.local
-rwxr-xr-x 1 root root 2617 Oct 4 2017 rc
drwxr-xr-x. 2 root root 4096 May 14 2019 rc1.d
drwxr-xr-x. 2 root root 4096 May 14 2019 rc0.d
drwxr-xr-x. 2 root root 4096 May 14 2019 rc6.d
drwxr-xr-x. 2 root root 4096 May 14 2019 rc2.d
drwxr-xr-x. 2 root root 4096 May 14 2019 rc5.d
drwxr-xr-x. 2 root root 4096 May 14 2019 rc4.d
drwxr-xr-x. 2 root root 4096 May 14 2019 rc3.d
drwxr-xr-x. 2 root root 4096 Jan 15 11:49 init.d
[root@dev3-pdx rc.d]#
However, the naming convention for the scripts, for eg, in the directory rc0.d is like this :
rc.local is for compatibility with BSD Unix, not well supported in Linux
In your start/stop script reate a dependency header - comments with certain keywords that belong to the LSB (Linux Standard Base).
Then put it in the init.d directory so it is seen by the chkconfig command.
chkonfig -add myscript
chkonfig --list
chkonfig myscript on
chkconfig --list
The on command creates suitable S and K numbers for the run levels, trying to fulfill the dependency in the LSB header.
#!/bin/bash
#
# httpd Startup script for the Apache HTTP Server
#
# chkconfig: - 85 15
# description: The Apache HTTP Server is an efficient and extensible \
# server implementing the current HTTP standards.
# processname: httpd
# config: /etc/httpd/conf/httpd.conf
# config: /etc/sysconfig/httpd
# pidfile: /var/run/httpd/httpd.pid
#
### BEGIN INIT INFO
# Provides: httpd
# Required-Start: $local_fs $remote_fs $network $named
# Required-Stop: $local_fs $remote_fs $network
# Should-Start: distcache
# Short-Description: start and stop Apache HTTP Server
# Description: The Apache HTTP Server is an extensible server
# implementing the current HTTP standards.
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions
if [ -f /etc/sysconfig/httpd ]; then
. /etc/sysconfig/httpd
fi
# Start httpd in the C locale by default.
HTTPD_LANG=${HTTPD_LANG-"C"}
# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=""
# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
# with the thread-based "worker" MPM; BE WARNED that some modules may not
# work correctly with a thread-based MPM; notably PHP will refuse to start.
# Path to the apachectl script, server binary, and short-form for messages.
apachectl=/usr/local/apache29-PDRM/bin/apachectl
httpd=${HTTPD-/usr/local/apache29-PDRM/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/usr/local/apache29-PDRM/logs/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0
STOP_TIMEOUT=${STOP_TIMEOUT-10}
# The semantics of these two functions differ from the way apachectl does
# things -- attempting to start while running is a failure, and shutdown
# when not running is also a failure. So we just do it the way init scripts
# are expected to behave here.
start() {
echo -n $"Starting $prog: "
LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch ${lockfile}
return $RETVAL
}
# When stopping httpd, a delay (of default 10 second) is required
# before SIGKILLing the httpd parent; this gives enough time for the
# httpd parent to SIGKILL any errant children.
stop() {
echo -n $"Stopping $prog: "
killproc -p ${pidfile} -d ${STOP_TIMEOUT} $httpd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
reload() {
echo -n $"Reloading $prog: "
if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
RETVAL=6
echo $"not reloading due to configuration syntax error"
failure $"not reloading $httpd due to configuration syntax error"
else
# Force LSB behaviour from killproc
LSB=1 killproc -p ${pidfile} $httpd -HUP
RETVAL=$?
if [ $RETVAL -eq 7 ]; then
failure $"httpd shutdown"
fi
fi
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status -p ${pidfile} $httpd
RETVAL=$?
;;
restart)
stop
start
;;
condrestart|try-restart)
if status -p ${pidfile} $httpd >&/dev/null; then
stop
start
fi
;;
force-reload|reload)
reload
;;
graceful|help|configtest|fullstatus)
$apachectl $@
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest}"
RETVAL=2
esac
exit $RETVAL
I believe this script already has the dependency headers, and thus if I run the commands
Many people, use rc.local on Linux. I don't see any benefit in "trashing it" as "not well supported". Also, this file (rc.local) does not require any special "support" since it is not a part of some broader framework. It's simple and works. It's a flat file which is executed at a particular time in the boot sequence.
Also, rc.local is not designed to require a lot of support (to my knowledge), it is simply a place where system admins can put startup scripts they want to start after the other scripts run:
On some versions of Linux, the default
linux #cat rc.local
used to be:
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
exit 0
In addition to the above, for completeness, if you search Google "rc.local" with Linux keywords you get around 833,000 results.
I did not find any "memos" (quick scan) where people were saying "rc.local" is not "well supported".... What support does it need? It's a flat file designed to be edited run as described. How do you "support" a flat file executed at the end of each multiuser runlevel?
Why does it need "support? Inquiring minds want to know
OBTW, on my ubuntu distro, it's blank waiting for someone to add what they want to it:
In fact, all my ubuntu distributions have rc.local available as a "blank" for sys admins who want to use it. It seems "supported to me" since it is there and blank for sys admins to edit and use.