Lines 1-8
Link Here
|
1 |
#!/sbin/openrc-run |
1 |
#!/sbin/openrc-run |
2 |
# Copyright 1999-2016 Gentoo Foundation |
2 |
# Copyright 1999-2017 Gentoo Foundation |
3 |
# Distributed under the terms of the GNU General Public License v2 |
3 |
# Distributed under the terms of the GNU General Public License v2 |
4 |
|
4 |
|
5 |
extra_commands="checkconfig" |
5 |
extra_commands="checkconfig bootstrap_galera" |
6 |
|
6 |
|
7 |
depend() { |
7 |
depend() { |
8 |
use net.lo |
8 |
use net.lo |
Lines 11-18
Link Here
|
11 |
} |
11 |
} |
12 |
|
12 |
|
13 |
get_config() { |
13 |
get_config() { |
14 |
my_print_defaults --config-file="$1" mysqld | |
14 |
my_print_defaults --defaults-file="$1" --mysqld | |
15 |
sed -n -e "s/^--$2=//p" |
15 |
sed -n -e "s/^--$2=?//p" |
16 |
} |
16 |
} |
17 |
|
17 |
|
18 |
mysql_svcname() { |
18 |
mysql_svcname() { |
Lines 24-29
Link Here
|
24 |
echo "${SVCNAME}${ebextra}" |
24 |
echo "${SVCNAME}${ebextra}" |
25 |
} |
25 |
} |
26 |
|
26 |
|
|
|
27 |
stringContain() { [ -z "${2##*$1*}" ] && [ -z "$1" -o -n "$2" ]; } |
28 |
|
29 |
bootstrap_galera() { |
30 |
if ! service_stopped ; then |
31 |
eerror "The server cannot be running to perform this action" |
32 |
return 1 |
33 |
fi |
34 |
MY_ARGS="--wsrep-new-cluster ${MY_ARGS}" |
35 |
mark_service_starting |
36 |
if start ; then |
37 |
mark_service_started |
38 |
return 0 |
39 |
else |
40 |
mark_service_stopped |
41 |
return 1 |
42 |
fi |
43 |
} |
44 |
|
27 |
start() { |
45 |
start() { |
28 |
# Check for old conf.d variables that mean migration was not yet done. |
46 |
# Check for old conf.d variables that mean migration was not yet done. |
29 |
set | egrep -sq '^(mysql_slot_|MYSQL_BLOG_PID_FILE|STOPTIMEOUT)' |
47 |
set | egrep -sq '^(mysql_slot_|MYSQL_BLOG_PID_FILE|STOPTIMEOUT)' |
Lines 38-44
Link Here
|
38 |
fi |
56 |
fi |
39 |
|
57 |
|
40 |
# Check the config or die |
58 |
# Check the config or die |
41 |
checkconfig || return 1 |
59 |
if [ ${RC_CMD} != "restart" ] ; then |
|
|
60 |
checkconfig || return 1 |
61 |
fi |
42 |
|
62 |
|
43 |
# Now we can startup |
63 |
# Now we can startup |
44 |
ebegin "Starting $(mysql_svcname)" |
64 |
ebegin "Starting $(mysql_svcname)" |
Lines 52-84
Link Here
|
52 |
|
72 |
|
53 |
# tail -n1 is critical as these we only want the last instance of the option |
73 |
# tail -n1 is critical as these we only want the last instance of the option |
54 |
local basedir=$(get_config "${MY_CNF}" basedir | tail -n1) |
74 |
local basedir=$(get_config "${MY_CNF}" basedir | tail -n1) |
55 |
local datadir=$(get_config "${MY_CNF}" datadir | tail -n1) |
|
|
56 |
local pidfile=$(get_config "${MY_CNF}" pid-file | tail -n1) |
75 |
local pidfile=$(get_config "${MY_CNF}" pid-file | tail -n1) |
57 |
local socket=$(get_config "${MY_CNF}" socket | tail -n1) |
76 |
local socket=$(get_config "${MY_CNF}" socket | tail -n1) |
58 |
local chroot=$(get_config "${MY_CNF}" chroot | tail -n1) |
77 |
local chroot=$(get_config "${MY_CNF}" chroot | tail -n1) |
|
|
78 |
local wsrep=$(get_config "${MY_CNF}" wsrep[_-]on | tail -n1) |
79 |
local wsrep-new=$(get_config "${MY_CNF}" wsrep-new-cluster | tail -n1) |
59 |
|
80 |
|
60 |
if [ -n "${chroot}" ] ; then |
81 |
if [ -n "${chroot}" ] ; then |
61 |
socket="${chroot}/${socket}" |
82 |
socket="${chroot}/${socket}" |
62 |
pidfile="${chroot}/${pidfile}" |
83 |
pidfile="${chroot}/${pidfile}" |
63 |
fi |
84 |
fi |
64 |
|
85 |
|
65 |
if [ ! -d "${datadir}" ] ; then |
86 |
# Galera: Only check datadir if not starting a new cluster and galera is enabled |
66 |
eerror "MySQL datadir \`${datadir}' is empty or invalid" |
87 |
# wsrep_on is empty or wsrep-new-cluster exists in the config or MY_ARGS |
67 |
eerror "Please check your config file \`${MY_CNF}'" |
88 |
if [ -z "${wsrep}" ] || [ -n "${wsrep-new}" ] || stringContain 'wsrep-new-cluster' "${MY_ARGS}" ; then |
68 |
return 1 |
89 |
|
69 |
fi |
90 |
local datadir=$(get_config "${MY_CNF}" datadir | tail -n1) |
|
|
91 |
if [ ! -d "${datadir}" ] ; then |
92 |
eerror "MySQL datadir \`${datadir}' is empty or invalid" |
93 |
eerror "Please check your config file \`${MY_CNF}'" |
94 |
return 1 |
95 |
fi |
70 |
|
96 |
|
71 |
if [ ! -d "${datadir}"/mysql ] ; then |
97 |
if [ ! -d "${datadir}"/mysql ] ; then |
72 |
# find which package is installed to report an error |
98 |
# find which package is installed to report an error |
73 |
local EROOT=$(portageq envvar EROOT) |
99 |
local EROOT=$(portageq envvar EROOT) |
74 |
local DBPKG_P=$(portageq match ${EROOT} $(portageq expand_virtual ${EROOT} virtual/mysql | head -n1)) |
100 |
local DBPKG_P=$(portageq match ${EROOT} $(portageq expand_virtual ${EROOT} virtual/mysql | head -n1)) |
75 |
if [ -z ${DBPKG_P} ] ; then |
101 |
if [ -z ${DBPKG_P} ] ; then |
76 |
eerror "You don't appear to have a server package installed yet." |
102 |
eerror "You don't appear to have a server package installed yet." |
77 |
else |
103 |
else |
78 |
eerror "You don't appear to have the mysql database installed yet." |
104 |
eerror "You don't appear to have the mysql database installed yet." |
79 |
eerror "Please run \`emerge --config =${DBPKG_P}\` to have this done..." |
105 |
eerror "Please run \`emerge --config =${DBPKG_P}\` to have this done..." |
|
|
106 |
fi |
107 |
return 1 |
80 |
fi |
108 |
fi |
81 |
return 1 |
|
|
82 |
fi |
109 |
fi |
83 |
|
110 |
|
84 |
local piddir="${pidfile%/*}" |
111 |
local piddir="${pidfile%/*}" |
Lines 96-102
Link Here
|
96 |
start-stop-daemon \ |
123 |
start-stop-daemon \ |
97 |
${DEBUG:+"--verbose"} \ |
124 |
${DEBUG:+"--verbose"} \ |
98 |
--start \ |
125 |
--start \ |
99 |
--exec "${basedir}"/sbin/mysqld \ |
126 |
--exec "${basedir:=/usr}"/sbin/mysqld \ |
100 |
--pidfile "${pidfile}" \ |
127 |
--pidfile "${pidfile}" \ |
101 |
--background \ |
128 |
--background \ |
102 |
--wait ${startup_early_timeout} \ |
129 |
--wait ${startup_early_timeout} \ |
Lines 117-122
Link Here
|
117 |
} |
144 |
} |
118 |
|
145 |
|
119 |
stop() { |
146 |
stop() { |
|
|
147 |
if [ ${RC_CMD} = "restart" ] ; then |
148 |
checkconfig || return 1 |
149 |
fi |
150 |
|
120 |
ebegin "Stopping $(mysql_svcname)" |
151 |
ebegin "Stopping $(mysql_svcname)" |
121 |
|
152 |
|
122 |
local pidfile="$(get_options pidfile)" |
153 |
local pidfile="$(get_options pidfile)" |
Lines 140-149
Link Here
|
140 |
|
171 |
|
141 |
if [ ${RC_CMD} = "checkconfig" ] ; then |
172 |
if [ ${RC_CMD} = "checkconfig" ] ; then |
142 |
# We are calling checkconfig specifically. Print warnings regardless. |
173 |
# We are calling checkconfig specifically. Print warnings regardless. |
143 |
"${basedir}"/sbin/mysqld --defaults-file="${my_cnf}" --help --verbose > /dev/null |
174 |
"${basedir:=/usr}"/sbin/mysqld --defaults-file="${my_cnf}" --help --verbose > /dev/null |
144 |
else |
175 |
else |
145 |
# Suppress output to check the return value |
176 |
# Suppress output to check the return value |
146 |
"${basedir}"/sbin/mysqld --defaults-file="${my_cnf}" --help --verbose > /dev/null 2>&1 |
177 |
"${basedir:=/usr}"/sbin/mysqld --defaults-file="${my_cnf}" --help --verbose > /dev/null 2>&1 |
147 |
|
178 |
|
148 |
# If the above command does not return 0, |
179 |
# If the above command does not return 0, |
149 |
# then there is an error to echo to the user |
180 |
# then there is an error to echo to the user |