sadm_startup.sh
Updated: 2018/10/18
Previous page   -  Return to software list   -  Index
 
NAME

sadm_startup.sh   -   Script executed at system startup (if SADMIN service is enable - see sadm_service_ctl.sh).


 
DESCRIPTION
  • The system startup script is located in the $SADMIN/sys directory.
  • You can customize this file to your own need, it will never be modify by future update.
  • You could have a different file for each of your servers or use the same for all your servers.
    By inserting your hostname in the 'case statement' you can use the same on all your servers.
  • This script will be executed at system startup only if the SADMIN service is activated ("sadm_service_ctrl.sh -e").
 
Example of sadm_startup.sh

$ cat $SADMIN/sys/sadm_startup.sh
#!/bin/sh
... 
... 

# --------------------------------------------------------------------------------------------------
#                                   This Script environment variables
# --------------------------------------------------------------------------------------------------
DEBUG_LEVEL=0                               ; export DEBUG_LEVEL        # 0=NoDebug Higher=+Verbose
NTP_SERVER="0.ca.pool.ntp.org"              ; export NTP_SERVER         # Canada NTP Pool


# --------------------------------------------------------------------------------------------------
#                                S c r i p t    M a i n     P r o c e s s
# --------------------------------------------------------------------------------------------------
main_process()
{
    ERROR_COUNT=0
    #sadm_writelog "$SADM_80_DASH"                                       # 80 Equal Sign Line
    sadm_writelog "*** Running SADM System Startup Script on $(sadm_get_fqdn)  ***"
    sadm_writelog " "
    
    sadm_writelog "Running Startup Standard Procedure"
    sadm_writelog "  Removing old files (log,pid) in ${SADM_TMP_DIR}"
    rm -f ${SADM_TMP_DIR}/* >> $SADM_LOG 2>&1

    sadm_writelog "  Removing SADM System Monitor Lock File ${SADM_BASE_DIR}/sysmon.lock"
    rm -f ${SADM_BASE_DIR}/sysmon.lock >> $SADM_LOG 2>&1

    sadm_writelog "  Synchronize System Clock with NTP server $NTP_SERVER"
    sleep 2
    ntpdate -u $NTP_SERVER >$SADM_TMP_FILE1 2>&1
    if [ $? -ne 0 ] 
        then sadm_writelog "  NTP Error Synchronizing Time with $NTP_SERVER" 
             cat $SADM_TMP_FILE1 | while read wline ; do sadm_writelog "$wline"; done
             ERROR_COUNT=$(($ERROR_COUNT+1))
    fi
             
    sadm_writelog "  Start 'nmon' performance system monitor tool"
    ${SADM_BIN_DIR}/sadm_nmon_watcher.sh > /dev/null 2>&1
    if [ $? -ne 0 ] 
        then sadm_writelog "  Error starting 'nmon' System Monitor." 
             ERROR_COUNT=$(($ERROR_COUNT+1))
    fi

    # Special Operation for some particular System
    sadm_writelog " "
    sadm_writelog "Starting specific startup procedure for $SADM_HOSTNAME"
    case "$SADM_HOSTNAME" in
        "myhost" )      sadm_writelog "  Start SysInfo Web Server"
                        /myapp/bin/start_httpd.sh >> $SADM_LOG 2>&1
                        if [ $? -ne 0 ] 
                            then sadm_writelog "  Error starting 'MyApp httpd' Service." 
                                 ERROR_COUNT=$(($ERROR_COUNT+1))
                        fi
                        ;;
                *)      sadm_writelog "  No particular procedure needed for $SADM_HOSTNAME"
                        ;;
    esac

    sadm_writelog " "
    return $ERROR_COUNT                                              # Return Default return code
}
 
 
# --------------------------------------------------------------------------------------------------
# 	                          	S T A R T   O F   M A I N    P R O G R A M
# --------------------------------------------------------------------------------------------------
    sadm_start                                                          # Init Env Dir & RC/Log File
    if ! [ $(id -u) -eq 0 ]                                             # If Cur. user is not root 
        then sadm_writelog "Script can only be run by the 'root' user"  # Advise User Message
             sadm_writelog "Process aborted"                            # Abort advise message
             sadm_stop 1                                                # Close and Trim Log
             exit 1                                                     # Exit To O/S with Error
    fi
    main_process                                                        # Main Process
    SADM_EXIT_CODE=$?                                                   # Save Process Exit Code
    sadm_writelog "End of startup script."                              # End of Script Message
    sadm_stop $SADM_EXIT_CODE                                           # Upd. RCH File & Trim Log
    exit $SADM_EXIT_CODE                                                # Exit With Global Err (0/1)


 
AUTHOR

Written by Jacques Duplessis (support@sadmin.ca.).


 
COPYRIGHT

  • Copyright © 2018 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html.
  • This is free software: you are free to change and redistribute it.
  • There is NO WARRANTY, to the extent permitted by law.

 
SEE ALSO
    • sadm_shutdown.sh    (System shutdown script)
    • sadm_service_ctrl.sh        (Activate/De-activate system startup/shutdown script execution).
    • Script use for the SADMIN service itself are ;
      • For InitV SADMIN use file '$SADMIN/cfg/.sadmin.rc'.
      • For Systemd SADMIN use file '$SADMIN/cfg/.sadmin.service'.

 
INDEX
NAME
DESCRIPTION
AUTHOR
COPYRIGHT
SEE ALSO
Copyright © 2015-2019 - www.sadmin.ca - Suggestions, Questions or Report a problem at support@sadmin.ca