summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorSebastian Schmelzer2008-12-15 13:46:25 +0100
committerSebastian Schmelzer2008-12-15 13:46:25 +0100
commit3b70275febad55d69b2180f8bc373f43a65c6fb6 (patch)
tree3d87866db1fab6f58bba256963d8c0d040878a5b /lib
parent * added descriptions (diff)
downloadcore-3b70275febad55d69b2180f8bc373f43a65c6fb6.tar.gz
core-3b70275febad55d69b2180f8bc373f43a65c6fb6.tar.xz
core-3b70275febad55d69b2180f8bc373f43a65c6fb6.zip
git-svn-id: http://svn.openslx.org/svn/openslx/openslx/trunk@2407 95ad53e4-c205-0410-b2fa-d234c58c8868
Diffstat (limited to 'lib')
-rw-r--r--lib/OpenSLX/DistroUtils.pm9
-rw-r--r--lib/OpenSLX/DistroUtils/Base.pm55
-rw-r--r--lib/OpenSLX/DistroUtils/Engine.pm2
-rw-r--r--lib/OpenSLX/DistroUtils/InitFile.pm56
-rw-r--r--lib/OpenSLX/DistroUtils/Suse.pm23
-rw-r--r--lib/OpenSLX/DistroUtils/Ubuntu.pm88
6 files changed, 220 insertions, 13 deletions
diff --git a/lib/OpenSLX/DistroUtils.pm b/lib/OpenSLX/DistroUtils.pm
index 454ffbd3..82c85bfa 100644
--- a/lib/OpenSLX/DistroUtils.pm
+++ b/lib/OpenSLX/DistroUtils.pm
@@ -33,6 +33,7 @@ $VERSION = 1.01;
@EXPORT = qw(
newInitFile
getInitFileForDistro
+ simpleInitFile
);
@@ -42,6 +43,14 @@ sub newInitFile {
}
+sub simpleInitFile {
+ my $config = shift;
+ my $initFile = OpenSLX::DistroUtils::InitFile->new();
+
+ return $initFile->simpleSetup($config);
+}
+
+
sub getInitFileForDistro {
my $initFile = shift;
my $distroName = shift;
diff --git a/lib/OpenSLX/DistroUtils/Base.pm b/lib/OpenSLX/DistroUtils/Base.pm
index e5993694..e7e4f367 100644
--- a/lib/OpenSLX/DistroUtils/Base.pm
+++ b/lib/OpenSLX/DistroUtils/Base.pm
@@ -43,16 +43,15 @@ sub _combineBlock
$output = "#";
$output .= $block->{'blockDesc'};
- $output .= "\n ";
+ $output .= "\n";
my $content = $block->{'content'};
while ( ($priority, $contentArray) = each %$content )
{
- $output .= join("\n ", @$contentArray);
- $output .= "\n ";
+ $output .= join("\n", @$contentArray);
+ $output .= "\n";
}
- $output .= "\n";
return $output;
}
@@ -84,13 +83,37 @@ sub _renderInfoBlock
);
}
+sub _insertSystemHelperFunctions
+{
+ my $self = shift;
+ my $content = shift;
+
+ # do some regex
+
+ # ubuntu:
+ # log_end_msg
+ # log_progress_msg
+ # log_daemon_msg
+ # log_action_msg
+
+ # start-stop-daemon
+
+ # suse http://de.opensuse.org/Paketbau/SUSE-Paketkonventionen/Init-Skripte
+
+ return $content;
+}
+
sub generateInitFile
{
my $self = shift;
my $initFile = shift;
+ my $block;
my $config = $initFile->{'configHash'};
+ print Dumper($initFile->{'configHash'});
+
+
$output = "#!/bin/sh\n\n";
$output .= $self->_renderInfoBlock($config);
$output .= "set -e \n\n";
@@ -103,7 +126,9 @@ sub generateInitFile
$output .= "case \"\$1\" in \n";
if (keys(%{$config->{'start'}->{'content'}}) > 0) {
$output .= " start)\n";
- $output .= $self->_combineBlock($config->{'start'});
+ $block = $self->_combineBlock($config->{'start'});
+ $block =~ s/^/ /mg;
+ $output .= $block;
$output .= " ;;\n";
} else {
# trigger error
@@ -111,7 +136,9 @@ sub generateInitFile
}
if (keys(%{$config->{'stop'}->{'content'}}) > 0) {
$output .= " stop)\n";
- $output .= $self->_combineBlock($config->{'stop'});
+ $block = $self->_combineBlock($config->{'stop'});
+ $block =~ s/^/ /mg;
+ $output .= $block;
$output .= " ;;\n";
} else {
# trigger error
@@ -119,22 +146,30 @@ sub generateInitFile
}
if (keys(%{$config->{'reload'}->{'content'}}) > 0) {
$output .= " reload)\n";
- $output .= $self->_combineBlock($config->{'relaod'});
+ $block = $self->_combineBlock($config->{'reload'});
+ $block =~ s/^/ /mg;
+ $output .= $block;
$output .= " ;;\n";
}
if (keys(%{$config->{'restart'}->{'content'}}) > 0) {
$output .= " restart)\n";
- $output .= $self->_combineBlock($config->{'restart'});
+ $block = $self->_combineBlock($config->{'restart'});
+ $block =~ s/^/ /mg;
+ $output .= $block;
$output .= " ;;\n";
}
if (keys(%{$config->{'status'}->{'content'}}) > 0) {
$output .= " status)\n";
- $output .= $self->_combineBlock($config->{'status'});
+ $block = $self->_combineBlock($config->{'status'});
+ $block =~ s/^/ /mg;
+ $output .= $block;
$output .= " ;;\n";
}
if (keys(%{$config->{'usage'}->{'content'}}) > 0) {
$output .= " *)\n";
- $output .= $self->_combineBlock($config->{'usage'});
+ $block = $self->_combineBlock($config->{'usage'});
+ $block =~ s/^/ /mg;
+ $output .= $block;
$output .= " exit 1\n";
} else {
# try to generate usage
diff --git a/lib/OpenSLX/DistroUtils/Engine.pm b/lib/OpenSLX/DistroUtils/Engine.pm
index 17b48e8f..28a4bd1d 100644
--- a/lib/OpenSLX/DistroUtils/Engine.pm
+++ b/lib/OpenSLX/DistroUtils/Engine.pm
@@ -33,9 +33,9 @@ sub loadDistro {
return 0 if !$distro; # module does not exist, try next
1;
};
-
if (!$loaded) {
$distro = instantiateClass("OpenSLX::DistroUtils::Base");
+ print ('couldnt load distro class');
}
return $distro;
}
diff --git a/lib/OpenSLX/DistroUtils/InitFile.pm b/lib/OpenSLX/DistroUtils/InitFile.pm
index 0319e73c..570126e6 100644
--- a/lib/OpenSLX/DistroUtils/InitFile.pm
+++ b/lib/OpenSLX/DistroUtils/InitFile.pm
@@ -16,6 +16,9 @@ package OpenSLX::DistroUtils::InitFile;
use strict;
use warnings;
+use OpenSLX::Basics;
+use OpenSLX::Utils;
+
sub new {
my $class = shift;
my $params = shift || {};
@@ -30,8 +33,8 @@ sub new {
sub _initialConfigHash() {
return {
'name' => "",
- 'requiredStart' => "",
- 'requiredStop' => "",
+ 'requiredStart' => "\$remote_fs",
+ 'requiredStop' => "\$remote_fs",
'defaultStart' => "2 3 4 5",
'defaultStop' => "1",
'shortDesc' => "",
@@ -56,6 +59,10 @@ sub _initialConfigHash() {
'blockDesc' => "reload: defines reload function for initscript",
'content' => {}
},
+ 'force-reload' => {
+ 'blockDesc' => "force-reload: defines force-reload function for initscript",
+ 'content' => {}
+ },
'restart' => {
'blockDesc' => "restart: defines restart function for initscript",
'content' => {}
@@ -100,6 +107,51 @@ sub setDesc {
return $self;
}
+sub addScript {
+ my $self = shift;
+ my $name = shift;
+ my $script = shift;
+ my $flags = shift || {};
+ my $block = $flags->{block} || 'start';
+ my $required = $flags->{required} || 1;
+ my $errormsg = $flags->{errormsg} || "$name failed!";
+ my $priority = $flags->{priority} || 5;
+
+ push(@{$self->{'configHash'}->{'highlevelConfig'}},
+ {
+ name => $name,
+ script => $script,
+ block => $block,
+ required => $required,
+ priority => $priority,
+ errormsg => $errormsg,
+ type => 'script'
+ });
+ return 1;
+}
+
+sub addDaemon {
+ my $self = shift;
+ my $binary = shift;
+ my $parameters = shift || "";
+ my $flags = shift || {};
+ my $required = $flags->{required} || 1;
+ my $desc = $flags->{desc} || "$binary";
+ my $errormsg = $flags->{errormsg} || "$desc failed!";
+ my $priority = $flags->{priority} || 5;
+
+ push(@{$self->{'configHash'}->{'highlevelConfig'}},
+ {
+ binary => $binary,
+ parameters => $parameters,
+ desc => $desc,
+ errormsg => $errormsg,
+ required => $required,
+ priority => $priority,
+ type => 'daemon'
+ });
+ return 1;
+}
1; \ No newline at end of file
diff --git a/lib/OpenSLX/DistroUtils/Suse.pm b/lib/OpenSLX/DistroUtils/Suse.pm
new file mode 100644
index 00000000..9bf52eb4
--- /dev/null
+++ b/lib/OpenSLX/DistroUtils/Suse.pm
@@ -0,0 +1,23 @@
+# 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/
+# -----------------------------------------------------------------------------
+# Suse.pm
+# - provides suse specific functions for distro based utils for OpenSLX
+# -----------------------------------------------------------------------------
+package OpenSLX::DistroUtils::Suse;
+
+use strict;
+use warnings;
+
+use base qw(OpenSLX::DistroUtils::Base);
+
+# need to be implemented..
+
+1; \ No newline at end of file
diff --git a/lib/OpenSLX/DistroUtils/Ubuntu.pm b/lib/OpenSLX/DistroUtils/Ubuntu.pm
new file mode 100644
index 00000000..dceae7e4
--- /dev/null
+++ b/lib/OpenSLX/DistroUtils/Ubuntu.pm
@@ -0,0 +1,88 @@
+# 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/
+# -----------------------------------------------------------------------------
+# Ubuntu.pm
+# - provides ubuntu specific functions for distro based utils for OpenSLX
+# -----------------------------------------------------------------------------
+package OpenSLX::DistroUtils::Ubuntu;
+
+use strict;
+use warnings;
+use Switch;
+
+use base qw(OpenSLX::DistroUtils::Base);
+
+sub _renderHighlevelConfig {
+ my $self = shift;
+ my $initFile = shift;
+
+ my $element;
+ my $hlc = $initFile->{'configHash'}->{'highlevelConfig'};
+
+ while ( $element = shift(@$hlc)){
+ switch ($element->{type}) {
+ case 'daemon' {
+ $element->{binary} =~ m/\/([^\/]*)$/;
+ my $shortname = $1;
+ my $tpl = "export %s_PARAMS=\"%s\" \n";
+ $tpl .= "[ -f /etc/default/%s ] . /etc/default/%s \n";
+ $initFile->addToBlock('head',
+ sprintf(
+ $tpl,
+ uc($shortname),
+ $element->{parameters},
+ $shortname,
+ $shortname
+ )
+ );
+
+
+ $tpl = "start-stop-daemon --start --quiet --oknodo ";
+ $tpl .= "--pidfile /var/run/%s.pid --exec %s -- \$%s_PARAMS \n";
+ $tpl .= "log_end_msg \$?";
+ $initFile->addToBlock('start',
+ sprintf(
+ $tpl,
+ $shortname,
+ $element->{binary},
+ uc($shortname)
+ )
+ );
+
+ $tpl = "start-stop-daemon --stop --quiet --oknodo ";
+ $tpl .= "--pidfile /var/run/%s.pid \n";
+ $tpl .= "log_end_msg \$?";
+ $initFile->addToBlock('stop',
+ sprintf(
+ $tpl,
+ $shortname
+ )
+ );
+
+
+ }
+ }
+ }
+
+}
+
+sub generateInitFile
+{
+ my $self = shift;
+ my $initFile = shift;
+
+ $initFile->addToBlock('head', '#ubuntu test');
+
+ $self->_renderHighlevelConfig($initFile);
+
+ return $self->SUPER::generateInitFile($initFile);
+}
+
+1; \ No newline at end of file