]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/examples/oils_ctl.sh
Merge branch 'opac-tt-poc' of git+ssh://yeti.esilibrary.com/home/evergreen/evergreen...
[Evergreen.git] / Open-ILS / examples / oils_ctl.sh
1 #!/bin/bash
2
3 OPT_ACTION=""
4 OPT_SIP_CONFIG=""
5 OPT_PID_DIR=""
6 OPT_SIP_ERR_LOG="/dev/null";
7 SIP_DIR="/opt/SIPServer";
8
9 # ---------------------------------------------------------------------------
10 # Make sure we're running as the correct user
11 # ---------------------------------------------------------------------------
12 [ $(whoami) != 'opensrf' ] && echo 'Must run as user "opensrf"' && exit;
13
14
15 function usage {
16         echo "";
17         echo "usage: $0 -d <pid_dir> -s <sip_config> -a <action> -l <sip_err_log>";
18         echo "";
19         echo "Actions include:"
20         echo -e "\tstart_sip"
21         echo -e "\tstop_sip"
22         echo -e "\trestart_sip"
23         exit;
24 }
25
26
27 # ---------------------------------------------------------------------------
28 # Load the command line options and set the global vars
29 # ---------------------------------------------------------------------------
30 while getopts "a:d:s:l:" flag; do
31         case $flag in   
32                 "a")            OPT_ACTION="$OPTARG";;
33                 "s")            OPT_SIP_CONFIG="$OPTARG";;
34                 "d")            OPT_PID_DIR="$OPTARG";;
35                 "l")            OPT_SIP_ERR_LOG="$OPTARG";;
36                 "h"|*)  usage;;
37         esac;
38 done
39
40
41 [ -z "$OPT_PID_DIR" ] && OPT_PID_DIR=/tmp;
42 [ -z "$OPT_ACTION" ] && usage;
43
44 PID_SIP="$OPT_PID_DIR/oils_sip.pid";
45
46
47 # ---------------------------------------------------------------------------
48 # Utility code for checking the PID files
49 # ---------------------------------------------------------------------------
50 function do_action {
51
52         action="$1"; 
53         pidfile="$2";
54         item="$3"; 
55
56         if [ $action == "start" ]; then
57
58                 if [ -e $pidfile ]; then
59                         pid=$(cat $pidfile);
60                         echo "$item already started : $pid";
61                         return 0;
62                 fi;
63                 echo "Starting $item";
64         fi;
65
66         if [ $action == "stop" ]; then
67
68                 if [ ! -e $pidfile ]; then
69                         echo "$item not running";
70                         return 0;
71                 fi;
72
73                 pid=$(cat $pidfile);
74                 echo "Stopping $item : $pid";
75                 kill -s INT $pid;
76                 rm -f $pidfile;
77
78         fi;
79
80         return 0;
81 }
82
83
84 # ---------------------------------------------------------------------------
85 # Start / Stop functions
86 # ---------------------------------------------------------------------------
87
88
89 function start_sip {
90         do_action "start" $PID_SIP "OILS SIP Server";
91         DIR=$(pwd);
92         cd $SIP_DIR;
93     perl SIPServer.pm "$OPT_SIP_CONFIG" >> "$OPT_SIP_ERR_LOG" 2>&1 &
94         pid=$!;
95         cd $DIR;
96         echo $pid > $PID_SIP;
97         return 0;
98 }
99
100 function stop_sip {
101         do_action "stop" $PID_SIP "OILS SIP Server";
102         return 0;
103 }
104
105
106
107 # ---------------------------------------------------------------------------
108 # Do the requested action
109 # ---------------------------------------------------------------------------
110 case $OPT_ACTION in
111         "start_sip") start_sip;;
112         "stop_sip") stop_sip;;
113         "restart_sip") stop_sip; start_sip;;
114         *) usage;;
115 esac;
116
117
118