]> git.evergreen-ils.org Git - OpenSRF.git/blob - bin/osrf_ctl.sh.in
LP#1224647: remove two invalid tests
[OpenSRF.git] / bin / osrf_ctl.sh.in
1 #!/bin/sh
2 #
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 # GNU General Public License for more details.
12  
13 # Strictness to avoid folly
14 set -e
15 set -u
16
17 prefix=@prefix@
18 exec_prefix=@exec_prefix@
19
20 OPT_ACTION=""
21 OPT_CONFIG=""
22 OPT_PID_DIR=""
23 OSRF_HOSTNAME=""
24
25 # ---------------------------------------------------------------------------
26 # Make sure we're running as the correct user
27 # ---------------------------------------------------------------------------
28 [ $(whoami) != 'opensrf' ] && echo 'Must run as user "opensrf"' && exit;
29
30
31 usage() {
32         cat << EOF
33
34 usage: $0 [OPTION]... -c <c_config> -a <action>
35
36 Mandatory parameters:
37   -a    action to perform
38
39 Optional parameters:";
40   -c    full path to C configuration file (opensrf_core.xml)
41   -d    store PID files in this directory
42   -l    accept 'localhost' as the fully-qualified domain name
43
44 Actions include:
45     stop_all
46     start_all
47     restart_all
48
49 Examples:
50   $0 -a restart_all
51   $0 -l -c opensrf_core.xml -a restart_all
52
53 EOF
54 }
55
56 # ---------------------------------------------------------------------------
57 # Load the command line options and set the global vars
58 # ---------------------------------------------------------------------------
59 while getopts  "a:d:c:s:k:lh" flag; do
60         case $flag in   
61                 "a")            OPT_ACTION="$OPTARG";;
62                 "c")            OPT_CONFIG="$OPTARG";;
63                 "d")            OPT_PID_DIR="$OPTARG";;
64                 "l")            export OSRF_HOSTNAME="localhost";;
65                 "h"|*)  usage;;
66         esac;
67 done
68
69 OSRF_CONFIG="@bindir@/osrf_config"
70 [ ! -f "$OSRF_CONFIG" ] && OSRF_CONFIG=`which osrf_config`
71
72 [ -z "$OPT_CONFIG" ] && OPT_CONFIG=`$OSRF_CONFIG --sysconfdir`/opensrf_core.xml;
73 if [ ! -r "$OPT_CONFIG" ]; then
74         echo "Please specify the location of the opensrf_core.xml file using the -c flag";
75         exit 1;
76 fi;
77 [ -z "$OPT_PID_DIR" ] && OPT_PID_DIR=`$OSRF_CONFIG --localstatedir`/run/opensrf;
78 [ -z "$OPT_ACTION" ] && usage;
79
80
81 start_all() {
82     opensrf-perl.pl --pid-dir $OPT_PID_DIR \
83         --config $OPT_CONFIG --start-all --settings-startup-pause 3
84 }
85
86 stop_all() {
87     opensrf-perl.pl --pid-dir $OPT_PID_DIR --config $OPT_CONFIG --stop-all
88 }
89
90 # ---------------------------------------------------------------------------
91 # Do the requested action
92 # ---------------------------------------------------------------------------
93 echo "$0 is deprecated.  Use osrf_control instead"
94
95 case $OPT_ACTION in
96         "stop_all") stop_all;;
97         "start_all") start_all;;
98         "restart_all") stop_all; start_all;;
99         *) usage;;
100 esac;
101
102