diff options
Diffstat (limited to 'setup/mysqlstat-setup.pl')
-rw-r--r-- | setup/mysqlstat-setup.pl | 42 |
1 files changed, 35 insertions, 7 deletions
diff --git a/setup/mysqlstat-setup.pl b/setup/mysqlstat-setup.pl index 00988a2..6c8eecc 100644 --- a/setup/mysqlstat-setup.pl +++ b/setup/mysqlstat-setup.pl @@ -1,4 +1,19 @@ #!/usr/bin/perl +# This file is part of Mysqlstat +# Copyright (C) 2016 Sergey Poznyakoff +# +# Mysqlstat 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 3, or (at your option) +# any later version. +# +# Mysqlstat 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 Mysqlstat. If not, see <http://www.gnu.org/licenses/>. use strict; use DBI; @@ -214,20 +229,30 @@ sub db_connect { $arg .= ":port=$mysql_port" if defined $mysql_port; $arg .= ":;mysql_read_default_file=$mysql_defaults_file" if defined $mysql_defaults_file; + my $my_cnf = "$ENV{HOME}/.my.cnf"; if (!$arg or (!defined($mysql_user) and !defined($mysql_defaults_file))) { - my $my_cnf = "$ENV{HOME}/.my.cnf"; if (-r $my_cnf) { error("info: using mysql option file $my_cnf"); $arg .= ":;mysql_read_default_file=$my_cnf"; } } - $arg = 'DBI:mysql'.$arg; + $arg = 'DBI:mysql'.($arg || ':'); my $dbd = DBI->connect($arg, $mysql_user, $mysql_password, { PrintError => 0, AutoCommit => 1 }); unless ($dbd) { - error("can't connect to MySQL server: ".$DBI::errstr); + error("can't connect to MySQL server: ".$DBI::errstr, + "This usually means that the credentials you supplied are incorrect.", + "The utility needs to connect to the MySQL server as a user with GRANT", + "privileges. There are several ways of supplying the credentials:", + "", + " 1. In $my_cnf file.", + " 2. In another MySQL option file.", + " In that case, use the option --defaults-file=FILENAME", + " 3. Via command line options --user, --password, and --host.", + "", + "Please verify that the supplied options are correct and rerun $progname."); exit EX_ERR; } return $dbd; @@ -357,6 +382,11 @@ GetOptions("h" => sub { "force|f" => \$force ) or exit(EX_ERR); +unless ($< == 0) { + error("must be run as root"); + exit EX_ERR; +} + unless ($libdir =~ m#^/#) { error('NetSNMP library directory is not set', "It appears you invoked a copy of $progname that hasn't been installed.", @@ -392,10 +422,6 @@ if (-e $mysqlstat_cnf and not $force) { exit EX_ERR; } -unless ($< == 0) { - error("must be run as root"); - exit EX_ERR; -} unless (-d $confdir) { error("no such directory: $confdir"); exit EX_ERR; @@ -420,3 +446,5 @@ edit_cnf; # 3. Edit snmpd.conf edit_snmp_conf; +print "$progname: Done.\n"; +print "$progname: Please restart snmpd in order for changes to make effect.\n"; |