initial commit of file from CVS for smeserver-mysql on Sat Mar 23 16:06:28 AEDT 2024
This commit is contained in:
61
root/sbin/e-smith/mysql-preload
Normal file
61
root/sbin/e-smith/mysql-preload
Normal 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 = "/usr/libexec/mysqld";
|
||||
if (-f "/usr/sbin/mysqld") {
|
||||
$mysqld = "/usr/sbin/mysqld";
|
||||
}
|
||||
# Hard-code user, since it is set in mysqld_safe currently.
|
||||
# See http://bugs.mysql.com/2163
|
||||
exec($mysqld, qw(--bootstrap --user=mysql --skip-grant-tables));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
warn "Couldn't fork: $!";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
system("/usr/bin/mysql < $file");
|
||||
}
|
||||
exit(0);
|
Reference in New Issue
Block a user