Metro Scripts

From MeLibraries Wiki
Jump to: navigation, search

Useful scripts

Start Stop under Ubuntu

This script is used to start, stop and restart the metro server on my Ubuntu 12.04 metro server:

=== snip ===
#!/bin/bash
# Setup variables
EXEC=/usr/bin/jsvc
JAVA_HOME=/usr/lib/jvm/java-7-openjdk
CLASS_PATH="/home/ilsdev/metro/dist/lib/commons-daemon-1.0.15.jar":"/home/ilsdev/metro/dist/MeCard.jar"
WDPATH=/home/ilsdev/metro/logs
PID=$WDPATH/metro.pid
CLASS=mecard.MetroService
USER=ilsdev
LOG_OUT=$WDPATH/metro.out
LOG_ERR=$WDPATH/metro.err
# -c tells the service where the config files are located. Valid values are "" or "-c <path>".
#ARGS="-c ../"
ARGS="-c /home/ilsdev/metro/config"
do_exec()
{
   $EXEC -home "$JAVA_HOME" -cp $CLASS_PATH -user $USER -outfile $LOG_OUT -errfile $LOG_ERR -pidfile $PID $1 $CLASS $ARGS
}
case "$1" in
   start)
       do_exec
           ;;
   stop)
       do_exec "-stop"
           ;;
   restart)
       if [ -f "$PID" ]; then
           do_exec "-stop"
           do_exec
       else
           echo "service not running, will do nothing"
           exit 1
       fi
           ;;
    *)
        echo "usage: $0 {start|stop|restart}" >&2
        exit 3
        ;;
esac
=== snip ===


Automate alert and restart under Ubuntu

I use this script on my Ubuntu 12.04 metro server to let me know if the server has stopped, and if so, restart it:

=== snip ===
#!/usr/bin/env bash
addressees=anisbet@epl.ca
netstat -an | grep 2004 &> /dev/null
result=$?
if [ $result -gt 0 ]; then
        echo "[`date`] metro is down."
        echo "Metro server has stopped, restarting." | /usr/bin/mailx -s "Metro Server Outage"  $addressees
        /home/ilsdev/metro/service.sh start
fi
=== snip ===


Load a customer’s flat file on Unix Symphony system

=== snip ===
#!/usr/bin/bash
##################
#
# Loads customers manually.
# param: metro customer file.
#
#################
if [ $# -eq 0 ]
then
        echo "usage: $0 [flat_file]"
        exit
fi
if [ -e $1 ]
then
        echo "loading customer $1"
        cat $1 | loadflatuser -aA -bA -l"ADMIN|PCGUI-DISP" -mc -y"EPLMNA" -d
else
        echo "no such file."
fi
=== snip ===

Windows metro install script

=== snip ===
REM Installs (updates) Service (US) Metro.
c:\metro\windows\prunsrv.exe //US//Metro --Jvm=auto --Startup=auto --StartMode=jvm --Classpath=c:\metro\dist\MeCard.jar --StartClass=mecard.MetroService
--StartMethod=start ++StartParams=-c;c:\metro --StopMode=jvm --StopClass=mecard.MetroService --StopMethod=stop --LogPath=c:\metro\logs --LogLevel=Info
--LogPrefix=metro --StdOutput=c:\metro\logs\stdout.txt --StdError=c:\metro\logs\stderr.txt
=== snip ===

Windows metro startup script

=== snip ===
c:\metro\windows\prunsrv.exe //ES//Metro --Jvm=auto --Startup=auto --StartMode=jvm --Classpath=c:\metro\dist\MeCard.jar --StartClass=mecard.MetroService
--StartMethod=start ++StartParams=-c;c:\metro\ --StopMode=jvm --StopClass=mecard.MetroService --StopMethod=stop --LogPath=c:\metro\logs --LogLevel=Info
--LogPrefix=metro --StdOutput=c:\metro\logs\stdout.txt --StdError=c:\metro\logs\stderr.txt
=== snip ===

Windows metro shutdown script

=== snip ===
c:\metro\windows\prunsrv.exe //SS//Metro --Jvm=auto --Classpath=c:\metro\dist\MeCard.jar --StopMode=jvm --StopClass=mecard.MetroService --StopMethod=stop
=== snip ===