Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Author: Pedro Martello (pedro.martello@pearson.com)
- #
- # Dev Project Control Script
- ## Usage:
- #
- usage () {
- if [ "$1" = "package-only" ]; then
- SVN_OPERATIONS="** Disabled **"
- BUILD="** Disabled **"
- FULLDEPLOY="** Disabled **"
- else
- SVN_OPERATIONS="svnupdate|svnswitch"
- BUILD="build"
- FULLDEPLOY="fulldeploy"
- fi
- echo -e "\
- Usage: `basename $0` operation
- Operations
- Initialization: init
- Tomcat Ctrl: start|debug|stop|restart|status
- SVN Operations: ${SVN_OPERATIONS}
- Build: ${BUILD}
- Install: install|uninstall
- Build+Install: ${FULLDEPLOY}
- Config Mgmt: editconfig
- Log File Mgmt: taillog|clearlog
- Fitnesse Ctrl: fitstart|fitstop|fitrestart|fitstatus
- Hudson Build: download_hudson_build|backup_hudson_build*
- SVN report: svnreport
- Help: help
- IMPORTANT NOTE
- The 'init' operation must be run executed before other commands
- can execute. You will get errors if you do not provide valid default
- values for init.
- * backup_hudson_build is only meant to be run by Hudson, or from build machine
- Options:
- --auto
- Accept default values for configurations and project selections.
- Probably a noob option only.
- --quiet
- Suppress most output (not yet implemented)
- --log=[logfile]
- Save output to file instead of showing on stdout (not yet implemented)
- --project=[project_tag]
- Specify which global env properties file to select for an operation. The format of the file must be global.[project_tag].env.
- "
- }
- ##
- # We need to know our real directories to work our magic
- # with minimal sysadmin intervention
- #
- PROG=`readlink -f $0`
- PROG_DIR=`dirname $PROG`
- # Sample directory structure layout and mappings to environment
- # variables:
- # ~/PRODUCTNAME (PRODUCT_BASE_DIR)
- # ~/PRODUCTNAME/env (BASE_DIR)
- # ~/PRODUCTNAME/env/scripts (SCRIPTS_DIR)
- # ~/PRODUCTNAME/env/configs (CONFIGS_DIR)
- #
- # Possible location for install and packages.
- # ~/PRODUCTNAME/install (PRODUCT_BASE_DIR/install)
- # ~/PRODUCTNAME/packages (PRODUCT_BASE_DIR/packages)
- export SCRIPTS_DIR=$PROG_DIR
- export BASE_DIR=`dirname $PROG_DIR`
- export PRODUCT_BASE_DIR=`dirname $BASE_DIR`
- if [[ -d $BASE_DIR/configs && -d $BASE_DIR/config ]]; then
- echo -e "\nYou have two configuration directories; "
- echo " $BASE_DIR/configs"
- echo " and "
- echo -e " $BASE_DIR/config\n"
- echo -e "I don't know which one to use. Please remove one or the other.\n"
- exit 1
- elif [ -d "$BASE_DIR/configs" ]; then
- export CONFIG_DIR=$BASE_DIR/configs
- elif [ -d "$BASE_DIR/config" ]; then
- export CONFIG_DIR=$BASE_DIR/config
- else
- echo -e "\nYou don't seem to have a configuration directory in $BASE_DIR."
- echo -e "Please install your product-specific configurations.\n"
- exit 1
- fi
- ##
- # Include lsb daemon control logging
- #
- . /lib/lsb/init-functions
- log_status () {
- if [ "$1" = "0" ]; then
- log_success_msg $2
- else
- log_failure_msg $2
- exit 1
- fi
- }
- ##
- # Parse Arguments
- for i in $@; do
- i=`echo $i | sed -r "s/^--(.*)/\1/"`
- case "$i" in
- quiet)
- AUTO=y
- QUIET=y
- ;;
- auto)
- AUTO=y
- ;;
- remote)
- REMOTE=y
- ;;
- node=[0-9]* )
- NODE=`echo $i | sed -r "s/.*=(.*)/\1/"`
- ;;
- project=* )
- PROJECT_ENV=`echo $i | sed -r "s/.*=(.*)/\1/"`
- if [ $PROJECT_ENV ]; then
- PROJECT_ENV=".$PROJECT_ENV"
- fi
- ;;
- *)
- OPERATION=$i
- esac
- done
- export ARGS=$@ AUTO QUIET PROJECT_ENV REMOTE NODE OPERATION
- ##
- # We special case the init operation since what follows from
- # here depends on it being run. In particular note that
- # project_init.sh will have to handle permissions itself since
- # the install owner is determined after it is run
- # (although we could obviously assume it from the basename of
- # the basedir - though that makes it very env specific)
- #
- if [ "$OPERATION" = "init" ]; then
- $SCRIPTS_DIR/project_init.sh $PROJECT_ENV
- log_status $? "project initialized"
- echo -e "\nyou can now run \`$0\` with more interesting operations" $QUIET
- exit
- else
- export GLOBAL_ENV=$CONFIG_DIR/global$PROJECT_ENV.env
- if [ ! -f $GLOBAL_ENV ]; then
- echo -e "\n'`basename $0` init' has not been run yet. Please execute it first.";
- echo -e "Aborting $0...";
- exit 1;
- fi
- source $GLOBAL_ENV
- fi
- ##
- # Read the Standard environment
- #
- source $SCRIPTS_DIR/project_common.sh
- #
- # make sure we run commands run after here are always run using $SUDO
- #
- CUR_USER=`whoami`
- if [ "$CUR_USER" != "$project_os_owner" ]; then
- SU_BIT=$SUDO
- fi
- ## Process OPERATION input parameter
- #
- case "$OPERATION" in
- start)
- do_command_per_node $SCRIPTS_DIR/project_start.sh
- RETURN_CODE=$?
- ;;
- debug)
- do_command_per_node $SCRIPTS_DIR/project_debug.sh
- RETURN_CODE=$?
- ;;
- stop)
- do_command_per_node $SCRIPTS_DIR/project_stop.sh
- RETURN_CODE=$?
- ;;
- restart)
- do_command_per_node $SCRIPTS_DIR/project_stop.sh
- do_command_per_node $SCRIPTS_DIR/project_start.sh
- RETURN_CODE=$?
- ;;
- status)
- do_command_per_node $SCRIPTS_DIR/project_status.sh
- RETURN_CODE=$?
- ;;
- fitstart)
- do_command_per_node $SCRIPTS_DIR/project_fitnesse_start.sh
- RETURN_CODE=$?
- ;;
- fitstop)
- do_command_per_node $SCRIPTS_DIR/project_fitnesse_stop.sh
- RETURN_CODE=$?
- ;;
- fitrestart)
- do_command_per_node $SCRIPTS_DIR/project_fitnesse_stop.sh
- do_command_per_node $SCRIPTS_DIR/project_fitnesse_start.sh
- RETURN_CODE=$?
- ;;
- fitstatus)
- do_command_per_node $SCRIPTS_DIR/project_fitnesse_status.sh
- RETURN_CODE=$?
- ;;
- editconfig)
- do_command_per_node $SCRIPTS_DIR/project_edit_config.sh
- RETURN_CODE=$?
- ;;
- fulldeploy)
- do_command_per_node $SCRIPTS_DIR/project_full_deploy.sh
- RETURN_CODE=$?
- ;;
- svnupdate)
- do_command_per_node $SCRIPTS_DIR/project_svnupdate.sh
- RETURN_CODE=$?
- ;;
- svnswitch)
- do_command_per_node $SCRIPTS_DIR/project_svn_switch.sh
- RETURN_CODE=$?
- ;;
- build)
- do_command_per_node $SCRIPTS_DIR/project_build.sh
- RETURN_CODE=$?
- ;;
- install)
- do_command_per_node $SCRIPTS_DIR/project_install.sh
- RETURN_CODE=$?
- ;;
- uninstall)
- do_command_per_node $SCRIPTS_DIR/project_uninstall.sh
- RETURN_CODE=$?
- ;;
- taillog)
- do_command_per_node $SCRIPTS_DIR/project_tail_log.sh
- RETURN_CODE=$?
- ;;
- clearlog)
- do_command_per_node $SCRIPTS_DIR/project_clear_log.sh
- RETURN_CODE=$?
- ;;
- svnreport)
- do_command_per_node $SCRIPTS_DIR/project_svn_revision_report.sh
- RETURN_CODE=$?
- ;;
- download_hudson_build)
- do_command_per_node $SCRIPTS_DIR/project_hudson_download_build.sh $*
- RETURN_CODE=$?
- ;;
- backup_hudson_build)
- # This should only be used by the hudson server
- $SCRIPTS_DIR/project_hudson_backup_build.sh $*
- RETURN_CODE=$?
- ;;
- *)
- usage $project_environment_type
- esac
- if [ ! -z $OPERATION ]; then
- log_status $RETURN_CODE "$0 $OPERATION"
- fi
Add Comment
Please, Sign In to add comment