From 416ab8a37f1b07dc9f6c0fb3ff1a8ff2036510b5 Mon Sep 17 00:00:00 2001 From: Sebastian Schmelzer Date: Thu, 2 Sep 2010 17:50:49 +0200 Subject: change dir structure --- .../plugins/syslog/OpenSLX/Distro/Base.pm | 93 ++++++ .../plugins/syslog/OpenSLX/Distro/Suse.pm | 41 +++ .../plugins/syslog/OpenSLX/OSPlugin/syslog.pm | 322 +++++++++++++++++++++ 3 files changed, 456 insertions(+) create mode 100644 src/os-plugins/plugins/syslog/OpenSLX/Distro/Base.pm create mode 100644 src/os-plugins/plugins/syslog/OpenSLX/Distro/Suse.pm create mode 100644 src/os-plugins/plugins/syslog/OpenSLX/OSPlugin/syslog.pm (limited to 'src/os-plugins/plugins/syslog/OpenSLX') diff --git a/src/os-plugins/plugins/syslog/OpenSLX/Distro/Base.pm b/src/os-plugins/plugins/syslog/OpenSLX/Distro/Base.pm new file mode 100644 index 00000000..ed08c5f3 --- /dev/null +++ b/src/os-plugins/plugins/syslog/OpenSLX/Distro/Base.pm @@ -0,0 +1,93 @@ +# Copyright (c) 2008 - OpenSLX GmbH +# +# This program is free software distributed under the GPL version 2. +# See http://openslx.org/COPYING +# +# If you have any feedback please consult http://openslx.org/feedback and +# send your suggestions, praise, or complaints to feedback@openslx.org +# +# General information about OpenSLX can be found at http://openslx.org/ +# ----------------------------------------------------------------------------- +# syslog/OpenSLX/Distro/Base.pm +# - provides base implementation of the Distro API for the syslog plugin. +# ----------------------------------------------------------------------------- +package syslog::OpenSLX::Distro::Base; + +use strict; +use warnings; + +our $VERSION = 1.01; # API-version . implementation-version + +use Scalar::Util qw( weaken ); + +use OpenSLX::Basics; +use OpenSLX::Utils; + +################################################################################ +### interface methods +################################################################################ +sub new +{ + my $class = shift; + my $self = {}; + return bless $self, $class; +} + +sub initialize +{ + my $self = shift; + $self->{engine} = shift; + weaken($self->{engine}); + # avoid circular reference between plugin and its engine + + return 1; +} + +sub runlevelInfo +{ + my $self = shift; + my $kind = shift; + + # most distros (well: Debian & Ubuntu) use a different initscript depending + # on which version of syslog is installed ('syslogd', 'syslog-ng' or 'rsyslog') + my %nameMap = ( + 'syslogd' => 'sysklogd', + 'syslog-ng' => 'syslog-ng', + 'rsyslog' => 'rsyslog', + ); + my $rlInfo = { + scriptName => $nameMap{$kind}, + startAt => 2, + stopAt => 15, + }; + + return $rlInfo; +} + +sub getPackageName +{ + my $self = shift; + my $name = shift; + + my %nameMap = ( + 'syslogd' => 'sysklogd', + 'syslog-ng' => 'syslog-ng', + 'rsyslog' => 'rsyslog', + ); + return $nameMap{$name}; +} + +sub getBinaryName +{ + my $self = shift; + my $name = shift; + + my %nameMap = ( + 'syslogd' => 'sysklogd', + 'syslog-ng' => 'syslog-ng', + 'rsyslog' => 'rsyslogd', + ); + return $nameMap{$name}; +} + +1; diff --git a/src/os-plugins/plugins/syslog/OpenSLX/Distro/Suse.pm b/src/os-plugins/plugins/syslog/OpenSLX/Distro/Suse.pm new file mode 100644 index 00000000..7255d6f5 --- /dev/null +++ b/src/os-plugins/plugins/syslog/OpenSLX/Distro/Suse.pm @@ -0,0 +1,41 @@ +# Copyright (c) 2006, 2007 - OpenSLX GmbH +# +# This program is free software distributed under the GPL version 2. +# See http://openslx.org/COPYING +# +# If you have any feedback please consult http://openslx.org/feedback and +# send your suggestions, praise, or complaints to feedback@openslx.org +# +# General information about OpenSLX can be found at http://openslx.org/ +# ----------------------------------------------------------------------------- +# syslog/OpenSLX/Distro/Suse.pm +# - provides SUSE-specific overrides of the Distro API for the syslog plugin. +# ----------------------------------------------------------------------------- +package syslog::OpenSLX::Distro::Suse; + +use strict; +use warnings; + +use base qw(syslog::OpenSLX::Distro::Base); + +use OpenSLX::Basics; + +################################################################################ +### interface methods +################################################################################ + +sub runlevelInfo +{ + my $self = shift; + my $attrs = shift; + + my $rlInfo = $self->SUPER::runlevelInfo($attrs); + + # SUSE uses a script named 'syslog', no matter if syslogd or syslog-ng + # is installed + $rlInfo->{scriptName} = 'syslog'; + + return $rlInfo; +} + +1; diff --git a/src/os-plugins/plugins/syslog/OpenSLX/OSPlugin/syslog.pm b/src/os-plugins/plugins/syslog/OpenSLX/OSPlugin/syslog.pm new file mode 100644 index 00000000..c011bf66 --- /dev/null +++ b/src/os-plugins/plugins/syslog/OpenSLX/OSPlugin/syslog.pm @@ -0,0 +1,322 @@ +# Copyright (c) 2008 - OpenSLX GmbH +# +# This program is free software distributed under the GPL version 2. +# See http://openslx.org/COPYING +# +# If you have any feedback please consult http://openslx.org/feedback and +# send your suggestions, praise, or complaints to feedback@openslx.org +# +# General information about OpenSLX can be found at http://openslx.org/ +# ----------------------------------------------------------------------------- +# syslog.pm +# - implementation of the 'syslog' plugin, which installs +# all needed information for a displaymanager and for the syslog. +# ----------------------------------------------------------------------------- +package OpenSLX::OSPlugin::syslog; + +use strict; +use warnings; + +use base qw(OpenSLX::OSPlugin::Base); + +use File::Basename; +use File::Path; + +use OpenSLX::Basics; +use OpenSLX::Utils; + +sub new +{ + my $class = shift; + + my $self = { + name => 'syslog', + }; + + return bless $self, $class; +} + +sub getInfo +{ + my $self = shift; + + return { + description => unshiftHereDoc(<<' End-of-Here'), + Sets up system log service for SLX-clients. + End-of-Here + precedence => 50, + }; +} + +sub getAttrInfo +{ + my $self = shift; + + return { + 'syslog::active' => { + applies_to_systems => 1, + applies_to_clients => 1, + description => unshiftHereDoc(<<' End-of-Here'), + should the 'syslog'-plugin be executed during boot? + End-of-Here + content_regex => qr{^(0|1)$}, + content_descr => '1 means active - 0 means inactive', + default => '1', + }, + 'syslog::kind' => { + applies_to_vendor_os => 1, + description => unshiftHereDoc(<<' End-of-Here'), + kind of syslog to use \(syslogd-ng or old-style syslog\) + End-of-Here + content_regex => qr{^(syslog-ng|syslogd|rsyslog)$}, + content_descr => 'allowed: syslog-ng, syslogd, rsyslog', + default => 'rsyslog', + }, + 'syslog::host' => { + applies_to_systems => 1, + applies_to_clients => 1, + description => unshiftHereDoc(<<' End-of-Here'), + name or IP-address of host where syslog shall be sent to + End-of-Here + content_regex => undef, + content_descr => 'a hostname or an IP address', + default => undef, + }, + 'syslog::port' => { + applies_to_systems => 1, + applies_to_clients => 1, + description => unshiftHereDoc(<<' End-of-Here'), + port number (UDP) where syslog shall be sent to + End-of-Here + content_regex => undef, + content_descr => 'a port number', + default => 514, + }, + 'syslog::file' => { + applies_to_systems => 1, + applies_to_clients => 1, + description => unshiftHereDoc(<<' End-of-Here'), + name of file where all log messages shall be written + End-of-Here + content_regex => undef, + content_descr => 'a complete file path', + default => '/var/log/messages', + }, + }; +} + +sub installationPhase +{ + my $self = shift; + my $info = shift; + + $self->{pluginRepositoryPath} = $info->{'plugin-repo-path'}; + $self->{pluginTempPath} = $info->{'plugin-temp-path'}; + $self->{openslxBasePath} = $info->{'openslx-base-path'}; + $self->{openslxConfigPath} = $info->{'openslx-config-path'}; + $self->{attrs} = $info->{'plugin-attrs'}; + + # We are going to change some of the stage1 attributes during installation + # (basically we are filling the ones that are not defined). Since the result + # of these changes might change between invocations, we do not want to store + # the resulting values, but we want to store the original (undef). + # In order to do so, we copy all stage1 attributes directly into the + # object hash and change them there. + $self->{kind} = lc($self->{attrs}->{'syslog::kind'}); + + my $engine = $self->{'os-plugin-engine'}; + + if ($self->{kind} eq 'rsyslog' && !isInPath($self->{distro}->getBinaryName('rsyslog'))) { + $engine->installPackages($self->{distro}->getPackageName('rsyslog')); + } + + if ($self->{kind} eq 'syslog-ng' && !isInPath('syslog-ng')) { + $engine->installPackages($self->{distro}->getPackageName($self->{distro}->getBinaryName('syslog-ng'))); + } + + # not sure if we ever should setup this service + if ($self->{kind} eq 'syslogd' && !isInPath($self->{distro}->getBinaryName('syslogd'))) { + $engine->installPackages($self->{distro}->getPackageName('syslogd')); + } + + if (!$self->{kind}) { + if (qx{which $self->{distro}->getBinaryName('rsyslog')}) { + $self->{kind} = 'rsyslog'; + } + elsif (qx{which $self->{distro}->getBinaryName('syslog-ng')}) { + $self->{kind} = 'syslog-ng'; + } + elsif (qx{which $self->{distro}->getBinaryName('syslogd')}) { + $self->{kind} = 'syslogd'; + } + else { + die _tr( + "no syslog daemon available, plugin 'syslog' wouldn't work!" + ); + } + print _tr("selecting %s as syslog kind\n", $self->{kind}); + } + + # start to actually do something - according to current stage1 attributes + if ($self->{kind} eq 'rsyslog') { + $self->_setupRsyslog($self->{attrs}); + } + elsif ($self->{kind} eq 'syslog-ng') { + $self->_setupSyslogNG($self->{attrs}); + } + elsif ($self->{kind} eq 'syslogd') { + $self->_setupSyslogd($self->{attrs}); + } + else { + die _tr( + 'unknown kind "%s" given, only "rsyslog", "syslog-ng" and "syslogd" are supported!', + $self->{kind} + ); + } + + return; +} + +sub removalPhase +{ + my $self = shift; + my $info = shift; + + return; +} + +sub _setupRsyslog +{ + my $self = shift; + my $attrs = shift; + + my $repoPath = $self->{pluginRepositoryPath}; + + my $kind = lc($attrs->{'syslog::kind'}); + my $rlInfo = $self->{distro}->runlevelInfo($kind); + + my $conf = unshiftHereDoc(<<" End-of-Here"); + #!/bin/sh + # written by OpenSLX-plugin 'syslog' + + testmkd /mnt/var/run/rsyslog + rllinker $rlInfo->{scriptName} $rlInfo->{startAt} $rlInfo->{stopAt} + + End-of-Here + spitFile("$repoPath/syslog.sh", $conf); + + return; +} + +sub _setupSyslogNG +{ + my $self = shift; + my $attrs = shift; + + my $repoPath = $self->{pluginRepositoryPath}; + + my $kind = lc($attrs->{'syslog::kind'}); + my $rlInfo = $self->{distro}->runlevelInfo($kind); + + my $conf = unshiftHereDoc(<<" End-of-Here"); + #!/bin/sh + # written by OpenSLX-plugin 'syslog' + + cat >/mnt/etc/syslog-ng/syslog-ng.conf <>/mnt/etc/syslog-ng/syslog-ng.conf <>/mnt/etc/syslog-ng/syslog-ng.conf <{scriptName} $rlInfo->{startAt} $rlInfo->{stopAt} + + End-of-Here + spitFile("$repoPath/syslog.sh", $conf); + + return; +} + +sub _setupSyslogd +{ + my $self = shift; + my $attrs = shift; + + my $repoPath = $self->{pluginRepositoryPath}; + + my $kind = lc($attrs->{'syslog::kind'}); + my $rlInfo = $self->{distro}->runlevelInfo($kind); + + my $conf = unshiftHereDoc(<<' End-of-Here'); + #!/bin/sh + # written by OpenSLX-plugin 'syslog' + + cat >/mnt/etc/syslog.conf </mnt/etc/syslog.conf </mnt/etc/syslog.conf <{scriptName} $rlInfo->{startAt} $rlInfo->{stopAt} + + End-of-Here + spitFile("$repoPath/syslog.sh", $conf); + + return; +} + +1; -- cgit v1.2.3-55-g7522