Hallo, dies ist ein Test.
PWD: /www/data-lst1/unixsoft/unixsoft/kaempfer/.public_html
Running in File Mode
Relative path: ./../../../../../.././lib/svc/method/svc-webui-server
Real path: /lib/svc/method/svc-webui-server
Zurück
#!/bin/sh # # Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved. . /lib/svc/share/smf_include.sh # Apache configuration files WEBUI_CONF_DIR=/var/webui/conf WEBUI_HTTPD_CONF=${WEBUI_CONF_DIR}/webui.conf WEBUI_RUNTIME_DIR=/system/volatile/webui WEBUI_HTTP_LOCK_FILE=${WEBUI_RUNTIME_DIR}/webui-server.lock WEBUI_HTTP_PID=${WEBUI_RUNTIME_DIR}/webui-server.pid WEBUI_CONFD_DIR=${WEBUI_CONF_DIR}/conf.d # constants WAIT_FOR_LISTEN_ADRS_OPEN=10 # Wait for at most 10 seconds for port to open WEBUI_LIB=/usr/lib/webui WEBUI_PRIVATE_BIN=${WEBUI_LIB}/bin WEBUI_PREFS_CLI=${WEBUI_PRIVATE_BIN}/webuiprefs # required commands APACHE2=/usr/apache2/2.4/bin/apachectl HTTPD=/usr/apache2/2.4/bin/httpd MKDIR=/usr/bin/mkdir RM=/usr/bin/rm MV=/usr/bin/mv PGREP=/usr/bin/pgrep SVCPROP=/usr/bin/svcprop FIND=/usr/bin/find DIFF=/usr/bin/diff ZONENAME=smf_zonename # Automated Install SMF variables PROP_LISTEN_ADRS='conf/listen_addresses' # Global SMF property values SMF_LISTEN_ADRS=$($SVCPROP -p $PROP_LISTEN_ADRS $SMF_FMRI 2>/dev/null) # extract first listen address for wait_for_port test set -A array ${SMF_LISTEN_ADRS} FIRST_LISTEN_ADRS=${array[0]} CURRENT_ZONE=`${ZONENAME}` 2> /dev/null # # verify_apache_restart # Verify if apache server needs a graceful restart due to creation/ # removal/modification of config files. If any of the known list of # config paths is newer than $WEBUI_HTTP_PID, a graceful restart is # required. # # Args # None # Return: # 0 - Newer apache configuration found, server needs a restart # 1 - Apache server configuration up-to-date, no need to restart # function verify_apache_restart { if [[ ! -f $WEBUI_HTTP_PID ]]; then return 0 fi set -A files_to_check $WEBUI_HTTPD_CONF set -A dirs_to_check $WEBUI_CONFD_DIR # Use file name generation to return only matching files which exist # when this script is executed. set -A wildcards_to_check ~(N)$WEBUI_CONFD_DIR/*.conf set -A paths_to_check ${files_to_check[*]} ${dirs_to_check[*]} \ ${wildcards_to_check[*]} # Check if any of the paths to check are newer than the pid file. # Use -prune to prevent find examining sub-dirs of dirs_to_check set -A newer_files \ $($FIND ${paths_to_check[*]} -prune -newer $WEBUI_HTTP_PID) if [[ ${#newer_files[@]} -gt 0 ]] ; then return 0 fi return 1 } # # test_connect_port # Attempts to connect to the specified port on localhost # # Args # $1 = the port number to connect to # Globals # None # Returns # 0 - Successfully connect to specified port # 1 - Failed to connect to the specified port # function test_connect_port { if test "${FIRST_LISTEN_ADRS#*:}" != $FIRST_LISTEN_ADRS then # : in $FIRST_LISTEN_ADRS IFS=':' set -A address $FIRST_LISTEN_ADRS if [[ -n "$1" ]]; then (: < /dev/tcp/${address[0]}/${address[1]}) 2>/dev/null return $? fi else # : not in $FIRST_LISTEN_ADRS if [[ -n "$1" ]]; then (: < /dev/tcp/localhost/${FIRST_LISTEN_ADRS}) 2>/dev/null return $? fi fi return 1 } # # start_apache # Starts the apache web server, waits until the PID file has # been created, or a timeout reached # # Args # $1 - The apache config file to be used # Returns # 0 - Successfully started apache # 1 - Failed to start apache # function start_apache { if [[ -z "$1" ]]; then return 1 fi if [[ $($PGREP -z ${CURRENT_ZONE} \ -f "${HTTPD} -f ${WEBUI_HTTPD_CONF}") ]]; then echo "${HTTPD} -f ${WEBUI_HTTPD_CONF} is already running" else if [[ -e ${WEBUI_HTTP_PID} ]]; then echo "${WEBUI_HTTP_PID} already exists, removing it" # as it prevents apache to start if present ${RM} -f ${WEBUI_HTTP_PID} fi fi if [[ ! -d ${WEBUI_RUNTIME_DIR} ]] ; then ${MKDIR} ${WEBUI_RUNTIME_DIR} fi attempt=3 while [[ ! -e ${WEBUI_HTTP_PID} && $attempt -gt 0 ]]; do attempt=$(( $attempt - 1 )) echo "Starting Apache webserver" ${APACHE2} -f $1 -k start if [[ $? -ne 0 ]]; then return 1 fi # Wait until it's really started, i.e. the PID file exists typeset -i timeout=30 while [[ ! -e ${WEBUI_HTTP_PID} && $timeout -gt 0 ]]; do timeout=$(( $timeout - 1 )) sleep 1 done done if [[ ! -e ${WEBUI_HTTP_PID} ]]; then return 1 fi echo "Apache start completed" return 0 } # # wait_for_port # Loops until the specified port is opened, or a timeout reached # # Args # $1 - the port number to connect to # $2 - (Optional) how long to wait in seconds # Globals # None # Returns # 0 - Successfully connected to port before timeout # 1 - Failed to connect to port, or invalid port # function wait_for_port { if [[ -z "$1" ]]; then return 1 fi typeset timeout="false" if [[ -n "$2" ]]; then timeout="$2" fi # The assumption is that this test is quick and sleeping 1 second is # reasonable in relation to the overall timeout. while [[ $timeout == "false" || $timeout -gt 0 ]]; do if test_connect_port "$1"; then break fi sleep 1 if [[ $timeout != "false" ]]; then timeout=$(( $timeout - 1 )) fi done } # # verify_smf_properties # Ensures specific SMF property values are set. # # Args # None # Returns # Nothing, Exits with SMF_EXIT_ERR_CONFIG # function verify_smf_properties { if [[ -z "${SMF_LISTEN_ADRS}" ]]; then echo "HTTPS port '${PROP_LISTEN_ADRS}', is not set." exit ${SMF_EXIT_ERR_CONFIG} fi } # # run_preferences_import # # Execute to import any delivered preferences # # Args # None # Returns # On any failure will return 1, # function run_preferences_import { if [[ -x ${WEBUI_PREFS_CLI} ]]; then echo "Importing preference files" if ${WEBUI_PREFS_CLI} import -A; then echo "Import succeeded" return ${SMF_EXIT_OK} else echo "Import failure, entering a degraded state" return 1 fi fi return 0 } # If an error occurred while importing, we will enter a degraded state. IMPORT_ERROR_OCCURRED=false case "$1" in 'start') # Code to execute on start # ensure that the default properties are set verify_smf_properties run_preferences_import || IMPORT_ERROR_OCCURRED=true # Start up the apache web server using our http config file if [[ -f ${WEBUI_HTTPD_CONF} ]] ; then start_apache ${WEBUI_HTTPD_CONF} if [[ $? -ne 0 ]] ; then echo "Unable to start apache process" exit $SMF_EXIT_ERR_CONFIG fi wait_for_port ${FIRST_LISTEN_ADRS} ${WAIT_FOR_LISTEN_ADRS_OPEN} else echo "Unable to start apache process due to missing" \ "config file ${WEBUI_HTTPD_CONF}" exit $SMF_EXIT_ERR_CONFIG fi ;; 'stop') # Code to execute on stop # stop apache server if [[ -f ${WEBUI_HTTPD_CONF} ]] ; then ${APACHE2} -f ${WEBUI_HTTPD_CONF} -k stop if [[ $? -ne 0 ]] ; then echo "Unable to stop apache process" exit $SMF_EXIT_ERR_CONFIG fi # wait for the apache servers to exit or the stop timeout is reached while [[ $($PGREP -z ${CURRENT_ZONE} \ -f "${HTTPD} -f ${WEBUI_HTTPD_CONF}") ]]; do sleep 1 done else echo "Unable to stop apache process due to missing" \ "config file ${WEBUI_HTTPD_CONF}" exit $SMF_EXIT_ERR_CONFIG fi ;; 'refresh') # ensure that the default properties are set verify_smf_properties run_preferences_import || IMPORT_ERROR_OCCURRED=true # Check if restart required, e.g. conf file changes verify_apache_restart typeset -i ret1=$? if [[ $ret1 -eq 0 ]] ; then print -n "Configuration files have changed, " # Apache doesn't like graceful restarts occurring to quickly, so # we try to wait until it stabilizes before completing the SMF action. # # To determine whether Apache has stabilized, we are relying on the # fact that it touches/updates the PID file when it has reached that # point. # # Create a temp file to compare its timestamp against the Apache PID # file timestamp. # BEFORE_RESTART=$(mktemp -p ${WEBUI_RUNTIME_DIR} .webui.before-XXXXX) echo "refreshing webserver." ${APACHE2} -f ${WEBUI_HTTPD_CONF} -k graceful # We wait for Apache to refresh its PID file to know when it # has completed restarting, and then wait for the port to be # available. # # We stop waiting about 60 seconds before the configured # refresh method timeout so that we don't risk being killed by # SMF prematurely. typeset -i wait_for_pid_timeout=0 typeset -i wait_for_port_timeout=0 if [[ $timeout -gt ${WAIT_FOR_LISTEN_ADRS_OPEN} ]]; then wait_for_pid_timeout=$(( $timeout - ${WAIT_FOR_LISTEN_ADRS_OPEN})) wait_for_port_timeout=${WAIT_FOR_LISTEN_ADRS_OPEN} elif [[ $timeout -gt 0 ]]; then wait_for_pid_timeout=$timeout fi while [[ $wait_for_pid_timeout -gt 0 && ( ! -f ${WEBUI_HTTP_PID} || \ ${BEFORE_RESTART} -nt ${WEBUI_HTTP_PID} ) ]]; do # The assumption is that this test is quick and # sleeping 1 second is reasonable in relation to the # overall timeout. sleep 1 wait_for_pid_timeout=$(( $wait_for_pid_timeout - 1 )) done # Try to wait for the port to be available wait_for_port ${FIRST_LISTEN_ADRS} ${wait_for_port_timeout} if [[ -n ${BEFORE_RESTART} ]]; then rm -f ${BEFORE_RESTART} fi else echo "Configuration files have not changed, " \ "not refreshing webserver." fi ;; *) echo "Usage: $0 { start | stop | refresh }" exit 1 ;; esac if [[ ${IMPORT_ERROR_OCCURRED} == true ]]; then smf_method_exit ${SMF_EXIT_DEGRADED} import_failure \ "Error importing one or more files" fi exit ${SMF_EXIT_OK}