Commit 24c18099 authored by Francesc Guasch's avatar Francesc Guasch
Browse files

[#281] allow config files elsewhere

parent c87733e8
......@@ -16,7 +16,9 @@ use Ravada::Auth::LDAP;
my $help;
my ($DEBUG, $ADD_USER );
my $FILE_CONFIG = "/etc/ravada.conf";
my $ADD_USER_LDAP;
my $IMPORT_DOMAIN;
my $CHANGE_PASSWORD;
......@@ -25,7 +27,7 @@ my $MAKE_ADMIN_USER;
my $REMOVE_ADMIN_USER;
my $USAGE = "$0 "
." [--debug] [--file-config=$FILE_CONFIG] [--add-user=name] [--add-user-ldap=name]"
." [--debug] [--config=$FILE_CONFIG] [--add-user=name] [--add-user-ldap=name]"
." [--change-password] [--make-admin=username]"
." [-X] [start|stop|status]"
."\n"
......@@ -34,9 +36,12 @@ my $USAGE = "$0 "
." --change-password : changes the password of an user\n"
." --import-domain : import a domain\n"
." --make-admin : make user admin\n"
." --config : config file, defaults to $FILE_CONFIG"
." -X : start in foreground\n"
;
$FILE_CONFIG = undef if ! -e $FILE_CONFIG;
GetOptions ( help => \$help
,debug => \$DEBUG
,'no-fork'=> \$NOFORK
......@@ -59,6 +64,11 @@ if ($help) {
}
die "Only root can do that\n" if $> && ( $ADD_USER || $ADD_USER_LDAP || $IMPORT_DOMAIN);
die "ERROR: Missing file config $FILE_CONFIG\n"
if $FILE_CONFIG && ! -e $FILE_CONFIG;
my %CONFIG;
%CONFIG = ( config => $FILE_CONFIG ) if $FILE_CONFIG;
$Ravada::DEBUG=1 if $DEBUG;
$Ravada::CAN_FORK=0 if $NOFORK;
......@@ -77,7 +87,7 @@ sub do_start {
start_process_longs() if !$NOFORK;
my $ravada = Ravada->new( config => $FILE_CONFIG );
my $ravada = Ravada->new( %CONFIG );
for (;;) {
my $t0 = time;
$ravada->process_requests();
......@@ -95,7 +105,7 @@ sub start_process_longs {
}
warn "Processing long requests in pid $$\n" if $DEBUG;
my $ravada = Ravada->new( config => $FILE_CONFIG );
my $ravada = Ravada->new( %CONFIG );
for (;;) {
my $t0 = time;
$ravada->process_long_requests();
......@@ -104,13 +114,13 @@ sub start_process_longs {
}
sub clean_killed_requests {
my $ravada = Ravada->new( config => $FILE_CONFIG );
my $ravada = Ravada->new( %CONFIG );
$ravada->clean_killed_requests();
}
sub start {
{
my $ravada = Ravada->new( config => $FILE_CONFIG );
my $ravada = Ravada->new( %CONFIG );
$Ravada::CONNECTOR->dbh;
for my $vm (@{$ravada->vm}) {
$vm->id;
......@@ -132,7 +142,7 @@ sub start {
sub add_user {
my $login = shift;
my $ravada = Ravada->new(config => $FILE_CONFIG);
my $ravada = Ravada->new( %CONFIG);
print "$login password: ";
my $password = <STDIN>;
......@@ -165,7 +175,7 @@ sub change_password {
chomp $login;
return if !$login;
my $ravada = Ravada->new( config => $FILE_CONFIG );
my $ravada = Ravada->new( %CONFIG );
my $user = Ravada::Auth::SQL->new(name => $login);
die "ERROR: Unknown user '$login'\n" if !$user->id;
......@@ -179,7 +189,7 @@ sub change_password {
sub make_admin {
my $login = shift;
my $ravada = Ravada->new(config => $FILE_CONFIG);
my $ravada = Ravada->new( %CONFIG);
my $user = Ravada::Auth::SQL->new(name => $login);
die "ERROR: Unknown user '$login'\n" if !$user->id;
......@@ -190,7 +200,7 @@ sub make_admin {
sub remove_admin {
my $login = shift;
my $ravada = Ravada->new(config => $FILE_CONFIG);
my $ravada = Ravada->new( %CONFIG);
my $user = Ravada::Auth::SQL->new(name => $login);
die "ERROR: Unknown user '$login'\n" if !$user->id;
......@@ -205,7 +215,7 @@ sub import_domain {
print "User name that will own the domain in Ravada : ";
my $user = <STDIN>;
chomp $user;
my $ravada = Ravada->new( config => $FILE_CONFIG );
my $ravada = Ravada->new( %CONFIG );
$ravada->import_domain(name => $name, vm => 'KVM', user => $user);
}
......
......@@ -48,6 +48,7 @@ Ravada - Remove Virtual Desktop Manager
our $FILE_CONFIG = "/etc/ravada.conf";
$FILE_CONFIG = undef if ! -e $FILE_CONFIG;
###########################################################################
......@@ -107,7 +108,7 @@ sub BUILD {
if ($self->config()) {
_init_config($self->config);
} else {
_init_config($FILE_CONFIG) if -e $FILE_CONFIG;
_init_config($FILE_CONFIG) if $FILE_CONFIG && -e $FILE_CONFIG;
}
if ( $self->connector ) {
......
......@@ -24,7 +24,6 @@ use Data::Dumper;
has 'config' => (
is => 'ro'
,isa => 'Str'
,default => $Ravada::FILE_CONFIG
);
has 'connector' => (
is => 'rw'
......@@ -60,7 +59,7 @@ sub BUILD {
if ($self->connector) {
$CONNECTOR = $self->connector;
} else {
Ravada::_init_config($self->config());
Ravada::_init_config($self->config()) if $self->config;
$CONNECTOR = Ravada::_connect_dbh();
}
$CONNECTOR->dbh();
......
......@@ -26,9 +26,17 @@ use POSIX qw(locale_h);
my $help;
my $FILE_CONFIG;
for ( "/etc/rvd_front.conf" , "$ENV{HOME}/rvd_front.conf") {
$FILE_CONFIG = $_ if -e $_;
last if $FILE_CONFIG;
for my $file ( "/etc/rvd_front.conf" , "$ENV{HOME}/rvd_front.conf") {
warn "WARNING: Found config file at $_ and at $FILE_CONFIG\n"
if -e $file && $FILE_CONFIG;
$FILE_CONFIG = $file if -e $file;
}
my $FILE_CONFIG_RAVADA;
for my $file ( "/etc/ravada.conf" , "$ENV{HOME}/ravada.conf") {
warn "WARNING: Found config file at $file and at $FILE_CONFIG_RAVADA\n"
if -e $file && $FILE_CONFIG_RAVADA;
$FILE_CONFIG_RAVADA = $file if -e $file;
}
my $CONFIG_FRONT = plugin Config => { default => {
......@@ -41,7 +49,7 @@ my $CONFIG_FRONT = plugin Config => { default => {
,login_message => ''
,secrets => ['changeme0']
,login_custom => ''
,config => ''
,config => $FILE_CONFIG_RAVADA
}
,file => $FILE_CONFIG
};
......@@ -70,7 +78,11 @@ setlocale(LC_CTYPE, $old_locale);
plugin I18N => {namespace => 'Ravada::I18N', default => 'en'};
plugin 'RenderFile';
our $RAVADA = Ravada::Front->new();
my %config;
%config = (config => $CONFIG_FRONT->{config}) if $CONFIG_FRONT->{config};
our $RAVADA = Ravada::Front->new(%config);
our $USER;
# TODO: get those from the config file
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment