|
| 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 | + /opt/mssql/bin/mssql-conf set memory.memorylimitmb "$((memorykb / 1024))" |
| 48 | + 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 |
| 49 | + fi |
| 50 | + ;; |
| 51 | + maria*) |
| 52 | + # mkdir -p "${mountpoint}/mysql" |
| 53 | + # chown mysql.mysql "${mountpoint}/mysql" |
| 54 | + # mkdir -p /var/lib/mysql |
| 55 | + # rm -f /var/lib/mysql/mysql.sock |
| 56 | + # ln -s "${mountpoint}/mysql/mysql.sock" /var/lib/mysql/mysql.sock |
| 57 | + # 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 |
| 58 | + #mkdir -p "$mountpoint"/mysql |
| 59 | + #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 |
| 60 | + /usr/libexec/mariadb-check-socket |
| 61 | + /usr/libexec/mariadb-prepare-db-dir mysql mysql |
| 62 | + mariadbd-safe& |
| 63 | + ;; |
| 64 | + *) |
| 65 | + echo "Unknown service $service" |
| 66 | + ;; |
| 67 | + esac |
| 68 | + done |
| 69 | + sleep 5 |
| 70 | +} |
| 71 | + |
| 72 | +stop_service() { |
| 73 | + local service |
| 74 | + for service in "$@" ; do |
| 75 | + case "$service" in |
| 76 | + postgres*) |
| 77 | + su -s /bin/bash - postgres -c "pg_ctl -D ${mountpoint}/pgsql -l ${mountpoint}/pgsql/logfile stop" |
| 78 | + ;; |
| 79 | + mssql*) |
| 80 | + podman kill mssql |
| 81 | + podman rm mssql |
| 82 | + ;; |
| 83 | + maria*) |
| 84 | + # podman kill mariadb |
| 85 | + # sleep 5 |
| 86 | + # podman rm mariadb |
| 87 | + # sleep 1 |
| 88 | + pkill mariadbd |
| 89 | + ;; |
| 90 | + *) |
| 91 | + echo "Unknown service $service" |
| 92 | + ;; |
| 93 | + esac |
| 94 | + done |
| 95 | + sleep 5 |
| 96 | +} |
| 97 | + |
| 98 | +restart_service() { |
| 99 | + local service |
| 100 | + for service in "$@" ; do |
| 101 | + case "$service" in |
| 102 | + postgres*) |
| 103 | + su -s /bin/bash - postgres -c "pg_ctl -D ${mountpoint}/pgsql -l ${mountpoint}/pgsql/logfile stop" |
| 104 | + su -s /bin/bash - postgres -c "pg_ctl -D ${mountpoint}/pgsql -l ${mountpoint}/pgsql/logfile start" & |
| 105 | + ;; |
| 106 | + mssql*) |
| 107 | + if podman ps |grep -q mssql ; then |
| 108 | + podman restart mssql |
| 109 | + else |
| 110 | + stop_service "$service" |
| 111 | + start_service "$service" |
| 112 | + fi |
| 113 | + ;; |
| 114 | + mariadb*) |
| 115 | + stop_service "$service" |
| 116 | + start_service "$service" |
| 117 | + ;; |
| 118 | + *) |
| 119 | + echo "Unknown service $service" |
| 120 | + ;; |
| 121 | + esac |
| 122 | + done |
| 123 | +} |
| 124 | + |
| 125 | +disable_service() { |
| 126 | + : |
| 127 | +} |
| 128 | + |
| 129 | +enable_service() { |
| 130 | + : |
| 131 | +} |
| 132 | + |
| 133 | +do_service() { |
| 134 | + local op=$1 |
| 135 | + shift |
| 136 | + if supports_systemctl ; then |
| 137 | + systemctl "$op" "$@" |
| 138 | + else |
| 139 | + "${op}_service" "$@" |
| 140 | + fi |
| 141 | +} |
| 142 | + |
| 143 | +# Local Variables: |
| 144 | +# sh-indentation: 8 |
| 145 | +# End: |
0 commit comments