-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrc.mysqlrouter.diff
207 lines (207 loc) · 6.25 KB
/
rc.mysqlrouter.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# Patch rc.mysqlrouter start/stop script to make it working by emulating LSB
# Copyright (C) 2017 Georgi D. Sotirov <[email protected]>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# Visit SlackPack at https://sotirov-bg.net/slackpack/
#
33c33,175
< . /lib/lsb/init-functions
---
> # Emulate LSB (Linux Standard Base) commands and functions
> function log_daemon_msg() { echo -n $1; }
> function log_success_msg() { echo $1; }
> function log_failure_msg() { echo $1; }
> function log_end_msg() { if [ $1 -eq 0 ]; then echo " Done."; else echo " Filure."; fi }
> function log_warning_msg() { echo -e "\nWarning: $1"; }
> function start_stop_daemon() {
> local retval=0
> local START_STOP="" PID_FILE="" CMD_LINE="" PROC_NAME="" USER_NAME=""
> local RTRY_CNT=1 FG_TEST=0 FG_OKNODO=0 FG_QUIET=0 SH_BKG=1 FG_MAKE_PID=1
> local CMD_OPTS=""
> # see https://man7.org/linux/man-pages/man8/start-stop-daemon.8.html
> while [[ $# -gt 1 ]]; do
> case "$1" in
> # commands
> -S|--start ) START_STOP="start" ;;
> -K|--stop ) START_STOP="stop" ;;
> # matching options
> -p|--pidfile ) PID_FILE="$2" ; shift ;;
> -x|--exec ) CMD_LINE="$2" ; shift ;;
> -n|--name ) PROC_NAME="$2"; shift ;; # not implemented
> -u|--user ) USER_NAME="$2"; shift ;; # not implemented
> # generic options
> -R=*|--retry=* ) RTRY_CNT="${1#*=}"; ;; # not implemented
> -a|--startas ) CMD_LINE=$2 ; shift ;;
> -t|--test ) FG_TEST=1 ;;
> -o|--oknodo ) FG_OKNODO=1 ;;
> -q|--quiet ) FG_QUIET=1 ;;
> -c|--chuid ) USER_NAME="$2"; shift ;;
> -b|--background ) SH_BKG=1 ;;
> -m|--make-pidfile) FG_MAKE_PID=1 ;;
> -- ) shift; CMD_OPTS="$@"; break ;;
> # ignore and report all other options as errors
> *) log_failure_msg "Error: Unregognized or unimplemented option: '$1'" ;;
> esac
> shift
> done
>
> if [ "$START_STOP" == "start" ]; then
> status_of_proc -p $PID_FILE $CMD_LINE "$PROC_NAME" >/dev/null 2>&1
> # return if process already running
> if [ $? -eq 0 ]; then
> return 1;
> fi
> if [ "$USER_NAME" != "" ]; then
> CMD_OPTS="--user $USER_NAME $CMD_OPTS"
> fi
>
> if [ $FG_QUIET -ne 1 ]; then
> echo -n " ($CMD_LINE $CMD_OPTS) "
> fi
> if [ $FG_TEST -eq 0 ]; then
> $CMD_LINE $CMD_OPTS >/dev/null 2>&1 &
> sleep 1
> kill -0 $! >/dev/null 2>&1
> retval=$?
> if [ $retval -eq 0 ]; then
> echo $! > $PID_FILE
> fi
> else
> if [ $FG_OKNODO -eq 1 ]; then
> retval=0
> else
> retval=1
> fi
> fi
> elif [ "$START_STOP" == "stop" ]; then
> status_of_proc -p $PID_FILE $CMD_LINE "$PROC_NAME" >/dev/null 2>&1
> # return if process is not running
> if [ $? -ne 0 ]; then
> return 1;
> fi
> if [ -e $PID_FILE ]; then
> if [ $FG_QUIET != 1 ]; then
> echo -n " (kill $(cat $PID_FILE)) "
> fi
> kill `cat $PID_FILE` >/dev/null 2>&1
> retval=$?
> else
> killall $PROC_NAME >/dev/null 2>&1
> retval=$?
> fi
> rm -f $PID_FILE
> else
> log_failure_msg "Error: No command given!"
> fi
>
> if [ $retval -ne 0 ]; then
> retval=2
> fi
>
> return $retval
> }
> function status_of_proc() {
> # see https://serverfault.com/questions/643006/what-is-status-of-proc-and-how-do-i-call-it
> local pidfile daemon name status OPTIND;
> pidfile=;
> OPTIND=1;
>
> while getopts p: opt; do
> case "$opt" in
> p) pidfile="$OPTARG" ;;
> esac
> done
>
> shift $(($OPTIND - 1));
>
> daemon="$1";
> name="$2";
> status="0";
>
> # see https://www.unix.com/man-page/suse/8/pidofproc/
> #pidofproc $pidfile $daemon > /dev/null || status="$?";
> if [ -e $pidfile ]; then
> if [ -r $pidfile ]; then
> proc_pid=$(cat $pidfile)
> kill -0 $proc_pid >/dev/null 2>&1
> status=$?
> else
> status="4"
> fi
> else
> proc_pid=$(pidof `basename $daemon`)
> if [ "$proc_pid" != "" ]; then
> status="0"
> else
> status="1"
> fi
> fi
>
> if [ "$status" = 0 ]; then
> log_success_msg "$name is running ($proc_pid).";
> return 0;
> else
> if [ "$status" = 4 ]; then
> log_failure_msg "could not access PID file '$pidfile' for $name";
> return $status;
> else
> log_failure_msg "$name is not running.";
> return $status;
> fi;
> fi
> }
37a180
> PROCNAME=mysqlrouter
49c192
< log_daemon_msg "Starting MySQL Router"
---
> log_daemon_msg "Starting ${NAME}:"
58c201
< install -d -m 0750 -o mysqlrouter -g adm ${RUNTIMEDIR}
---
> install -d -m 0750 -o mysql -g mysql ${RUNTIMEDIR}
63c206
< install -d -m 0750 -o mysqlrouter -g adm ${DATADIR}
---
> install -d -m 0750 -o mysql -g mysql ${DATADIR}
68c211
< install -d -m 0750 -o mysqlrouter -g adm ${LOGDIR}
---
> install -d -m 0750 -o mysql -g mysql ${LOGDIR}
71c214
< install /dev/null -m 0640 -o mysqlrouter -g adm ${LOGFILE}
---
> install /dev/null -m 0640 -o mysql -g mysql ${LOGFILE}
75c218
< start-stop-daemon --start \
---
> start_stop_daemon --start \
81c224
< --chuid mysqlrouter \
---
> --chuid mysql \
100c243
< log_daemon_msg "Stopping $NAME"
---
> log_daemon_msg "Stopping $NAME:"
107c250
< start-stop-daemon --stop \
---
> start_stop_daemon --stop \
149c292
< >2& echo "Usage: /etc/init.d/mysqlrouter {start|stop|status|restart|force-reload}"
---
> >2& echo "Usage: $0 {start|stop|status|restart|force-reload}"