1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | #!/bin/bash # # Netcetera Demo Merchant Simulator control script. usage() { cat <<EOF Usage: $0 <options> < command > This script allows to control Netcetera Demo Merchant Simulator instance (i.e. start /stop them). OPTIONS: -c The configuration home directory -j The Java options to set (optional). See examples below... -h Show this message COMMANDS: start Starts an 3DS Server node stop Stops an 3DS Server node Java option examples: Set the maximum heap space for the Netcetera Demo Merchant Simulator to 1024 MB and the maximum PermGen space to 256 MB: -Xmx1024m -XX:MaxPermSize=256m Enable JSSE (Java Secure Socket Extension) debug output (Check http: //docs .oracle.com /javase/7/docs/technotes/guides/security/jsse/JSSERefGuide .html #Debug for details): -Djavax.net.debug=all EOF } # Set defaults for command line arguments NDM_SIMULATOR_CONFIG_HOME= "" JAVA_OPTS= "" # Read command line arguments while getopts "n:c:j:h" OPTION do case $OPTION in c) NDM_SIMULATOR_CONFIG_HOME=$OPTARG ;; j) JAVA_OPTS=$OPTARG ;; h) usage exit ;; n) # -n is an ignored option because the Rundeck start/stop jobs are common to the Netcetera NDM Simulator and 3DS Server apps echo "Ignored option -n." ;; \?) echo "Unknown option: -$OPTARG" >&2 exit 1 ;; :) echo "Missing option argument for -$OPTARG" >&2 exit 1 ;; *) echo "Unimplemented option: -$OPTARG" >&2 exit 1 ;; esac done shift $(($OPTIND-1)) # Set variables NDM_SIMULATOR_HOME=$( cd $( dirname "$0" )/..; pwd ) NDM_SIMULATOR_JAR= "$NDM_SIMULATOR_HOME/lib/ndm-simulator.jar" PID_FILE= "$NDM_SIMULATOR_HOME/pid/node.pid" CURRENT_DATE=` date + "%Y-%m-%d" ` CATALINA_OUT= "$NDM_SIMULATOR_HOME/out/catalina.out" # Check files and directories assert_file_exists_and_is_readable() { if [[ ! -f $1 || ! -r $1 ]]; then echo "File $1 doesn't exist or is not readable" >&2 exit 1 fi } assert_directory_exists_and_is_writable() { if [[ ! -d $1 || ! -w $1 ]]; then echo "Directory $1 doesn't exist or is not writable" >&2 exit 1 fi } create_directory_if_not_exists() { if [[ ! -d $1 ]]; then mkdir $1 fi } assert_file_exists_and_is_readable $NDM_SIMULATOR_JAR assert_directory_exists_and_is_writable "$NDM_SIMULATOR_HOME" create_directory_if_not_exists "$NDM_SIMULATOR_HOME/pid/" create_directory_if_not_exists "$NDM_SIMULATOR_HOME/out/" # Execute command COMMAND=$1 case $COMMAND in start) if [[ -e $PID_FILE ]]; then PID=$(<$PID_FILE) CURRENT_PID=` ps aux | awk '{print $2}' | grep "^$PID$" ` if [[ "$CURRENT_PID" - eq "$PID" ]]; then echo "Netcetera Demo Merchant Simulator node seems to be already started (there is a active PID for this node)" exit 0 else rm $PID_FILE fi fi java $JAVA_OPTS -jar $NDM_SIMULATOR_JAR --spring.config.name=application,cardholder-numbers-simulated-message-types,simulated-card-range-data,simulated-otp-responses,threeds-one-acs-simulator-config,threeds-one-simulated-otp-responses,threeds-one-ds-simulator-config,upop-simulator-config --spring.config.additional-location=$NDM_SIMULATOR_CONFIG_HOME > $CATALINA_OUT 2>&1 & echo $! > $PID_FILE ;; stop) if [[ ! -e $PID_FILE ]]; then echo "Netcetera Demo Merchant Simulator node seems not to be started (there is no PID file for this node)" exit 0 fi PID=$(<$PID_FILE) kill $PID rm $PID_FILE ;; *) usage exit 1 ;; esac |