]> git.evergreen-ils.org Git - OpenSRF.git/blob - bin/osrf_ctl.sh.in
ff9d1ebc450de7f1986450a2f1ef0b00be20564e
[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 OPT_SIGNAL=""
24 OPT_SERVICE=""
25 OSRF_HOSTNAME=""
26
27 # ---------------------------------------------------------------------------
28 # Make sure we're running as the correct user
29 # ---------------------------------------------------------------------------
30 [ $(whoami) != 'opensrf' ] && echo 'Must run as user "opensrf"' && exit;
31
32
33 usage() {
34         cat << EOF
35
36 usage: $0 [OPTION]... -c <c_config> -a <action>
37
38 Mandatory parameters:
39   -a    action to perform
40
41 Optional parameters:";
42   -c    full path to C configuration file (opensrf_core.xml)
43   -d    store PID files in this directory
44   -l    accept 'localhost' as the fully-qualified domain name
45
46 Actions include:
47     stop_all
48     start_all
49     restart_all
50     smart_clear     - Clear all PID files that don't refer to a process 
51     clear_pid       - Clear all PID files
52
53 Examples:
54   $0 -a restart_all
55   $0 -l -c opensrf_core.xml -a restart_all
56
57 EOF
58 }
59
60 # ---------------------------------------------------------------------------
61 # Load the command line options and set the global vars
62 # ---------------------------------------------------------------------------
63 while getopts  "a:d:c:s:k:lh" flag; do
64         case $flag in   
65                 "a")            OPT_ACTION="$OPTARG";;
66                 "c")            OPT_CONFIG="$OPTARG";;
67                 "d")            OPT_PID_DIR="$OPTARG";;
68                 "s")            OPT_SERVICE="$OPTARG";;
69                 "k")            OPT_SIGNAL="$OPTARG";;
70                 "l")            export OSRF_HOSTNAME="localhost";;
71                 "h"|*)  usage;;
72         esac;
73 done
74
75 OSRF_CONFIG="@bindir@/osrf_config"
76 [ ! -f "$OSRF_CONFIG" ] && OSRF_CONFIG=`which osrf_config`
77
78 [ -z "$OPT_CONFIG" ] && OPT_CONFIG=`$OSRF_CONFIG --sysconfdir`/opensrf_core.xml;
79 if [ ! -r "$OPT_CONFIG" ]; then
80         echo "Please specify the location of the opensrf_core.xml file using the -c flag";
81         exit 1;
82 fi;
83 [ -z "$OPT_PID_DIR" ] && OPT_PID_DIR=`$OSRF_CONFIG --localstatedir`/run/opensrf;
84 [ -z "$OPT_ACTION" ] && usage;
85
86
87 start_all() {
88     opensrf-perl.pl --verbose --pid-dir $OPT_PID_DIR \
89         --config $OPT_CONFIG --start-all --settings-startup-pause 3
90 }
91
92 stop_all() {
93     opensrf-perl.pl --verbose --pid-dir $OPT_PID_DIR --config $OPT_CONFIG --stop-all
94 }
95
96 # ---------------------------------------------------------------------------
97 # Do the requested action
98 # ---------------------------------------------------------------------------
99 echo "$0 is deprecated.  Use opensrf-perl.pl instead"
100 case $OPT_ACTION in
101         "stop_all") stop_all;;
102         "start_all") start_all;;
103         "restart_all") stop_all; start_all;;
104         *) usage;;
105 esac;
106
107