#!/bin/bash # # description: Ubuntu Linux dist compatible init.d script # for starting/stopping WANdisco svnreplicator daemon # # Copyright (c) 2006-2016 WANdisco,Inc. Pleasanton,CA,USA # All rights reserved. # # Author: WANdisco Support Staff <support@wandisco.com> # ############################################################ # MODIFY THE FOLLOWING VARIBLES TO MATCH YOUR ENVIRONMENT export JAVA_HOME=/usr/lib/jvm/java-6-sun WD_USER="root" WD_INSTALL_DIR="/home/user/svnrep/svn-replicator" # (WD_INSTALL_DIR _MUST_ end with "/svn-replicator" or errors in installation can occur. ############################################################ # DO NOT MODIFY THESE VARIABLES # Source function library. . /lib/lsb/init-functions CURRENT_OS=`uname -sv` OS_DEFINER="/etc/debian_version" PERL_LOC="/usr/bin" WD_AGENT_NAME="svnreplicator" WD_SHUTDOWN="${WD_INSTALL_DIR}/bin/shutdown" WD_AGENT_BIN="${WD_INSTALL_DIR}/bin/${WD_AGENT_NAME}" WD_AGENT_CONF="${WD_INSTALL_DIR}/config/prefs.xml" # Maximum number of file descriptors. MAXFDS="65000" ############################################################ # Startup procedure. start() { # Checks to see if the replicator is running. REPRUN=`ps ax | grep "${WD_AGENT_NAME}" | grep -v grep | wc -l` RETVAL=$? if [ ${REPRUN} -gt 0 ] then echo "The replicator is already running." echo "------------------------------" else echo "Starting ${WD_AGENT_BIN}:" # Don't produce core files. ulimit -S -c 0 >/dev/null 2>&1 # Set maximum number of file descriptors. ulimit -n ${MAXFDS} >/dev/null 2>&1 start-stop-daemon --start --quiet --chuid ${WD_USER} --exec ${WD_AGENT_BIN} > /dev/null 2>&1 # Checks the last transaction and returns a value depending on success or failure. RETVAL=$? # Sleep to prevent errors in restarts. sleep 4 if [ ${RETVAL} -eq 0 ] then echo "Status Code: $RETVAL: The ${WD_AGENT_NAME} started successfully." echo "------------------------------" fi if [ ${RETVAL} -eq 2 ] then echo "Status Code: $RETVAL: The ${WD_AGENT_NAME} failed to start successfully." status fi fi } ############################################################ # Shutdown procedure. stop() { REPRUN=`ps ax | grep "${WD_AGENT_NAME}" | grep -v grep | wc -l` RETVAL=$? # Checks to see if the replicator is running. If it is, script will shut it down, otherwise a message will be printed. if [ ${REPRUN} -gt 0 ] then echo "Shutting down ${WD_AGENT_NAME}" start-stop-daemon --start --chuid ${WD_USER} --exec ${WD_SHUTDOWN} > /dev/null 2>&1 # Checks the last transaction and returns a value depending on success or failure. RETVAL=$? # Sleep to prevent errors in restarts. sleep 4 if [ ${RETVAL} -eq 0 ] then echo "Status Code: $RETVAL: The ${WD_AGENT_NAME} shutdown successfully." echo "------------------------------" fi if [ ${RETVAL} -eq 2 ] then echo "Status Code: $RETVAL: The ${WD_AGENT_NAME} failed to shut down successfully." status fi else echo "The replicator is currently not running." echo "------------------------------" fi } ############################################################ # Replicator status checker. status() { echo "------------------------------" # Checks for to make sure that the person running the script is root. if [ `id -u` = 0 ] then echo "[OK] This script is being run by root." else echo "[FAIL] This script is not being run by root. Please switch the user to root to avoid any potential errors." fi echo "------------------------------" echo "The current operating system is ${CURRENT_OS}." # Checks the system info see if Ubuntu is installed. if test -f "${OS_DEFINER}" then echo "[OK] The current operating system is valid to run this script." else echo "[FAIL] You are not running on this script on a valid operating system." fi echo "------------------------------" echo "Checking ${PERL_LOC} for Perl binary." # Checks to see if Perl is installed. if test -f "${PERL_LOC}/perl" then echo "[OK] Perl is installed on this machine." else echo "[FAIL] Could not find Perl on this machine." fi echo "------------------------------" echo "The Java environment variable is currently set to: ${JAVA_HOME}" # Tests for the JAVA_HOME variable. if test -f "${JAVA_HOME}/bin/java" then echo "[OK] The JAVA_HOME variable is set correctly." else echo "[FAIL] The JAVA_HOME variable is not set correctly." fi echo "------------------------------" echo "The user is currently set to: ${WD_USER}" # Tests to see if a valid user exists. id "${WD_USER}" >/dev/null 2>&1 RETVAL=$? if [ ${RETVAL} -eq 0 ] then echo "[OK] This is a valid user." else echo "[FAIL] This is not a valid user." fi echo "------------------------------" # Returns the base directory of the {WD_INSTALL_DIR}. BASE_INS_DIR=`basename ${WD_INSTALL_DIR}` echo "The install directory is currently set to: ${WD_INSTALL_DIR}" # Checks to see if the WD_INSTALL_DIR ends with "/svn-replicator" if `[ "${BASE_INS_DIR}" == "svn-replicator" ]` then echo "[OK] The replicator is installed to a suitable directory." else echo "[FAIL] Please rename the replicator install directory to /svn-replicator to avoid installation errors." fi echo "------------------------------" echo "The replicator binary is currently set to: ${WD_AGENT_BIN}" # Checks to see if the replicator binary exists in the specified directory. if test -f "${WD_AGENT_BIN}" then echo "[OK] The replicator script was found successfully." else echo "[FAIL] The replicator script was not found." fi echo "------------------------------" echo "The shutdown script is currently set to: ${WD_SHUTDOWN}" # Checks to see if the config file exists. if test -f "${WD_SHUTDOWN}" then echo "[OK] The shutdown script was found successfully." else echo "[FAIL] The shutdown script was not found." fi echo "------------------------------" echo "The config file is currently set to: ${WD_AGENT_CONF}" # Checks to see if the config file is readable. if test -r "${WD_AGENT_CONF}" then echo "[OK] The config file could be read." else echo "[FAIL] The config file could not be read." fi echo "------------------------------" # Checks to see if the replicator is running. if ps ax | grep -v grep | grep ${WD_AGENT_BIN} > /dev/null then # Returns the process ID of the replicator and checks the relevent file for the file descriptors. PROC_ID=`pidof -sx "${WD_AGENT_BIN}"` FDS_LOC=`grep -i "Max open files *${MAXFDS}" /proc/${PROC_ID}/limits` RETVAL=$? echo "The attempted max number of set file descriptors is ${MAXFDS}." # Checks the /proc/${PROC_ID}/limits file for the file descriptors. if [ ${RETVAL} -eq 0 ] then echo "[OK] The file descriptors were set successfully." echo "------------------------------" else echo "[FAIL] The file descriptors were not set successfully." echo "------------------------------" fi echo "[OK] The replicator is currently running." else echo "[FAIL] The replicator is currently not running." fi echo "------------------------------" } ############################################################ # Restart procedure. restart() { stop sleep 4 start } ############################################################ case "$1" in start) start ;; stop) stop ;; status) status ;; restart|reload) restart ;; *) echo $"Usage: $0 {start|stop|status|restart}" exit 1 esac
Copyright © 2010-2012 WANdisco
All Rights Reserved
This product is protected by copyright and distributed under
licenses restricting copying, distribution and decompilation.