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