]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/examples/oils_ctl.sh
LP1948035 Angular 12 updates
[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 running as the correct user
21 # ---------------------------------------------------------------------------
22 [ $(whoami) != 'opensrf' ] && echo 'Must run as user "opensrf"' && exit;
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 0;
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 0;
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         do_action "start" $PID_SIP "OILS SIP Server";
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         return 0;
116 }
117
118 function stop_sip {
119         do_action "stop" $PID_SIP "OILS SIP Server";
120         return 0;
121 }
122
123 function start_z3950 {
124         do_action "start" $PID_Z3950 "OILS Z39.50 Server";
125         simple2zoom -c $OPT_Z3950_CONFIG -- -f $OPT_YAZ_CONFIG >> "$Z3950_LOG" 2>&1 &
126         pid=$!;
127         echo $pid > $PID_Z3950;
128         return 0;
129 }
130
131 function stop_z3950 {
132         do_action "stop" $PID_Z3950 "OILS Z39.50 Server";
133         return 0;
134 }
135
136
137 # ---------------------------------------------------------------------------
138 # Do the requested action
139 # ---------------------------------------------------------------------------
140 case $OPT_ACTION in
141         "start_sip") start_sip;;
142         "stop_sip") stop_sip;;
143         "restart_sip") stop_sip; start_sip;;
144         "start_z3950") start_z3950;;
145         "stop_z3950") stop_z3950;;
146         "restart_z3950") stop_z3950; start_z3950;;
147         "start_all") start_sip; start_z3950;;
148         "stop_all") stop_sip; stop_z3950;;
149         "restart_all") stop_sip; stop_z3950; start_sip; start_z3950;;
150         *) usage;;
151 esac;
152
153
154