Problem

How can I run msqld automatically at boot time?

Solution

TAT uses an msql database to locate LCUs for modular tests using VxWorks.

It might be therefore convenient to run msqld at boot time.

This can be done installing the following msql script to /etc/rc.d/init.d:


1) ================== /etc/rc.d/init.d/msql script:


#!/usr/bin/ksh

#  Need to set the path or else 'sed', 'su', etc not found.
PATH=/bin:/usr/bin

#  HP-UX and Redhat Linux collect the results of the 'start_msg'
#  calls before running any of the scripts and release-dependent
#  scripts to whom this task is delegated may require that NFS
#  and/or automounter are running, which, while is sure to be
#  the case when this script is called with 'start', it is not
#  certain when it is called with 'start_msg'. For this reason
#  the display of messages is handled by *this* script, but the
#  main responsibility is delegated to the release dependent
#  script.

THING="MSQL database daemon"

case "$1" in
    start_msg) echo "Start $THING"
               exit 0 ;;
    stop_msg)  echo "Stop $THING"
               exit 0 ;;
    start)     : ;;
    stop)      : ;;
    *)         echo "Usage: $0 { start | stop | start_msg | stop_msg }" >&2
               exit 1 ;;
esac

BOOT_RELEASE_DEFINER=almamgr
ALMASW_ROOTDIR=`su - $BOOT_RELEASE_DEFINER -c '. .bashrc; echo $ALMASW_ROOTDIR' 2>/dev/null`
ALMASW_RELEASE=`su - $BOOT_RELEASE_DEFINER -c '. .bashrc; echo $ALMASW_RELEASE' 2>/dev/null`
INITD_SCRIPT=`echo $0 | sed -e 's/.*\///' -e 's/[KS][0-9]*//'`
BOOT_SCRIPT=$ALMASW_ROOTDIR/$ALMASW_RELEASE/System/initd_$INITD_SCRIPT
exec $BOOT_SCRIPT "$@"

#  $Id: FaqMsqld.txt,v 1.2 2014/05/12 14:37:38 AlessandroCaproni Exp $


2) ================== create the following links: 


# chmod 555 /etc/rc.d/init.d/msql 
# ln -s /etc/rc.d/init.d/msql /etc/rc.d/rc3.d/S99msql 
# ln -s /etc/rc.d/init.d/msql /etc/rc.d/rc4.d/S99msql 
# ln -s /etc/rc.d/init.d/msql /etc/rc.d/rc5.d/S99msql 
# ln -s /etc/rc.d/init.d/msql /etc/rc.d/rc6.d/K01msql 


3) ================== correct /alma/MAR2002/System/initd_msql replacing the  vlt user by almamgr user.
Attached is the modified version:


#!/usr/bin/ksh
##*************************************
##
## E.S.O. - VLT project
##
## "@(#) $Id: FaqMsqld.txt,v 1.2 2014/05/12 14:37:38 AlessandroCaproni Exp $" 
##
## msql"
## 
##  who      when     what
## -------- -------- ------------------
## awalland 21/04/97 Startup of msql at boot time
## vltmgr   06/19/98 created for cmm
## ahuxley  17/10/99 changed to ksh script for future flexibility
##                   tidied
##                   added SunOS run messages
##                   removed env defs - they're picked up by 'su -'
##                   removed 'exit' which lost *real* return code
## ahuxley  13/12/99 fixed lost exit codes
##                   added comment block for startup sequences
## ahuxley  14/08/00 added sourcing of .bashrc to 'su - vlt -c ...' call
##                   since su'd bash doesn't source it.
#
#  To install this file on Suns:
#       cp <full_path_of_this_file> /etc/init.d/msql
#       ln -s /etc/init.d/msql /etc/rc3.d/S91msql
#       ln -s /etc/init.d/msql /etc/rc0.d/K08msql
#       
#  To install this file on HPs:
#       cp <full_path_of_this_file> /sbin/init.d/msql
#       ln -s /sbin/init.d/msql /sbin/rc3.d/S910msql
#       ln -s /sbin/init.d/msql /sbin/rc2.d/K089msql
#
#  To install this file on Redhat 6.* Linux:
#       cp <full_path_of_this_file> /etc/rc.d/init.d/msql
#       ln -s /etc/rc.d/init.d/msql /etc/rc.d/rc3.d/S91msql
#       ln -s /etc/rc.d/init.d/msql /etc/rc.d/rc2.d/K08msql  (run level has not been verified - AHU 17/10/99)
#

PATH=/bin:/usr/bin; export PATH
UNAMES=`uname -s`

case $1 in
        start_msg) echo "Start msql daemon " ;;
        stop_msg)  echo "Stop msql daemon " ;;
        start)     [ $UNAMES = SunOS ] && echo "Starting msql daemon ... \c"
                   su - almamgr -c '. ./.bashrc; nohup msqld &'
                   RC=$?
                   [ $UNAMES = SunOS ] && echo "done" ;;
        stop)      [ $UNAMES = SunOS ] && echo "leaving msql daemon to be killed by init" ;;
        *)         echo "Usage: $0 { start | stop | stop_msg | start_msg }"
                   RC=2 ;;
esac

exit ${RC:-0}
<verbatim>

==========

Thanks to J.Ibsen for the instructions!