0

我有一个 开源票务请求系统(OTRS) docker 容器,当我在文件中定义DatabaseDatabaseHostDatabasePw和时,它可以完美运行DatabaseUserConfig.pm

# 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;

现在我想使用容器的环境变量,一个Amazon Machine Image (AMI) Linux 虚拟系统。

env命令打印出正确的变量

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

当我这样定义它们时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};";

我收到以下错误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?

我不明白为什么 perluse strict不能识别环境变量。

我已经尝试了如何在 Perl 脚本中访问 shell 环境变量中的所有方法

甚至尝试过

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

与所有变量。

$ENV{'MYSQL_HOSTNAME'}当基础映像是 Ubuntu 而不是 AMI Linux / RedHat 时,该脚本适用

4

0 回答 0