Guest User

Untitled

a guest
May 22nd, 2018
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 6.80 KB | None | 0 0
  1. #!/bin/bash
  2. # Author: Pedro Martello (pedro.martello@pearson.com)
  3. #
  4. # Dev Project Control Script
  5.  
  6.  
  7. ## Usage:
  8. #
  9. usage () {
  10.  
  11. if [ "$1" = "package-only" ]; then
  12.     SVN_OPERATIONS="** Disabled **"
  13.     BUILD="** Disabled **"
  14.     FULLDEPLOY="** Disabled **"
  15. else
  16.     SVN_OPERATIONS="svnupdate|svnswitch"
  17.     BUILD="build"
  18.     FULLDEPLOY="fulldeploy"
  19. fi
  20.  
  21. echo -e "\
  22. Usage: `basename $0` operation
  23.  
  24. Operations
  25.  
  26. Initialization:  init
  27.  
  28. Tomcat Ctrl:    start|debug|stop|restart|status
  29. SVN Operations: ${SVN_OPERATIONS}
  30. Build:          ${BUILD}
  31. Install:        install|uninstall
  32. Build+Install:  ${FULLDEPLOY}
  33. Config Mgmt:    editconfig
  34. Log File Mgmt:  taillog|clearlog
  35. Fitnesse Ctrl:  fitstart|fitstop|fitrestart|fitstatus
  36. Hudson Build:   download_hudson_build|backup_hudson_build*
  37. SVN report:     svnreport
  38. Help:           help
  39.  
  40. IMPORTANT NOTE
  41.  
  42. The 'init' operation must be run executed before other commands
  43. can execute. You will get errors if you do not provide valid default
  44. values for init.
  45.  
  46. * backup_hudson_build is only meant to be run by Hudson, or from build machine
  47.  
  48. Options:
  49. --auto
  50.        Accept default values for configurations and project selections.
  51.        Probably a noob option only.
  52. --quiet
  53.        Suppress most output (not yet implemented)
  54. --log=[logfile]
  55.        Save output to file instead of showing on stdout (not yet implemented)
  56. --project=[project_tag]
  57.        Specify which global env properties file to select for an operation.            The format of the file must be global.[project_tag].env.
  58. "
  59. }
  60.  
  61.  
  62.  
  63. ##
  64. # We need to know our real directories to work our magic
  65. # with minimal sysadmin intervention
  66. #
  67. PROG=`readlink -f $0`
  68. PROG_DIR=`dirname $PROG`
  69.  
  70. # Sample directory structure layout and mappings to environment
  71. # variables:
  72. # ~/PRODUCTNAME (PRODUCT_BASE_DIR)
  73. # ~/PRODUCTNAME/env (BASE_DIR)
  74. # ~/PRODUCTNAME/env/scripts (SCRIPTS_DIR)
  75. # ~/PRODUCTNAME/env/configs (CONFIGS_DIR)
  76. #
  77. # Possible location for install and packages.
  78. # ~/PRODUCTNAME/install (PRODUCT_BASE_DIR/install)
  79. # ~/PRODUCTNAME/packages (PRODUCT_BASE_DIR/packages)
  80.  
  81. export SCRIPTS_DIR=$PROG_DIR
  82. export BASE_DIR=`dirname $PROG_DIR`
  83. export PRODUCT_BASE_DIR=`dirname $BASE_DIR`
  84.  
  85. if [[ -d $BASE_DIR/configs && -d $BASE_DIR/config ]]; then
  86.    echo -e "\nYou have two configuration directories; "
  87.    echo    "    $BASE_DIR/configs"
  88.    echo    "    and "
  89.    echo -e "    $BASE_DIR/config\n"
  90.    echo -e "I don't know which one to use.  Please remove one or the other.\n"
  91.    exit 1
  92. elif [ -d "$BASE_DIR/configs" ]; then
  93.    export CONFIG_DIR=$BASE_DIR/configs
  94. elif [ -d "$BASE_DIR/config" ]; then
  95.    export CONFIG_DIR=$BASE_DIR/config
  96. else
  97.    echo -e "\nYou don't seem to have a configuration directory in $BASE_DIR."
  98.    echo -e "Please install your product-specific configurations.\n"
  99.    exit 1
  100. fi
  101.  
  102. ##
  103. # Include lsb daemon control logging
  104. #
  105. . /lib/lsb/init-functions
  106.  
  107. log_status () {
  108.    if [ "$1" = "0" ]; then
  109.         log_success_msg $2
  110.     else
  111.         log_failure_msg $2
  112.         exit 1
  113.     fi
  114. }
  115.  
  116. ##
  117. # Parse Arguments
  118. for i in $@; do
  119.     i=`echo $i | sed -r "s/^--(.*)/\1/"`
  120.     case "$i" in
  121.     quiet)
  122.         AUTO=y
  123.         QUIET=y
  124.         ;;
  125.     auto)
  126.         AUTO=y
  127.         ;;
  128.     remote)
  129.         REMOTE=y
  130.         ;;
  131.     node=[0-9]* )
  132.         NODE=`echo $i | sed -r "s/.*=(.*)/\1/"`
  133.         ;;
  134.     project=* )
  135.         PROJECT_ENV=`echo $i | sed -r "s/.*=(.*)/\1/"`
  136.         if [ $PROJECT_ENV ]; then
  137.           PROJECT_ENV=".$PROJECT_ENV"
  138.         fi
  139.         ;;
  140.     *)
  141.         OPERATION=$i
  142.      esac
  143. done
  144.  
  145. export ARGS=$@ AUTO QUIET PROJECT_ENV REMOTE NODE OPERATION
  146.  
  147. ##
  148. # We special case the init operation since what follows from
  149. # here depends on it being run. In particular note that
  150. # project_init.sh will have to handle permissions itself since
  151. # the install owner is determined after it is run
  152. # (although we could obviously assume it from the basename of
  153. #  the basedir - though that makes it very env specific)
  154. #
  155. if [ "$OPERATION" = "init" ]; then
  156.     $SCRIPTS_DIR/project_init.sh $PROJECT_ENV
  157.     log_status $? "project initialized"
  158.     echo -e "\nyou can now run \`$0\` with more interesting operations" $QUIET
  159.     exit
  160. else
  161.     export GLOBAL_ENV=$CONFIG_DIR/global$PROJECT_ENV.env
  162.     if [ ! -f $GLOBAL_ENV ]; then
  163.         echo -e "\n'`basename $0` init' has not been run yet. Please execute it first.";
  164.         echo -e "Aborting $0...";
  165.         exit 1;
  166.     fi
  167.     source $GLOBAL_ENV
  168. fi
  169. ##
  170. # Read the Standard environment
  171. #
  172. source $SCRIPTS_DIR/project_common.sh
  173.  
  174. #
  175. # make sure we run commands run after here are always run using $SUDO
  176. #
  177. CUR_USER=`whoami`
  178. if [ "$CUR_USER" != "$project_os_owner" ]; then
  179.     SU_BIT=$SUDO
  180. fi
  181.  
  182. ## Process OPERATION input parameter
  183. #
  184. case "$OPERATION" in
  185. start)
  186.     do_command_per_node $SCRIPTS_DIR/project_start.sh
  187.     RETURN_CODE=$?
  188.     ;;
  189. debug)
  190.     do_command_per_node $SCRIPTS_DIR/project_debug.sh
  191.     RETURN_CODE=$?
  192.     ;;
  193. stop)
  194.     do_command_per_node $SCRIPTS_DIR/project_stop.sh
  195.     RETURN_CODE=$?
  196.     ;;
  197. restart)
  198.     do_command_per_node $SCRIPTS_DIR/project_stop.sh
  199.  
  200.     do_command_per_node $SCRIPTS_DIR/project_start.sh
  201.     RETURN_CODE=$?
  202.     ;;
  203. status)
  204.     do_command_per_node $SCRIPTS_DIR/project_status.sh
  205.     RETURN_CODE=$?
  206.     ;;
  207. fitstart)
  208.     do_command_per_node $SCRIPTS_DIR/project_fitnesse_start.sh
  209.     RETURN_CODE=$?
  210.     ;;
  211. fitstop)
  212.     do_command_per_node $SCRIPTS_DIR/project_fitnesse_stop.sh
  213.     RETURN_CODE=$?
  214.     ;;
  215. fitrestart)
  216.     do_command_per_node $SCRIPTS_DIR/project_fitnesse_stop.sh
  217.  
  218.     do_command_per_node $SCRIPTS_DIR/project_fitnesse_start.sh
  219.     RETURN_CODE=$?
  220.     ;;
  221. fitstatus)
  222.     do_command_per_node $SCRIPTS_DIR/project_fitnesse_status.sh
  223.     RETURN_CODE=$?
  224.     ;;
  225. editconfig)
  226.     do_command_per_node $SCRIPTS_DIR/project_edit_config.sh
  227.     RETURN_CODE=$?
  228.     ;;
  229. fulldeploy)
  230.     do_command_per_node $SCRIPTS_DIR/project_full_deploy.sh
  231.     RETURN_CODE=$?
  232.     ;;
  233. svnupdate)
  234.     do_command_per_node $SCRIPTS_DIR/project_svnupdate.sh
  235.     RETURN_CODE=$?
  236.     ;;
  237. svnswitch)
  238.     do_command_per_node $SCRIPTS_DIR/project_svn_switch.sh
  239.     RETURN_CODE=$?
  240.     ;;
  241. build)
  242.     do_command_per_node $SCRIPTS_DIR/project_build.sh
  243.     RETURN_CODE=$?
  244.     ;;
  245. install)
  246.     do_command_per_node $SCRIPTS_DIR/project_install.sh
  247.     RETURN_CODE=$?
  248.     ;;
  249. uninstall)
  250.     do_command_per_node $SCRIPTS_DIR/project_uninstall.sh
  251.     RETURN_CODE=$?
  252.     ;;
  253. taillog)
  254.     do_command_per_node $SCRIPTS_DIR/project_tail_log.sh
  255.     RETURN_CODE=$?
  256.     ;;
  257. clearlog)
  258.     do_command_per_node $SCRIPTS_DIR/project_clear_log.sh
  259.     RETURN_CODE=$?
  260.     ;;
  261. svnreport)
  262.     do_command_per_node $SCRIPTS_DIR/project_svn_revision_report.sh
  263.     RETURN_CODE=$?
  264.     ;;
  265. download_hudson_build)
  266.     do_command_per_node $SCRIPTS_DIR/project_hudson_download_build.sh $*
  267.     RETURN_CODE=$?
  268.     ;;
  269. backup_hudson_build)
  270.     # This should only be used by the hudson server
  271.     $SCRIPTS_DIR/project_hudson_backup_build.sh $*
  272.     RETURN_CODE=$?
  273.     ;;
  274. *)
  275.     usage $project_environment_type
  276. esac
  277.  
  278. if [ ! -z $OPERATION ]; then
  279.     log_status $RETURN_CODE "$0 $OPERATION"
  280. fi
Add Comment
Please, Sign In to add comment