index.pl: DBI connect('database=;host=;','',...) failed

时间:2017-07-12 08:06:09

标签: perl docker otrs perlscript

I have an Open-source Ticket Request System (OTRS) docker container that works perfectly when I define Database, DatabaseHost, DatabasePw, and DatabaseUser in the Config.pm file

# The database host
    $Self->{DatabaseHost} = mysqldb;

    # The database name
    $Self->{Database} = otrs;

    # The database user
    $Self->{DatabaseUser} = otrs;

    # The password of database user. You also can use bin/otrs.Console.pl Maint::Database::PasswordCrypt
    # for crypted passwords
    $Self->{DatabasePw} = otrs;

Now I want to use the environment variables of the container, an Amazon Machine Image (AMI) Linux virtual system.

The env command prints out the right variables

bash-4.2# env
MYSQL_DATABASE=otrs
MYSQL_PASSWORD=otrs
MYSQL_HOSTNAME=mysqldb
MYSQL_USER=otrs

When I define them like this in Config.pm

use strict;
use warnings;
use utf8;
use diagnostics;

use Env;

my $MYSQL_HOSTNAME = $ENV{MYSQL_HOSTNAME};
my $MYSQL_DATABASE = $ENV{MYSQL_DATABASE};
my $MYSQL_USER     = $ENV{MYSQL_USER};
my $MYSQL_PASSWORD = $ENV{MYSQL_PASSWORD};


sub Load {
    my $Self = shift;

    # ---------------------------------------------------- #
    # database settings                                    #
    # ---------------------------------------------------- #

    # The database host
    $Self->{DatabaseHost} = $MYSQL_HOSTNAME;

    # The database name
    $Self->{Database} = $MYSQL_DATABASE;

    # The database user
    $Self->{DatabaseUser} = $MYSQL_USER;

    # The password of database user. You also can use bin/otrs.Console.pl Maint::Database::PasswordCrypt
    # for crypted passwords
    $Self->{DatabasePw} = $MYSQL_PASSWORD;

    # The database DSN for MySQL ==> more: "perldoc DBD::mysql"
    $Self->{DatabaseDSN} = "DBI:mysql:database=$Self->{Database};host=$Self->{DatabaseHost};";

I'm getting the following errors in etc/httpd/logs/error_log

[Wed Jul 12 07:45:54 2017] [error] [client 172.18.0.1] [Wed Jul 12 07:45:54 2017] index.pl: Use of uninitialized value in concatenation (.) or string at /opt/otrs/bin/cgi-bin/../../Kernel/Config.pm line 53., referer: http://localhost/otrs/index.pl?
[Wed Jul 12 07:45:54 2017] [error] [client 172.18.0.1] [Wed Jul 12 07:45:54 2017] index.pl: Use of uninitialized value in concatenation (.) or string at /opt/otrs/bin/cgi-bin/../../Kernel/Config.pm line 53., referer: http://localhost/otrs/index.pl?
[Wed Jul 12 07:45:54 2017] [error] [client 172.18.0.1] [Wed Jul 12 07:45:54 2017] index.pl: Use of uninitialized value in concatenation (.) or string at /opt/otrs/bin/cgi-bin/../../Kernel/Config.pm line 53., referer: http://localhost/otrs/index.pl?
[Wed Jul 12 07:45:54 2017] [error] [client 172.18.0.1] [Wed Jul 12 07:45:54 2017] index.pl: Use of uninitialized value in concatenation (.) or string at /opt/otrs/bin/cgi-bin/../../Kernel/Config.pm line 53., referer: http://localhost/otrs/index.pl?
[Wed Jul 12 07:45:54 2017] [error] [client 172.18.0.1] ERROR: Database not defined!, referer: http://localhost/otrs/index.pl?
[Wed Jul 12 07:45:54 2017] [error] [client 172.18.0.1] ERROR: DatabaseHost not defined!, referer: http://localhost/otrs/index.pl?
[Wed Jul 12 07:45:54 2017] [error] [client 172.18.0.1] ERROR: DatabasePw not defined!, referer: http://localhost/otrs/index.pl?
[Wed Jul 12 07:45:54 2017] [error] [client 172.18.0.1] ERROR: DatabaseUser not defined!, referer: http://localhost/otrs/index.pl?
[Wed Jul 12 07:45:54 2017] [error] [client 172.18.0.1] [Wed Jul 12 07:45:54 2017] index.pl: Use of uninitialized value in pattern match (m//) at /opt/otrs/bin/cgi-bin/../../Kernel/System/DB.pm line 92., referer: http://localhost/otrs/index.pl?
[Wed Jul 12 07:45:54 2017] [error] [client 172.18.0.1] [Wed Jul 12 07:45:54 2017] index.pl: DBI connect('database=;host=;','',...) failed: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) at /opt/otrs/bin/cgi-bin/../../Kernel/System/DB.pm line 202., referer: http://localhost/otrs/index.pl?
[Wed Jul 12 07:45:54 2017] [error] [client 172.18.0.1] ERROR: OTRS-CGI-10 Perl: 5.16.3 OS: linux Time: Wed Jul 12 07:45:54 2017, referer: http://localhost/otrs/index.pl?
[Wed Jul 12 07:45:54 2017] [error] [client 172.18.0.1] , referer: http://localhost/otrs/index.pl?
[Wed Jul 12 07:45:54 2017] [error] [client 172.18.0.1]  Message: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2), referer: http://localhost/otrs/index.pl?
[Wed Jul 12 07:45:54 2017] [error] [client 172.18.0.1] , referer: http://localhost/otrs/index.pl?
[Wed Jul 12 07:45:54 2017] [error] [client 172.18.0.1]  RemoteAddress: 172.18.0.1, referer: http://localhost/otrs/index.pl?
[Wed Jul 12 07:45:54 2017] [error] [client 172.18.0.1]  RequestURI: /otrs/index.pl?, referer: http://localhost/otrs/index.pl?
[Wed Jul 12 07:45:54 2017] [error] [client 172.18.0.1] , referer: http://localhost/otrs/index.pl?
[Wed Jul 12 07:45:54 2017] [error] [client 172.18.0.1]  Traceback (4724): , referer: http://localhost/otrs/index.pl?
[Wed Jul 12 07:45:54 2017] [error] [client 172.18.0.1]    Module: Kernel::System::Web::InterfaceAgent::Run Line: 164, referer: http://localhost/otrs/index.pl?
[Wed Jul 12 07:45:54 2017] [error] [client 172.18.0.1]    Module: /opt/otrs/bin/cgi-bin/index.pl Line: 40, referer: http://localhost/otrs/index.pl?
[Wed Jul 12 07:45:54 2017] [error] [client 172.18.0.1] , referer: http://localhost/otrs/index.pl?

I don't understand why the perl use strict doesn't recognise the environment variables.

I have tried every method from How to access shell environment variables in Perl script

and even tried it with

$Self->{DatabaseHost} = $ENV{'MYSQL_HOSTNAME'};

with all variables.

The script works with $ENV{'MYSQL_HOSTNAME'} when the base image is Ubuntu and not AMI Linux / RedHat

0 个答案:

没有答案