initial commit of file from CVS for smeserver-mysql on Sat Mar 23 16:06:28 AEDT 2024

This commit is contained in:
Trevor Batley
2024-03-23 16:06:28 +11:00
parent 715005ffa3
commit df83d181c9
67 changed files with 2762 additions and 2 deletions

View File

@@ -0,0 +1,3 @@
#! /bin/sh
cd /var/opt/rh/rh-mariadb!!!VER!!!/lib/mysql && find . -type f | xargs rm -f

View File

@@ -0,0 +1,3 @@
#!/bin/sh
exec /bin/rm -f /home/e-smith/db/mariadb!!!VER!!!/*.dump

View File

@@ -0,0 +1,58 @@
#!/bin/sh
# We have to re-enable SCL environment, because /sbin/service
# clears almost all environment variables.
# Since X_SCLS is cleared as well, we lose information about other
# collections enabled.
. /opt/rh/rh-mariadb!!!VER!!!/service-environment
for sclname in $RH_MARIADB!!!VER!!!_SCLS_ENABLED ; do
. /opt/rh/$sclname/enable
export X_SCLS="$X_SCLS $sclname"
done
# we want start daemon only inside "scl enable" invocation
if ! scl_enabled $sclname ; then
echo "Collection $sclname has to be listed in /opt/rh/rh-mariadb!!!VER!!!/service-environment"
exit 1
fi
status=$(/sbin/e-smith/config getprop mariadb status)
fixtables=$(/sbin/e-smith/config getprop mariadb autofixtables || echo "disabled")
if [ "$fixtables" = "enabled" ]; then
/sbin/e-smith/config delprop mariadb failsbackup
fi
failsbackup=$(/sbin/e-smith/config getprop mariadb failsbackup || echo "disabled")
onfailure () {
db=$1
message=""
if [ "$failsbackup" = "enabled" ]; then
exit 1;
message="There was an error trying to dump database $db, please fix this db. We stop there without backups."
echo $message
echo $message | /usr/bin/mail -s "error on backup of $db MariaDB !!!VER!!! database" admin
fi
message="$message \nThere was an error trying to dump database $db, please check for table errors in this db. Forcing a backup of the corrupted DB."
/opt/rh/rh-mariadb!!!VER!!!/root/usr/bin/mysqldump --socket=!!!SOCKET!!! --force --ignore-table=mysql.event --single-transaction --add-drop-table -QB "$db" -r /home/e-smith/db/mariadb!!!VER!!!/"$db"-failed.dump || message="$message \nFailed to force backup of corrupted db $db as $db-failed.dump" >&2
if [ "$fixtables" = "enabled" ]; then
repair="failure"
message="$message \nTrying to auto-repair the db and do a backup after..."
/opt/rh/rh-mariadb!!!VER!!!/root/usr/bin/mysqlcheck --socket=!!!SOCKET!!! -s --auto-repair -c "$db" && \
/opt/rh/rh-mariadb!!!VER!!!/root/usr/bin/mysqldump --socket=!!!SOCKET!!! --ignore-table=mysql.event --single-transaction --add-drop-table -QB "$db" -r /home/e-smith/db/mariadb!!!VER!!!/"$db".dump && repair="success"
message="$message \n => $repair"
fi
echo $message
echo $message | /usr/bin/mail -s "error on backup of $db MariaDB database" admin
}
if [ "$status" = "disabled" ]
then
echo "mysqld is disabled - no tables dumped" >&2
exit 0
fi
for db in $(/opt/rh/rh-mariadb!!!VER!!!/root/usr/bin/mysql --socket=!!!SOCKET!!! -BNre "show databases;"|egrep -vi "^information_schema$|^performance_schema$")
do
/opt/rh/rh-mariadb!!!VER!!!/root/usr/bin/mysqldump --socket=!!!SOCKET!!! --ignore-table=mysql.event --single-transaction --add-drop-table -QB "$db" -r /home/e-smith/db/mariadb!!!VER!!!/"$db".dump || onfailure $db
done

View File

@@ -0,0 +1,17 @@
#!/bin/sh
status=$(/sbin/e-smith/config getprop mariadb!!!VER!!!-mariadb status)
if [ "$status" = "disabled" ]
then
echo "mysqld is disabled - no tables restored" >&2
exit 0
fi
/bin/rm -f /home/e-smith/db/mariadb!!!VER!!!/information_schema.dump
/bin/rm -f /home/e-smith/db/mariadb!!!VER!!!/performance_schema.dump
if [ ! -f /var/opt/rh/rh-mariadb!!!VER!!!/lib/mysql/mysql/user.frm ]
then
for db in $(ls /home/e-smith/db/mariadb!!!VER!!!/*.dump 2> /dev/null | grep -v '/mysql.dump')
do
mv $db /etc/e-smith/sql/init!!!VER!!!/01_$(basename $db .dump).sql
done
fi

View File

@@ -0,0 +1,5 @@
socket=/var/lib/mysql/mariadb!!!VER!!!.sock
{
my $localonly = ${'mariadb!!!VER!!!-mariadb'}{'LocalNetworkingOnly'} || "no";
$OUT = ($localonly eq 'yes') ? "skip-networking" : "skip-networking=0\n# networking is enabled";
}

View File

@@ -0,0 +1,7 @@
{
$OUT = "";
my $localonly = ${'mariadb!!!VER!!!-mariadb'}{'LocalNetworkingOnly'} || "no";
# define port
my $port = ${'mariadb!!!VER!!!-mariadb'}{'port'} || "!!!PORT!!!";
$OUT .= ($localonly eq 'yes') ? "#no port as skip-networking\n" : "port=$port\n";
}

View File

@@ -0,0 +1,84 @@
/* Server Mariadb !!!VER!!! localhost (config:root) [1] */
$i++;
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['connect_type'] = 'socket';
$cfg['Servers'][$i]['socket'] = '!!!SOCKET!!!';
$cfg['Servers'][$i]['compress'] = false;
# standalone or login mode
$scriptname=end(explode('/',$_SERVER['PHP_SELF']));
$scriptpath=str_replace($scriptname,"",$_SERVER['PHP_SELF']);
# standalone login part
{
my $adminaccess = ($phpmyadmin{'adminaccess'} || 'enabled');
my $multiaccess = ($phpmyadmin{'multiaccess'} || 'disabled');
if (("$adminaccess" eq "enabled"))
{
$OUT .="if (\$scriptpath==\"/phpmyadmin/\" && \$_SERVER['PHP_AUTH_USER']=='admin')\n";
$OUT .="{\n";
$OUT .="\$cfg['Servers'][\$i]['auth_type'] = 'config';\n";
$OUT .="\$cfg['Servers'][\$i]['user'] = 'root';\n";
open (PW, "/etc/openldap/ldap.pw")
|| die "Could not read LDAP password.\n";
my $pw = <PW>;
chomp ($pw);
close PW;
$OUT .="\$cfg['Servers'][\$i]['password'] = '$pw';\n";
$OUT .="}";
}
else
{
$OUT .="# standelaone admin configuration disabled";
}
}
# end of standalone login part
# multiuser login part
{
my $adminaccess = ($phpmyadmin{'adminaccess'} || 'enabled');
my $multiaccess = ($phpmyadmin{'multiaccess'} || 'disabled');
$OUT .="\n";
if (("$multiaccess" eq "enabled") && ("$adminaccess" eq "enabled"))
{
$OUT .="if (\$scriptpath==\"/phpmyadmin-multi/\")\n";
$OUT .="{\n";
}
if (("$multiaccess" eq "enabled"))
{
$OUT .="\$cfg['Servers'][\$i]['auth_type'] = 'cookie';\n";
my $secret = ${'httpd-admin'}{TKTAuthSecret} || "34322500-7330-4400-423A-3A00434F5245";
$OUT .="\$cfg['blowfish_secret'] = '$secret';\n";
}
else
{
$OUT .="# multiuser disabled\n";
}
if (("$multiaccess" eq "enabled") && ("$adminaccess" eq "enabled"))
{
$OUT .="}\n";
}
}
# end of multiuser login part
$cfg['Servers'][$i]['controluser'] = "";
$cfg['Servers'][$i]['controlpass'] = "";
$cfg['Servers'][$i]['only_db'] = "";
$cfg['Servers'][$i]['hide_db'] = "";
$cfg['Servers'][$i]['verbose'] = 'Mariadb!!!VER!!!';// here is the name as it appears in phpmyadmin
$cfg['Servers'][$i]['pmadb'] = "";
$cfg['Servers'][$i]['bookmarktable'] = "";
$cfg['Servers'][$i]['relation'] = "";
$cfg['Servers'][$i]['table_info'] = "";
$cfg['Servers'][$i]['table_coords'] = "";
$cfg['Servers'][$i]['pdf_pages'] = "";
$cfg['Servers'][$i]['column_info'] = "";
$cfg['Servers'][$i]['history'] = "";
$cfg['Servers'][$i]['verbose_check'] = TRUE;
$cfg['Servers'][$i]['AllowRoot'] = TRUE;
$cfg['Servers'][$i]['AllowDeny']['order']="";
$cfg['Servers'][$i]['AllowDeny']['rules']= array();
$cfg['Servers'][$i]['AllowNoPassword']= FALSE;
$cfg['Servers'][$i]['designer_coords']= "";
$cfg['Servers'][$i]['bs_garbage_threshold']= 50;
$cfg['Servers'][$i]['bs_repository_threshold']= '32M';
$cfg['Servers'][$i]['bs_temp_blob_timeout']= 600;
$cfg['Servers'][$i]['bs_temp_log_threshold']= '32M';

View File

@@ -0,0 +1,17 @@
/var/log/mariadb!!!VER!!!/*.log {
create 640 mysql mysql
notifempty
daily
rotate 7
missingok
compress
postrotate
# just if mysqld is really running
if test -x /opt/rh/rh-mariadb!!!VER!!!/root/usr/bin/mysqladmin && \
/usr/bin/scl enable rh-mariadb!!!VER!!! -- /opt/rh/rh-mariadb!!!VER!!!/root/usr/bin/mysqladmin --socket=!!!SOCKET!!! ping &>/dev/null
then
/usr/bin/scl enable rh-mariadb!!!VER!!! -- /opt/rh/rh-mariadb!!!VER!!!/root/usr/bin/mysqladmin --socket=!!!SOCKET!!! --local flush-error-log \
flush-engine-log flush-general-log flush-slow-log
fi
endscript
}

View File

@@ -0,0 +1,61 @@
#!/usr/bin/perl -w
use strict;
use esmith::config;
use esmith::db;
use esmith::util;
my %conf;
tie %conf, 'esmith::config';
my $event = $ARGV[0];
my $file = $ARGV[1];
#---------------------------------------------------------------------------
# Check the runlevel, if we're in runlevel 7, and we're being called from
# bootstrap-console-save, then MySQL can't be running, so use bootstrap mode.
# Otherwise, just use mysql to do a straight import.
#---------------------------------------------------------------------------
my $runlevel;
open (RUNLEVEL, "-|", "/usr/bin/systemctl get-default");
(undef, $runlevel) = split(' ',<RUNLEVEL>);
close RUNLEVEL;
if ( ($runlevel ne 'multi-user.target' && $runlevel ne "sme-server.target") || $event eq 'bootstrap-console-save')
{
my $pid = open(KID, "|-");
if (defined $pid)
{
if ($pid)
{
open(SQL, "<$file");
print KID foreach (<SQL>);
close SQL;
close(KID);
waitpid $pid,0;
}
else
{
# Find our mysqld binary
my $mysqld = "/opt/rh/rh-mariadb!!!VER!!!/root/usr/libexec/mysqld";
if (-f "/opt/rh/rh-mariadb!!!VER!!!/root/usr/sbin/mysqld") {
$mysqld = "/opt/rh/rh-mariadb!!!VER!!!/root/usr/sbin/mysqld";
}
# Hard-code user, since it is set in mysqld_safe currently.
# See http://bugs.mysql.com/2163
exec("/usr/bin/scl enable rh-mariadb!!!VER!!! -- $mysqld", qw(--bootstrap --user=mysql --skip-grant-tables));
}
}
else
{
warn "Couldn't fork: $!";
}
}
else
{
system("/usr/bin/scl enable rh-mariadb!!!VER!!! -- /opt/rh/rh-mariadb!!!VER!!!/root/usr/bin/mysql < $file");
}
exit(0);

View File

@@ -0,0 +1,58 @@
#!/bin/bash
datadir="/var/opt/rh/rh-mariadb!!!VER!!!/lib/mysql"
# We have to re-enable SCL environment, because /sbin/service
# clears almost all environment variables.
# Since X_SCLS is cleared as well, we lose information about other
# collections enabled.
. /opt/rh/rh-mariadb!!!VER!!!/service-environment
for sclname in $RH_MARIADB!!!VER!!!_SCLS_ENABLED ; do
. /opt/rh/$sclname/enable
export X_SCLS="$X_SCLS $sclname"
done
# we want start daemon only inside "scl enable" invocation
if ! scl_enabled $sclname ; then
echo "Collection $sclname has to be listed in /opt/rh/rh-mariadb!!!VER!!!/service-environment"
exit 1
fi
if [ ! -f $datadir/mysql/user.frm ]
then
touch /var/log/mariadb!!!VER!!!/mariadb.log
chown mysql:mysql /var/log/mariadb!!!VER!!!/mariadb.log
chmod 0640 /var/log/mariadb!!!VER!!!/mariadb.log
echo "Initializing mariadb!!!VER!!! database"
/opt/rh/rh-mariadb!!!VER!!!/root/usr/libexec/mysql-prepare-db-dir
ret=$?
if [ $ret -ne 0 ] ; then
echo "Initialization of MySQL database failed." >&2
echo "Perhaps /etc/opt/rh/rh-mariadb!!!VER!!!/my.cnf is misconfigured." >&2
# Clean up any partially-created database files
if [ ! -e "$datadir/mysql/user.frm" ] ; then
rm -rf "$datadir"/*
fi
exit $ret
fi
# set root password , 104 and above have a different syntax and allow root passwordless access
if [ !!!VER!!! -le 103 ]
then
/opt/rh/rh-mariadb!!!VER!!!/root/usr/libexec/mysqld --bootstrap --datadir="$datadir" --user="mysql" < /var/lib/mysql/set.password2
fi
# upgrade does not need to be run on a fresh datadir
#echo "5.7.24" >"$datadir/mysql_upgrade_info"
# In case we're running as root, make sure files are owned properly
chown -R "mysql:mysql" "$datadir"
if [ -f /home/e-smith/db/mariadb!!!VER!!!/mysql.dump ]
then
/sbin/e-smith/expand-template /etc/e-smith/sql/init!!!VER!!!/00_restore_dumped_dbs
fi
else
# else we set root password anyway ! just to be sure ! 104 and above have a different syntax and allow root passwordless access
if [ !!!VER!!! -le 103 ]
then
/opt/rh/rh-mariadb!!!VER!!!/root/usr/libexec/mysqld --bootstrap --datadir="$datadir" --user="mysql" < /var/lib/mysql/set.password2
fi
exit 0
fi

View File

@@ -0,0 +1,82 @@
#!/bin/sh
#----------------------------------------------------------------------
# copyright (C) 2022 Koozali Foundation
#
# 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Technical support for this program is available from Mitel Networks
# Please visit our web site www.mitel.com/sme/ for details.
#----------------------------------------------------------------------
# We have to re-enable SCL environment, because /sbin/service
# clears almost all environment variables.
# Since X_SCLS is cleared as well, we lose information about other
# collections enabled.
. /opt/rh/rh-mariadb!!!VER!!!/service-environment
for sclname in $RH_MARIADB!!!VER!!!_SCLS_ENABLED ; do
. /opt/rh/$sclname/enable
export X_SCLS="$X_SCLS $sclname"
done
# we want start daemon only inside "scl enable" invocation
if ! scl_enabled $sclname ; then
echo "Collection $sclname has to be listed in /opt/rh/rh-mariadb!!!VER!!!/service-environment"
exit 1
fi
# Source function library.
. /etc/rc.d/init.d/functions
if [ $# -lt 1 ]; then
echo "Usage: $0 <start|restart>" 1>&2
exit 1
fi
# We should only do something if $1 is 'start'.
if [ $1 != "start" ] && [ $1 != "restart" ]; then
exit 0
fi
for i in $(seq 1 10)
do
if test -e !!!SOCKET!!!
then
exit_value=0
HOME=/root
export HOME
for link in $(find /etc/e-smith/sql/init!!!VER!!! -type f -o -type l | sort)
do
F=$(basename $link | sed s/S[0-9][0-9]//)
case $F in
*.sql)
action "Loading $F into mariadb !!!VER!!!" /opt/rh/rh-mariadb!!!VER!!!/root/usr/bin/mysql --socket=!!!SOCKET!!! < $link && /bin/rm $link
;;
*)
action "Loading $F into mariadb !!!VER!!!" $link && /bin/rm $link
;;
esac
# Record any failure for the final return value.
if [ $? -ne 0 ]; then
exit_value=1
fi
done
exit $exit_value
fi
echo "Waiting for mysql to startup" >&2
sleep 2
done
exit 1

View File

@@ -0,0 +1,18 @@
#!/bin/bash
for i in $(seq 1 20);
do
if [ -S !!!SOCKET!!! ]
then
/usr/bin/mysql!!!VER!!! < /var/lib/mysql/set.password2
echo "root password set"
exit 0
fi
echo waiting for rh-mariadb105-mariadb to start to set root password
sleep 1
done
echo failed to set root password
# we fail silently, mariadb will still work, only issue is for phpmyadmin
# and non socket access
exit 0

View File

@@ -0,0 +1,53 @@
[Unit]
Description=Mariadb !!!VER!!! database server
After=syslog.target
After=network.target
[Service]
Type=simple
User=root
Group=root
PIDFile=/var/run/rh-mariadb!!!VER!!!-mariadb/mariadb.pid
# Load collections set to enabled for this service
EnvironmentFile=/opt/rh/rh-mariadb!!!VER!!!/service-environment
#ours : we need root user as + and ! are not yet supported
ExecStartPre=-/sbin/e-smith/service-status mariadb!!!VER!!!-mariadb
ExecStartPre=-/sbin/e-smith/expand-template /var/lib/mysql/set.password
ExecStartPre=-/sbin/e-smith/expand-template /root/.my.cnf
ExecStartPre=-/sbin/e-smith/expand-template /etc/my.cnf
ExecStartPre=-/sbin/e-smith/expand-template /etc/opt/rh/rh-mariadb!!!VER!!!/my.cnf
ExecStartPre=/sbin/e-smith/systemd/mariadb!!!VER!!!-initialize
# We want to start server only inside "scl enable" invocation
ExecStartPre=/usr/bin/scl enable $RH_MARIADB!!!VER!!!_SCLS_ENABLED -- /usr/bin/scl_enabled rh-mariadb!!!VER!!!
ExecStartPre=/usr/bin/scl enable $RH_MARIADB!!!VER!!!_SCLS_ENABLED -- /opt/rh/rh-mariadb!!!VER!!!/root/usr/libexec/mysql-check-socket
ExecStartPre=/usr/bin/scl enable $RH_MARIADB!!!VER!!!_SCLS_ENABLED -- /opt/rh/rh-mariadb!!!VER!!!/root/usr/libexec/mysql-prepare-db-dir %n
# Note: we set --basedir to prevent probes that might trigger SELinux alarms,
# per bug #547485
ExecStart=/opt/rh/rh-mariadb!!!VER!!!/root/usr/libexec/mysqld_safe-scl-helper enable $RH_MARIADB!!!VER!!!_SCLS_ENABLED -- /opt/rh/rh-mariadb!!!VER!!!/root/usr/libexec/mysqld \
--defaults-file=/etc/my.cnf \
--datadir=/var/opt/rh/rh-mariadb!!!VER!!!/lib/mysql \
--user=mysql \
--basedir=/opt/rh/rh-mariadb!!!VER!!!/root/usr \
--pid-file=/var/run/rh-mariadb!!!VER!!!-mariadb/mariadb.pid
ExecStartPost=/usr/bin/scl enable $RH_MARIADB!!!VER!!!_SCLS_ENABLED -- /opt/rh/rh-mariadb!!!VER!!!/root/usr/libexec/mysql-check-upgrade
ExecStopPost=/usr/bin/scl enable $RH_MARIADB!!!VER!!!_SCLS_ENABLED -- /opt/rh/rh-mariadb!!!VER!!!/root/usr/libexec/mysql-wait-stop
#ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID
# Give a reasonable amount of time for the server to start up/shut down
TimeoutSec=300
# Place temp files in a secure directory, not /tmp
PrivateTmp=true
Restart=on-failure
RestartPreventExitStatus=1
[Install]
WantedBy=sme-server.target

View File

@@ -0,0 +1,20 @@
[Unit]
SourcePath=/sbin/e-smith/systemd/mariadb!!!VER!!!-mysql.init
Description=Koozali SME Server mysql DB injector for mariadb!!!VER!!!
After=mariadb!!!VER!!!-mariadb.service
Requires=mariadb!!!VER!!!-mariadb.service
[Service]
Type=oneshot
Restart=no
TimeoutSec=10min
IgnoreSIGPIPE=no
KillMode=process
GuessMainPID=no
RemainAfterExit=yes
ExecStart=/sbin/e-smith/systemd/mariadb!!!VER!!!-mysql.init start
ExecStop=/sbin/e-smith/systemd/mariadb!!!VER!!!-mysql.init stop
[Install]
WantedBy=sme-server.target