62 lines
1.4 KiB
Plaintext
62 lines
1.4 KiB
Plaintext
|
#!/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);
|