"Fossies" - the Fresh Open Source Software Archive

Member "opensaf-5.21.09/src/nid/opensafd" (14 Sep 2021, 9441 Bytes) of package /linux/misc/opensaf-5.21.09.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "opensafd": 5.21.06_vs_5.21.09.

    1 #!/bin/sh
    2 #
    3 ### BEGIN INIT INFO
    4 # Provides: opensafd
    5 # Required-Start: $local_fs $remote_fs $network $syslog
    6 # Required-Stop: $local_fs $remote_fs $network $syslog
    7 # Should-Start: 
    8 # Should-Stop: 
    9 # Default-Start: 3 4 5
   10 # Default-Stop: 0 1 2 6
   11 # Short-Description: Start and stop the OpenSAF node
   12 # Description: Start and stop the OpenSAF node
   13 ### END INIT INFO
   14 
   15 osafdirfile=/etc/opensaf/osafdir.conf
   16 osafprog="opensafd"
   17 osafprog_inprogress="opensafd_inprogress"
   18 
   19 # Source LSB functions library
   20 . /lib/lsb/init-functions
   21 
   22 if [ ! -r $osafdirfile ]; then
   23     logger -t $osafprog "can't read $osafdirfile, exiting."
   24     exit 6
   25 else
   26     . $osafdirfile
   27     . $pkgsysconfdir/nid.conf
   28 fi
   29 
   30 binary=$pkglibdir/$osafprog
   31 lockfile=$lockdir/$osafprog
   32 lockfile_inprogress=$lockdir/$osafprog_inprogress
   33 amfnd_bin=$pkglibdir/osafamfnd
   34 amfnd_pid=$pkgpiddir/osafamfnd.pid
   35 
   36 MANAGE_TIPC=${OPENSAF_MANAGE_TIPC:-"yes"}
   37 RETVAL=0
   38 TERMTIMEOUT=${OPENSAF_TERMTIMEOUT:-60}
   39 
   40 nodetype=$(cat $pkgsysconfdir/node_type)
   41 nodeinitdotconf=$pkgsysconfdir/nodeinit.conf.$nodetype
   42 
   43 osafversion=1
   44 if [ $osafversion = "1" ] ; then
   45        osafversion=5.21.09
   46 fi
   47 
   48 osafcshash=5d4ac92ff7110005bae206b83b7463d5aeb27224
   49 
   50 unload_tipc() {
   51 
   52     # Unload TIPC if already loaded
   53     if [ "$MANAGE_TIPC" = "yes" ] && grep tipc /proc/modules >/dev/null 2>&1; then
   54         modprobe -r tipc >/dev/null 2>&1
   55         if [ $? -eq 1 ]; then
   56             logger -t $osafprog "warning: TIPC module unloading failed"
   57         fi
   58     fi
   59 }
   60 
   61 check_tipc() {
   62 
   63     if [ "$MANAGE_TIPC" != "yes" ]; then
   64         return 0
   65     fi
   66 
   67     tipc=$(which tipc 2> /dev/null)
   68     tipc_config=$(which tipc-config 2> /dev/null)
   69 
   70     if ! [ -x "${tipc}" ] && ! [ -x "${tipc_config}" ]; then
   71         logger -s -t $osafprog "error: neither tipc nor tipc-config is available"
   72         exit 1
   73     fi
   74 
   75     unload_tipc
   76 }
   77 
   78 setup_env() {
   79     # The following lines if --enable-gcov is configured
   80     # If running in UML uncomment the next line
   81     # echo 100 >  /proc/sys/net/ipv4/igmp_max_memberships
   82     # gcov collecton is using multicast, to change default multicast group and multicast group:
   83     # IPv4:
   84     # export OPENSAF_GCOV_MULTICAST_GROUP="224.0.0.1"
   85     # IPv6:
   86     # export OPENSAF_GCOV_MULTICAST_GROUP="ff02::1"
   87     # export OPENSAF_GCOV_MULTICAST_PORT="4711"
   88 
   89     # Make sure this kernel has POSIX shared memory configured
   90     if [ ! -d /dev/shm ]; then
   91         logger -s -t $osafprog "POSIX shared memory (/dev/shm) not enabled, exiting."
   92         exit 6
   93     fi
   94 
   95     # /var/lock & /var/run could be tmpfs mounts and needs to be
   96     # recreated at each boot
   97     directories="$lockdir $pkgpiddir"
   98     for directory in $directories; do
   99         mkdir -p $directory
  100         if [ -n "$OPENSAF_GROUP" ]; then
  101             getent group $OPENSAF_GROUP > /dev/null && chgrp $OPENSAF_GROUP $directory
  102         fi
  103         if [ -n "$OPENSAF_USER" ]; then
  104             getent passwd $OPENSAF_USER > /dev/null && chown $OPENSAF_USER $directory
  105         fi
  106     done
  107 }
  108 
  109 clean_shm() {
  110     # Remove shared memory files created by OpenSAF
  111     find /dev/shm/. -maxdepth 1 -name 'opensaf_*' -exec rm -f {} \;
  112 }
  113 
  114 enable_coredump() {
  115     core_size="unlimited"
  116     core_pattern="/var/crash/opensaf/core_%t.%e.%p"
  117 
  118     if [ ! -d /var/crash/opensaf ]; then
  119         mkdir -p /var/crash/opensaf
  120     fi
  121 
  122     if [ `ulimit -c` = 0 ]; then
  123         ulimit -c $core_size
  124     fi
  125     echo $core_pattern > /proc/sys/kernel/core_pattern
  126 }
  127 
  128 final_clean() {
  129     # Loop throught all the OpenSAF LSB CLC-CLI scripts to clean staling pid/lock
  130     for cmd in `ls $pkgclcclidir/osaf-*`; do
  131         # skip dtm here to allow shutdown of other services (e.g. amfd)
  132         if [ "$cmd" != "$pkgclcclidir/osaf-dtm" ]; then
  133             $cmd stop >/dev/null 2>&1
  134         fi
  135     done
  136 
  137     if [ "$MDS_TRANSPORT" = "TIPC" ]; then
  138         unload_tipc
  139     else
  140         # stop dtm, now all dependent services should be stopped
  141         $pkgclcclidir/osaf-dtm stop >/dev/null 2>&1
  142         rm -f $pkglocalstatedir/osaf_dtm_intra_server
  143     fi
  144 
  145     clean_shm
  146 
  147     rm -f "$lockfile" "$NIDFIFO" "$pkglocalstatedir/node_id"
  148 }
  149 
  150 generate_nodeid() {
  151     CHASSIS_ID_FILE=$pkgsysconfdir/chassis_id
  152     SLOT_ID_FILE=$pkgsysconfdir/slot_id
  153     SUBSLOT_ID_FILE=$pkgsysconfdir/subslot_id
  154     CHASSIS_ID=2
  155     SUBSLOT_ID=15
  156     if test -f "$CHASSIS_ID_FILE"; then
  157         CHASSIS_ID=$(cat "$CHASSIS_ID_FILE")
  158         if [ "$CHASSIS_ID" -gt "16" ] || [ "$CHASSIS_ID" -lt "1" ]
  159         then
  160             echo "CHASSIS ID Should be in the range of 1 to 16"
  161             echo "Quitting......"
  162             exit 1
  163         fi
  164     fi
  165     if test -f "$SUBSLOT_ID_FILE"; then
  166         SUBSLOT_ID=$(cat "$SUBSLOT_ID_FILE")
  167         if [ "$SUBSLOT_ID" -gt "15" ] || [ "$SUBSLOT_ID" -lt "0" ]; then
  168             echo "SUBSLOT ID Should be in the range of 0 to 15"
  169             echo "Quitting......"
  170             exit 1
  171         fi
  172     fi
  173     if ! test -f "$SLOT_ID_FILE"; then
  174         return 0
  175     fi
  176     SLOT_ID=$(cat "$SLOT_ID_FILE")
  177     if [ "$SLOT_ID" -eq "0" ]; then
  178         return 0
  179     fi
  180     if [ "$SLOT_ID" -gt "4095" ] || [ "$SLOT_ID" -lt "1" ]
  181     then
  182         echo "SLOT ID Should be in the range of 1 to 4095"
  183         echo "Quitting......"
  184         exit 1
  185     fi
  186     printf "00%02x%02x%02x\n" $CHASSIS_ID $((SLOT_ID & 255)) $((SUBSLOT_ID ^ ((SLOT_ID >> 8) & 15) )) > $pkglocalstatedir/node_id
  187     chmod 744 $pkglocalstatedir/node_id
  188 }
  189 
  190 check_transport() {
  191     rm -f $pkglocalstatedir/osaf_dtm_intra_server
  192     if [ $MDS_TRANSPORT != "TCP" ] && [ $MDS_TRANSPORT != "TIPC" ]
  193     then
  194         export MDS_TRANSPORT=TCP
  195     fi
  196 
  197     if [ "$MDS_TRANSPORT" = "TIPC" ]; then
  198         # Transport TIPC
  199         check_tipc
  200     else
  201         # Transport TCP
  202         generate_nodeid
  203     fi
  204 }
  205 
  206 # Create a mutex for start/stop on the filesystem. Will use trap if available.
  207 mutex_create() {
  208     timeout=10
  209     interval=2
  210     while [ $timeout -gt 0 ]; do
  211         if mkdir "$lockfile_inprogress"; then
  212             trap 'rmdir "$lockfile_inprogress"; exit $?' INT TERM EXIT 2> /dev/null
  213             return 0
  214         else
  215             # lockfile exist, try again until timeout
  216             if [ $timeout -eq 10 ]; then  # log only one time
  217                 log_warning_msg "opensafd start/stop in progress. Waiting for lockfile to be removed"
  218                 logger -t $osafprog "opensafd start/stop in progress. Waiting for lockfile to be removed"
  219             fi
  220             sleep $interval
  221             timeout=$((timeout-interval))
  222         fi
  223     done
  224 
  225     log_warning_msg "opensafd start/stop already in progress. Unable to continue"
  226     logger -t $osafprog "opensafd start/stop already in progress. Unable to continue"
  227     log_warning_msg "To forcefully start/stop OpenSAF remove $lockfile_inprogress"
  228     logger -t $osafprog "To forcefully start/stop OpenSAF remove $lockfile_inprogress"
  229     return 1
  230 }
  231 
  232 mutex_remove() {
  233     rmdir "$lockfile_inprogress" 2> /dev/null
  234     trap - INT TERM EXIT 2> /dev/null
  235 }
  236 
  237 start() {
  238     setup_env
  239 
  240     if ! mutex_create; then
  241         return 1
  242     fi
  243 
  244     export LD_LIBRARY_PATH=$pkglibdir:$LD_LIBRARY_PATH
  245         pidofproc -p $amfnd_pid $amfnd_bin > /dev/null 2>&1
  246     lsb_status=$?
  247     if [ $lsb_status -eq 0 ]; then
  248         RETVAL=0
  249         log_success_msg
  250         mutex_remove
  251         return $RETVAL
  252     fi
  253 
  254     rm -f $pkgpiddir/*
  255     rm -f $pkglogdir/nid.log
  256 
  257     [ -x $daemon ] || exit 5
  258 
  259     check_transport
  260 
  261     logger -t $osafprog "Starting OpenSAF Services($osafversion - $osafcshash) (Using $MDS_TRANSPORT)"
  262 
  263     # Comment/Uncomment if you want cores disabled/enabled
  264     #enable_coredump
  265 
  266     echo -n "Starting OpenSAF Services (Using $MDS_TRANSPORT):"
  267     start_daemon $binary $args
  268     RETVAL=$?
  269     if [ $RETVAL -eq 0 ]; then
  270         logger -t $osafprog "OpenSAF($osafversion - $osafcshash) services successfully started"
  271         touch $lockfile
  272         log_success_msg
  273     else
  274         final_clean
  275         log_failure_msg
  276         if [ $REBOOT_ON_FAIL_TIMEOUT -ne 0 ]; then
  277             logger -t $osafprog "Starting OpenSAF failed, rebooting..."
  278             sleep $REBOOT_ON_FAIL_TIMEOUT
  279             mutex_remove
  280             /sbin/reboot &
  281         else
  282             logger -t $osafprog "Starting OpenSAF failed"
  283         fi
  284     fi
  285     mutex_remove
  286     return $RETVAL
  287 }
  288 
  289 stop() {
  290     # flush all internal opensaf log messages into disk before stopping
  291     $bindir/osaflog --flush
  292 
  293     if ! mutex_create; then
  294         return 1
  295     fi
  296 
  297     logger -t $osafprog "Stopping OpenSAF Services"
  298     amfpid=`pidofproc -p $amfnd_pid $amfnd_bin`
  299     echo -n "Stopping OpenSAF Services: "
  300     if [ -n "$amfpid" ]; then
  301         kill $amfpid
  302         timeout=$TERMTIMEOUT
  303         while [ $timeout -gt 0 ]; do
  304             sleep 1
  305             [ -d /proc/$amfpid ] || break
  306             timeout=$((timeout-1))
  307         done
  308         [ -d /proc/$amfpid ] && RETVAL=1
  309         if [ $RETVAL -eq 1 ]; then
  310             logger -t $osafprog "amfnd has not yet exited, killing it forcibly."
  311             kill -9 $amfpid
  312         fi
  313     else
  314         pkill -9 osaf* >/dev/null 2>&1
  315     fi
  316 
  317     final_clean
  318     mutex_remove
  319 
  320     if [ $RETVAL -eq 0 ]; then
  321         logger -t $osafprog "OpenSAF services successfully stopped"
  322         log_success_msg
  323     else
  324         log_failure_msg
  325         # If AMF fails to terminate its components,
  326         # this system is out of control, reboot it now!
  327         if [ $REBOOT_ON_FAIL_TIMEOUT -ne 0 ]; then
  328             logger -t $osafprog "Stopping OpenSAF failed, rebooting..."
  329             sleep $REBOOT_ON_FAIL_TIMEOUT
  330             /sbin/shutdown -r now "OpenSAF termination failed (timeout)"
  331         else
  332             logger -t $osafprog "Stoping OpenSAF failed"
  333         fi
  334     fi
  335     return $RETVAL
  336 }
  337 
  338 restart() {
  339     stop
  340     start
  341 }
  342 
  343 tryrestart() {
  344     [ -e $lockfile ] && restart
  345     return 0
  346 }
  347 
  348 reload() {
  349     echo -n "Reloading $osafprog: "
  350     log_warning_msg
  351     logger -t $osafprog "reloading configuration is currently an unimplemented LSB feature"
  352     return 3
  353 }
  354 
  355 forcereload() {
  356     reload
  357     restart
  358     return 0
  359 }
  360 
  361 status() {
  362     amfpid=`pidofproc -p $amfnd_pid $amfnd_bin`
  363     if [ -n "$amfpid" ]; then
  364         amf-state siass ha
  365         RETVAL=$?
  366     else
  367         echo "The OpenSAF HA Framework is not running"
  368         RETVAL=3
  369     fi
  370 
  371     return $RETVAL
  372 }
  373 
  374 case "$1" in
  375   start)
  376     start
  377     RETVAL=$?
  378     ;;
  379   stop)
  380     stop
  381     RETVAL=$?
  382     ;;
  383   restart)
  384     restart
  385     RETVAL=$?
  386     ;;
  387   try-restart|condrestart)
  388     tryrestart
  389     RETVAL=$?
  390     ;;
  391   reload)
  392     reload
  393     RETVAL=$?
  394     ;;
  395   force-reload)
  396     forcereload
  397     RETVAL=$?
  398     ;;
  399   status)
  400     status
  401     RETVAL=$?
  402     ;;
  403   *)
  404     echo "Usage: $0 {start|stop|restart|try-restart|reload|force-reload|status}"
  405     RETVAL=2
  406 esac
  407 
  408 exit $RETVAL