]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/examples/oils_ctl.sh
LP2045292 Color contrast for AngularJS patron bills
[working/Evergreen.git] / Open-ILS / examples / oils_ctl.sh
1 #!/bin/bash
2
3 OPT_ACTION=""
4 OPT_SIP_CONFIG="SYSCONFDIR/oils_sip.xml"
5 OPT_PID_DIR="LOCALSTATEDIR/run"
6 OPT_SIP_ERR_LOG="LOCALSTATEDIR/log/oils_sip.log";
7 OPT_Z3950_CONFIG="SYSCONFDIR/oils_z3950.xml"
8 OPT_YAZ_CONFIG="SYSCONFDIR/oils_yaz.xml"
9 Z3950_LOG="LOCALSTATEDIR/log/oils_z3950.log"
10 SIP_DIR="/opt/SIPServer";
11 if [ -z "${PERL5LIB}" ]; then
12     export PERL5LIB="${SIP_DIR}"
13 else
14     if ! grep -q "${SIP_DIR}" <<< "${PERL5LIB}"; then
15         PERL5LIB="${PERL5LIB}:${SIP_DIR}"
16     fi
17 fi
18
19 # ---------------------------------------------------------------------------
20 # Make sure we're not running as the root user
21 # ---------------------------------------------------------------------------
22 [ `id -u` -eq 0 ] && echo 'Not to be run as root' && exit 1;
23
24
25 function usage {
26         echo "";
27         echo "usage: $0 -d <pid_dir> -s <sip_config> -z <z3950_config> -y <yaz_config> -a <action> -l <sip_err_log>";
28         echo "";
29         echo "Actions include:"
30         echo -e "\tstart_sip"
31         echo -e "\tstop_sip"
32         echo -e "\trestart_sip"
33         echo -e "\tstart_z3950"
34         echo -e "\tstop_z3950"
35         echo -e "\trestart_z3950"
36         echo -e "\tstart_all"
37         echo -e "\tstop_all"
38         echo -e "\trestart_all"
39         exit;
40 }
41
42
43 # ---------------------------------------------------------------------------
44 # Load the command line options and set the global vars
45 # ---------------------------------------------------------------------------
46 while getopts "a:d:s:l:y:z:" flag; do
47         case $flag in   
48                 "a")            OPT_ACTION="$OPTARG";;
49                 "s")            OPT_SIP_CONFIG="$OPTARG";;
50                 "d")            OPT_PID_DIR="$OPTARG";;
51                 "l")            OPT_SIP_ERR_LOG="$OPTARG";;
52                 "z")            OPT_Z3950_CONFIG="$OPTARG";;
53                 "y")            OPT_YAZ_CONFIG="$OPTARG";;
54                 "h"|*)  usage;;
55         esac;
56 done
57
58
59 [ -z "$OPT_PID_DIR" ] && OPT_PID_DIR=/tmp;
60 [ -z "$OPT_ACTION" ] && usage;
61
62 PID_SIP="$OPT_PID_DIR/oils_sip.pid";
63 PID_Z3950="$OPT_PID_DIR/oils_z3950.pid";
64
65 # ---------------------------------------------------------------------------
66 # Utility code for checking the PID files
67 # ---------------------------------------------------------------------------
68 function do_action {
69
70         action="$1"; 
71         pidfile="$2";
72         item="$3"; 
73
74         if [ $action == "start" ]; then
75
76                 if [ -e $pidfile ]; then
77                         pid=$(cat $pidfile);
78                         echo "$item already started : $pid";
79                         return 1;
80                 fi;
81                 echo "Starting $item";
82         fi;
83
84         if [ $action == "stop" ]; then
85
86                 if [ ! -e $pidfile ]; then
87                         echo "$item not running";
88                         return 1;
89                 fi;
90
91                 pid=$(cat $pidfile);
92                 echo "Stopping $item : $pid";
93                 kill -s TERM $pid;
94                 rm -f $pidfile;
95
96         fi;
97
98         return 0;
99 }
100
101
102 # ---------------------------------------------------------------------------
103 # Start / Stop functions
104 # ---------------------------------------------------------------------------
105
106
107 function start_sip {
108         if do_action "start" $PID_SIP "OILS SIP Server"; then
109                 DIR=$(pwd);
110                 cd $SIP_DIR;
111                 perl SIPServer.pm "$OPT_SIP_CONFIG" >> "$OPT_SIP_ERR_LOG" 2>&1 &
112                 pid=$!;
113                 cd $DIR;
114                 echo $pid > $PID_SIP;
115         fi
116         return 0;
117 }
118
119 function stop_sip {
120         do_action "stop" $PID_SIP "OILS SIP Server";
121         return 0;
122 }
123
124 function start_z3950 {
125         if do_action "start" $PID_Z3950 "OILS Z39.50 Server"; then
126                 simple2zoom -c $OPT_Z3950_CONFIG -- -f $OPT_YAZ_CONFIG >> "$Z3950_LOG" 2>&1 &
127                 pid=$!;
128                 echo $pid > $PID_Z3950;
129         fi
130         return 0;
131 }
132
133 function stop_z3950 {
134         do_action "stop" $PID_Z3950 "OILS Z39.50 Server";
135         return 0;
136 }
137
138
139 # ---------------------------------------------------------------------------
140 # Do the requested action
141 # ---------------------------------------------------------------------------
142 case $OPT_ACTION in
143         "start_sip") start_sip;;
144         "stop_sip") stop_sip;;
145         "restart_sip") stop_sip; start_sip;;
146         "start_z3950") start_z3950;;
147         "stop_z3950") stop_z3950;;
148         "restart_z3950") stop_z3950; start_z3950;;
149         "start_all") start_sip; start_z3950;;
150         "stop_all") stop_sip; stop_z3950;;
151         "restart_all") stop_sip; stop_z3950; start_sip; start_z3950;;
152         *) usage;;
153 esac;
154
155
156