Skip to content

Commit 61b54fc

Browse files
committed
Work around lack of systemd on pods
Fix some more broken paths
1 parent 446b2ac commit 61b54fc

File tree

3 files changed

+263
-60
lines changed

3 files changed

+263
-60
lines changed

hammerdb/do_service

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
#!/bin/bash
2+
#
3+
# Copyright (C) 2024 Robert Krawitz [email protected]
4+
#
5+
# This program is free software; you can redistribute it and/or
6+
# modify it under the terms of the GNU General Public License
7+
# as published by the Free Software Foundation; either version 2
8+
# of the License, or (at your option) any later version.
9+
#
10+
# This program is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU General Public License
16+
# along with this program; if not, write to the Free Software
17+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18+
19+
# This file is intended to be sourced, not executed directly.
20+
21+
declare -g _does_support_systemctl=${_does_support_systemctl:--1}
22+
23+
supports_systemctl() {
24+
if ((_does_support_systemctl < 0)) ; then
25+
if type -p systemctl >/dev/null && systemctl >/dev/null 2>&1 ; then
26+
_does_support_systemctl=1
27+
else
28+
_does_support_systemctl=0
29+
fi
30+
fi
31+
((_does_support_systemctl))
32+
}
33+
34+
start_service() {
35+
local service
36+
for service in "$@" ; do
37+
case "$service" in
38+
postgres*)
39+
su -s /bin/bash - postgres -c "pg_ctl -D ${mountpoint}/pgsql -l ${mountpoint}/pgsql/logfile start" &
40+
;;
41+
mssql*)
42+
mkdir -p "${mountpoint}/mssql"
43+
chmod 777 "${mountpoint}/mssql"
44+
podman run --replace -e ACCEPT_EULA=Y -e MSSQL_SA_PASSWORD=100yard- -p1433:1433 --name mssql -v "${mountpoint}/mssql:/var/opt/mssql" -d mcr.microsoft.com/mssql/server:2022-latest
45+
if [[ -n "${memorykb:-}" ]] ; then
46+
sleep 5
47+
podman exec mssql /opt/mssql/bin/mssql-conf set memory.memorylimitmb "$((memorykb / 1024))"
48+
podman restart mssql
49+
sleep 5
50+
fi
51+
;;
52+
maria*)
53+
# mkdir -p "${mountpoint}/mysql"
54+
# chown mysql.mysql "${mountpoint}/mysql"
55+
# mkdir -p /var/lib/mysql
56+
# rm -f /var/lib/mysql/mysql.sock
57+
# ln -s "${mountpoint}/mysql/mysql.sock" /var/lib/mysql/mysql.sock
58+
# podman run --rm --replace -p 3306:3306 -d --user mysql:mysql --name mariadb -e MYSQL_ROOT_PASSWORD=100yard- -v "${mountpoint}/mysql:/var/lib/mysql" quay.io/fedora/mariadb-102
59+
#mkdir -p "$mountpoint"/mysql
60+
#podman run --replace -p 3306:3306 --userns=keep-id -d --name mariadb -e MYSQL_ROOT_PASSWORD=100yard- -v "${mountpoint}/mysql:/var/lib/mysql" quay.io/fedora/mariadb-102
61+
/usr/libexec/mariadb-check-socket
62+
/usr/libexec/mariadb-prepare-db-dir mysql mysql
63+
mariadbd-safe&
64+
;;
65+
*)
66+
echo "Unknown service $service"
67+
;;
68+
esac
69+
done
70+
sleep 5
71+
}
72+
73+
stop_service() {
74+
local service
75+
for service in "$@" ; do
76+
case "$service" in
77+
postgres*)
78+
su -s /bin/bash - postgres -c "pg_ctl -D ${mountpoint}/pgsql -l ${mountpoint}/pgsql/logfile stop"
79+
;;
80+
mssql*)
81+
podman kill mssql
82+
podman rm mssql
83+
;;
84+
maria*)
85+
# podman kill mariadb
86+
# sleep 5
87+
# podman rm mariadb
88+
# sleep 1
89+
pkill mariadbd
90+
;;
91+
*)
92+
echo "Unknown service $service"
93+
;;
94+
esac
95+
done
96+
sleep 5
97+
}
98+
99+
restart_service() {
100+
local service
101+
for service in "$@" ; do
102+
case "$service" in
103+
postgres*)
104+
su -s /bin/bash - postgres -c "pg_ctl -D ${mountpoint}/pgsql -l ${mountpoint}/pgsql/logfile stop"
105+
su -s /bin/bash - postgres -c "pg_ctl -D ${mountpoint}/pgsql -l ${mountpoint}/pgsql/logfile start" &
106+
;;
107+
mssql*)
108+
if podman ps |grep -q mssql ; then
109+
podman restart mssql
110+
else
111+
stop_service "$service"
112+
start_service "$service"
113+
fi
114+
;;
115+
mariadb*)
116+
stop_service "$service"
117+
start_service "$service"
118+
;;
119+
*)
120+
echo "Unknown service $service"
121+
;;
122+
esac
123+
done
124+
}
125+
126+
disable_service() {
127+
:
128+
}
129+
130+
enable_service() {
131+
:
132+
}
133+
134+
do_service() {
135+
local op=$1
136+
shift
137+
if supports_systemctl ; then
138+
systemctl "$op" "$@"
139+
else
140+
"${op}_service" "$@"
141+
fi
142+
}
143+
144+
# Local Variables:
145+
# sh-indentation: 8
146+
# End:

0 commit comments

Comments
 (0)