summaryrefslogtreecommitdiffstats
path: root/src/lib/OpenSLX/DistroUtils
diff options
context:
space:
mode:
authorSebastian Schmelzer2010-09-02 17:50:49 +0200
committerSebastian Schmelzer2010-09-02 17:50:49 +0200
commit416ab8a37f1b07dc9f6c0fb3ff1a8ff2036510b5 (patch)
tree4715f7d742fec50931017f38fe6ff0a89d4ceccc /src/lib/OpenSLX/DistroUtils
parentFix for the problem reported on the list (sed filter forgotten for the (diff)
downloadcore-416ab8a37f1b07dc9f6c0fb3ff1a8ff2036510b5.tar.gz
core-416ab8a37f1b07dc9f6c0fb3ff1a8ff2036510b5.tar.xz
core-416ab8a37f1b07dc9f6c0fb3ff1a8ff2036510b5.zip
change dir structure
Diffstat (limited to 'src/lib/OpenSLX/DistroUtils')
-rw-r--r--src/lib/OpenSLX/DistroUtils/Base.pm429
-rw-r--r--src/lib/OpenSLX/DistroUtils/Engine.pm58
-rw-r--r--src/lib/OpenSLX/DistroUtils/InitFile.pm232
-rw-r--r--src/lib/OpenSLX/DistroUtils/Suse.pm174
-rw-r--r--src/lib/OpenSLX/DistroUtils/Ubuntu.pm172
5 files changed, 1065 insertions, 0 deletions
diff --git a/src/lib/OpenSLX/DistroUtils/Base.pm b/src/lib/OpenSLX/DistroUtils/Base.pm
new file mode 100644
index 00000000..f9e6b13b
--- /dev/null
+++ b/src/lib/OpenSLX/DistroUtils/Base.pm
@@ -0,0 +1,429 @@
+# Copyright (c) 2008, 2009 - 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/
+# -----------------------------------------------------------------------------
+# DistroUtils.pm
+# - provides base for distro based utils for OpenSLX
+# -----------------------------------------------------------------------------
+package OpenSLX::DistroUtils::Base;
+
+use Data::Dumper;
+use OpenSLX::Utils;
+use Clone qw(clone);
+use Switch;
+
+use strict;
+use warnings;
+
+sub new
+{
+ my $class = shift;
+ my $self = {};
+ return bless $self, $class;
+}
+
+sub dumpInit
+{
+ my $self = shift;
+ my $initFile = shift;
+
+ print Dumper($initFile->{'configHash'});
+
+ print $self->generateInitFile($initFile);
+}
+
+sub _concatContent
+{
+ my $self = shift;
+ my $block = shift;
+
+ my $output;
+
+ $output = "#";
+ $output .= $block->{'blockDesc'};
+ $output .= "\n";
+
+ my $content = $block->{'content'};
+ while ( my ($priority, $contentArray) = each %$content )
+ {
+ $output .= join("\n", @$contentArray);
+ $output .= "\n";
+ }
+
+ return $output;
+}
+
+sub _renderInfoBlock
+{
+ my $self = shift;
+ my $config = shift;
+
+ my $tpl = unshiftHereDoc(<<' End-of-Here');
+ ### BEGIN INIT INFO
+ # Provides: %s
+ # Required-Start: %s
+ # Required-Stop: %s
+ # Default-Start: %s
+ # Default-Stop: %s
+ # Short-Description: %s
+ ### END INIT INFO
+
+ End-of-Here
+
+ return sprintf(
+ $tpl,
+ $config->{'name'},
+ $config->{'requiredStart'},
+ $config->{'requiredStop'},
+ $config->{'defaultStart'},
+ $config->{'defaultStop'},
+ $config->{'shortDesc'}
+ );
+}
+
+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 _renderHighlevelConfig
+{
+ my $self = shift;
+ my $initFile = shift;
+
+ my $element;
+ my $hlc = $initFile->{'configHash'}->{'highlevelConfig'};
+
+ while ( $element = shift(@$hlc)){
+ switch ($element->{type}) {
+ case 'daemon' {
+ my $tpl;
+ $tpl = "%s_BIN=%s \n";
+ $tpl .= "[ -x %s_BIN ] || exit 5\n\n";
+ $tpl .= "%s_OPTS=\"%s\" \n";
+ $tpl .= "[ -f /etc/sysconfig/%s ] . /etc/sysconfig/%s \n\n";
+ $tpl .= "[ -f /etc/default/%s ] . /etc/default/%s \n\n";
+ $tpl .= "%s_PIDFILE=\"/var/run/%s.init.pid\" \n\n";
+ $initFile->addToBlock('head',
+ sprintf(
+ $tpl,
+ uc($element->{shortname}),
+ $element->{binary},
+ uc($element->{shortname}),
+ uc($element->{shortname}),
+ $element->{parameters},
+ $element->{shortname},
+ $element->{shortname},
+ $element->{shortname},
+ $element->{shortname},
+ uc($element->{shortname}),
+ $element->{shortname}
+ ),
+ $element->{priority}
+ );
+
+ $tpl = "echo -n \"Starting %s \"\n";
+ $tpl .= "startproc -f -p \$%s_PIDFILE \$%s_BIN \$%s_OPTS\n";
+ $tpl .= "rc_status -v";
+ $initFile->addToCase('start',
+ sprintf(
+ $tpl,
+ $element->{desc},
+ uc($element->{shortname}),
+ uc($element->{shortname}),
+ uc($element->{shortname})
+ ),
+ $element->{priority}
+ );
+
+ $tpl = "echo -n \"Shutting down %s\" \n";
+ $tpl .= "killproc -p \$%s_PIDFILE -TERM \$%s_BIN\n";
+ $tpl .= "rc_status -v";
+ $initFile->addToCase('stop',
+ sprintf(
+ $tpl,
+ $element->{desc},
+ uc($element->{shortname}),
+ uc($element->{shortname})
+ ),
+ 10 - $element->{priority}
+ );
+
+ $tpl = "## Stop the service and if this succeeds (i.e. the \n";
+ $tpl .= "## service was running before), start it again.\n";
+ $tpl .= "\$0 status >/dev/null && \$0 restart\n\n";
+ $tpl .= "# Remember status and be quiet\n";
+ $tpl .= "rc_status";
+ $initFile->addToCase('try-restart',
+ $tpl,
+ $element->{priority}
+ );
+
+ $tpl = "## Stop the service and regardless of whether it was \n";
+ $tpl .= "## running or not, start it again.\n";
+ $tpl .= "\$0 stop\n";
+ $tpl .= "\$0 start\n\n";
+ $tpl .= "# Remember status and be quiet\n";
+ $tpl .= "rc_status";
+ $initFile->addToCase('restart',
+ $tpl,
+ $element->{priority}
+ );
+
+ $tpl = "echo -n \"Reload service %s\"\n";
+ $tpl .= "killproc -p \$%s_PIDFILE -HUP \$%s_BIN\n";
+ $tpl .= "rc_status -v";
+ $initFile->addToCase('reload',
+ sprintf(
+ $tpl,
+ $element->{desc},
+ uc($element->{shortname}),
+ uc($element->{shortname}),
+ uc($element->{shortname})
+ ),
+ $element->{priority}
+ );
+
+ $tpl = "echo -n \"Checking for service %s\"\n";
+ $tpl .= "checkproc -p \$%s_PIDFILE \$%s_BIN\n";
+ $tpl .= "rc_status -v";
+ $initFile->addToCase('status',
+ sprintf(
+ $tpl,
+ $element->{desc},
+ uc($element->{shortname}),
+ uc($element->{shortname})
+ ),
+ $element->{priority}
+ );
+
+
+ }
+ case 'function' {
+ my $tpl;
+ $tpl = "%s () { \n";
+ $tpl .= "%s";
+ $tpl .= "\n}\n";
+ $initFile->addToBlock('functions',
+ sprintf(
+ $tpl,
+ $element->{name},
+ $element->{script}
+ )
+ );
+
+ }
+ case 'functionCall' {
+ my $tpl;
+ $tpl = "%s %s\n";
+ #$tpl .= "%s\n ";
+ $initFile->addToCase($element->{block},
+ sprintf(
+ $tpl,
+ $element->{function},
+ $element->{parameters},
+ ""
+ ),
+ $element->{priority}
+ );
+
+ }
+ }
+ }
+
+}
+
+
+sub _getInitsystemIncludes
+{
+ return "\n";
+}
+
+sub _renderCasePrefix
+{
+ return "\n";
+}
+
+sub _renderFooter
+{
+ return "exit 0\n";
+}
+
+sub _generateUsage
+{
+ my $self = shift;
+ my $usage = shift;
+ my $tpl;
+
+ $tpl = "## print out usage \n";
+ $tpl .= "echo \"Usage: \$0 {%s}\" >&2 \n";
+ $tpl .= "exit 1";
+
+ return sprintf(
+ $tpl,
+ $usage
+ );
+}
+
+sub _getAuthorBlock
+{
+ my $tpl;
+
+ $tpl = "# Copyright (c) 2009 - OpenSLX GmbH \n";
+ $tpl .= "# \n";
+ $tpl .= "# This program is free software distributed under the GPL version 2. \n";
+ $tpl .= "# See http://openslx.org/COPYING \n";
+ $tpl .= "# \n";
+ $tpl .= "# If you have any feedback please consult http://openslx.org/feedback and \n";
+ $tpl .= "# send your suggestions, praise, or complaints to feedback\@openslx.org \n";
+ $tpl .= "# \n";
+ $tpl .= "# General information about OpenSLX can be found at http://openslx.org/ \n";
+ $tpl .= "# -----------------------------------------------------------------------------\n";
+ $tpl .= "# §filename§ \n";
+ $tpl .= "# - §desc§ \n";
+ $tpl .= "# §generated§ \n";
+ $tpl .= "# -----------------------------------------------------------------------------\n\n";
+
+ return sprintf(
+ $tpl
+ );
+}
+
+sub generateInitFile
+{
+ my $self = shift;
+ my $initFile = shift;
+ my $content;
+ my @usage;
+
+ # get a copy of initFile object before modifying it..
+ my $initFileCopy = clone($initFile);
+
+ $self->_renderHighlevelConfig($initFileCopy);
+
+ my $config = $initFileCopy->{'configHash'};
+ my $output;
+
+ # head
+ $output = "#!/bin/sh\n";
+ $output .= $self->_getAuthorBlock();
+ $output .= $self->_renderInfoBlock($config);
+ $output .= $self->_getInitsystemIncludes();
+
+ if (keys(%{$config->{'blocks'}->{'head'}->{'content'}}) > 0) {
+ $output .= $self->_concatContent($config->{'blocks'}->{'head'});
+ }
+
+ # functions
+ if (keys(%{$config->{'blocks'}->{'functions'}->{'content'}}) > 0) {
+ $output .= $self->_concatContent($config->{'blocks'}->{'functions'});
+ }
+
+ # case block
+ $output .= $self->_renderCasePrefix();
+ $output .= "\ncase \"\$1\" in \n";
+
+ # get caseBlocks in defined order
+ my @blocks = sort{
+ $config->{'caseBlocks'}->{$a}->{'order'} <=>
+ $config->{'caseBlocks'}->{$b}->{'order'}
+ }
+ keys(%{$config->{'caseBlocks'}});
+
+ # case block
+ while (@blocks)
+ {
+ my $block= shift(@blocks);
+ if (keys(%{$config->{'caseBlocks'}->{$block}->{'content'}}) > 0) {
+ push(@usage, $block);
+ $output .= " $block)\n";
+ $content = $self->_concatContent($config->{'caseBlocks'}->{$block});
+ $content =~ s/^/ /mg;
+ $output .= $content;
+ $output .= " ;;\n";
+ } else {
+ if ($config->{'caseBlocks'}->{$block}->{'required'}) {
+ print "required block $block undefined";
+ }
+ }
+ }
+
+ # autogenerate usage
+ if (scalar(grep(/usage/, @usage)) == 0) {
+ $initFileCopy->addToCase(
+ 'usage',
+ $self->_generateUsage(join(', ',@usage))
+ );
+
+ $output .= " *)\n";
+ $content = $self->_concatContent($config->{'caseBlocks'}->{'usage'});
+ $content =~ s/^/ /mg;
+ $output .= $content;
+ $output .= " ;;\n";
+
+ }
+
+ # footer
+ $output .= "esac\n\n";
+ $output .= $self->_renderFooter();
+
+ return $output;
+
+}
+
+sub getKernelVersion
+{
+ my $self = shift;
+ my $kernelPath = shift;
+
+
+ my $newestKernelFile;
+ my $newestKernelFileSortKey = '';
+ my $kernelPattern = '{vmlinuz,kernel-genkernel-x86}-*';
+ foreach my $kernelFile (glob("$kernelPath/$kernelPattern")) {
+ next unless $kernelFile =~ m{
+ (?:vmlinuz|x86)-(\d+)\.(\d+)\.(\d+)(?:\.(\d+))?-(\d+(?:\.\d+)?)
+ }x;
+ my $sortKey
+ = sprintf("%02d.%02d.%02d.%02d-%2.1f", $1, $2, $3, $4||0, $5);
+ if ($newestKernelFileSortKey lt $sortKey) {
+ $newestKernelFile = $kernelFile;
+ $newestKernelFileSortKey = $sortKey;
+ }
+ }
+
+ if (!defined $newestKernelFile) {
+ die; #_tr("unable to pick a kernel-file from path '%s'!", $kernelPath);
+ }
+
+ $newestKernelFile =~ /.*?-([.\-0-9]*)-([a-zA-Z]*?)$/;
+ my $kernel = {};
+ $kernel->{'version'} = $1;
+ $kernel->{'suffix'} = $2;
+ return $kernel;
+
+}
+
+
+1;
diff --git a/src/lib/OpenSLX/DistroUtils/Engine.pm b/src/lib/OpenSLX/DistroUtils/Engine.pm
new file mode 100644
index 00000000..16c3e585
--- /dev/null
+++ b/src/lib/OpenSLX/DistroUtils/Engine.pm
@@ -0,0 +1,58 @@
+# Copyright (c) 2008, 2009 - 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/
+# -----------------------------------------------------------------------------
+# Engine.pm
+# - provides engine to distro based utils for OpenSLX
+# -----------------------------------------------------------------------------
+package OpenSLX::DistroUtils::Engine;
+
+use OpenSLX::Basics;
+
+use strict;
+use warnings;
+
+sub new
+{
+ my $class = shift;
+ my $self = {};
+ return bless $self, $class;
+}
+
+
+sub loadDistro {
+ my $self = shift;
+ my $distroName = shift;
+ $distroName = ucfirst($distroName);
+
+ my $distro;
+
+ my $loaded = eval {
+ $distro = instantiateClass("OpenSLX::DistroUtils::${distroName}");
+ return 0 if !$distro; # module does not exist, try next
+ 1;
+ };
+
+ if (!$loaded) {
+ vlog(1, "can't find distro specific class, try base class..");
+ $loaded = eval {
+ $distro = instantiateClass("OpenSLX::DistroUtils::Base");
+ return 0 if !$distro; # module does not exist, try next
+ 1;
+ };
+ }
+
+ if (!$loaded) {
+ vlog(1, "failed to load DistroUtils!");
+ }
+
+ return $distro;
+}
+
+1;
diff --git a/src/lib/OpenSLX/DistroUtils/InitFile.pm b/src/lib/OpenSLX/DistroUtils/InitFile.pm
new file mode 100644
index 00000000..ab729959
--- /dev/null
+++ b/src/lib/OpenSLX/DistroUtils/InitFile.pm
@@ -0,0 +1,232 @@
+# Copyright (c) 2008, 2009 - 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/
+# -----------------------------------------------------------------------------
+# InitFile.pm
+# - configuration object for runlevel script
+# -----------------------------------------------------------------------------
+package OpenSLX::DistroUtils::InitFile;
+
+use strict;
+use warnings;
+
+use OpenSLX::Basics;
+use OpenSLX::Utils;
+
+sub new {
+ my $class = shift;
+ my $params = shift || {};
+ my $self = {
+ };
+
+ $self->{'configHash'} = _initialConfigHash();
+
+ return bless $self, $class;
+}
+
+sub _initialConfigHash() {
+ return {
+ 'name' => "",
+ 'requiredStart' => "\$remote_fs",
+ 'requiredStop' => "\$remote_fs",
+ 'defaultStart' => "2 3 4 5",
+ 'defaultStop' => "1",
+ 'shortDesc' => "",
+ 'blocks' => {
+ 'head' => {
+ 'blockDesc' => "head: file existing checks, etc.",
+ 'content' => {}
+ },
+ 'functions' => {
+ 'blockDesc' => "functions: helper functions",
+ 'content' => {}
+ }
+ },
+ 'caseBlocks' => {
+ 'start' => {
+ 'blockDesc' => "start: defines start function for initscript",
+ 'content' => {},
+ 'order' => 1,
+ 'required' => 1
+ },
+ 'stop' => {
+ 'blockDesc' => "stop: defines stop function for initscript",
+ 'content' => {},
+ 'order' => 2,
+ 'required' => 1
+ },
+ 'reload' => {
+ 'blockDesc' => "reload: defines reload function for initscript",
+ 'content' => {},
+ 'order' => 3,
+ 'required' => 0
+ },
+ 'force-reload' => {
+ 'blockDesc' => "force-reload: defines force-reload function for initscript",
+ 'content' => {},
+ 'order' => 4,
+ 'required' => 0
+ },
+ 'restart' => {
+ 'blockDesc' => "restart: defines restart function for initscript",
+ 'content' => {},
+ 'order' => 5,
+ 'required' => 1
+ },
+ 'try-restart' => {
+ 'blockDesc' => "restart: defines restart function for initscript",
+ 'content' => {},
+ 'order' => 6,
+ 'required' => 0
+ },
+ 'status' => {
+ 'blockDesc' => "status: defines status function for initscript",
+ 'content' => {},
+ 'order' => 7,
+ 'required' => 0
+ },
+ 'usage' => {
+ 'blockDesc' => "usage: defines usage function for initscript",
+ 'content' => {},
+ 'order' => 8,
+ 'required' => 0
+ }
+ }
+ };
+}
+
+sub addToCase {
+ my $self = shift;
+ my $blockName = shift;
+ my $content = shift;
+ my $priority = shift || 5;
+
+ #check if block is valid..
+
+ push(@{$self->{'configHash'}->{'caseBlocks'}->{$blockName}->{'content'}->{$priority}}, $content);
+
+ return $self;
+}
+
+sub addToBlock {
+ my $self = shift;
+ my $blockName = shift;
+ my $content = shift;
+ my $priority = shift || 5;
+
+ #check if block is valid..
+
+ push(@{$self->{'configHash'}->{'blocks'}->{$blockName}->{'content'}->{$priority}}, $content);
+
+ return $self;
+}
+
+sub setName {
+ my $self = shift;
+ my $name = shift;
+
+ $self->{'configHash'}->{'name'} = $name;
+ return $self;
+}
+
+sub setDesc {
+ my $self = shift;
+ my $desc = shift;
+
+ $self->{'configHash'}->{'shortDesc'} = $desc;
+ return $self;
+}
+
+sub addFunction {
+ my $self = shift;
+ my $name = shift;
+ my $script = shift;
+ my $flags = shift || {};
+ my $priority = $flags->{priority} || 5;
+
+ push(@{$self->{'configHash'}->{'highlevelConfig'}},
+ {
+ name => $name,
+ script => $script,
+ priority => $priority,
+ type => 'function'
+ });
+ return 1;
+}
+
+sub addFunctionCall {
+ my $self = shift;
+ my $function = shift;
+ my $block = shift;
+ my $flags = shift;
+ my $priority = $flags->{priority} || 5;
+ my $parameters = $flags->{parameters} || "";
+
+ push(@{$self->{'configHash'}->{'highlevelConfig'}},
+ {
+ function => $function,
+ block => $block,
+ parameters => $parameters,
+ priority => $priority,
+ type => 'functionCall'
+ });
+ return 1;
+}
+
+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;
+ $binary =~ m/\/([^\/]*)$/;
+ my $shortname = $1;
+ my $parameters = shift || "";
+ my $flags = shift || {};
+ my $required = $flags->{required} || 1;
+ my $desc = $flags->{desc} || "$shortname";
+ my $errormsg = $flags->{errormsg} || "$desc failed!";
+ my $priority = $flags->{priority} || 5;
+
+ push(@{$self->{'configHash'}->{'highlevelConfig'}},
+ {
+ binary => $binary,
+ shortname => $shortname,
+ parameters => $parameters,
+ desc => $desc,
+ errormsg => $errormsg,
+ required => $required,
+ priority => $priority,
+ type => 'daemon'
+ });
+ return 1;
+}
+
+
+1;
diff --git a/src/lib/OpenSLX/DistroUtils/Suse.pm b/src/lib/OpenSLX/DistroUtils/Suse.pm
new file mode 100644
index 00000000..8a41c2eb
--- /dev/null
+++ b/src/lib/OpenSLX/DistroUtils/Suse.pm
@@ -0,0 +1,174 @@
+# Copyright (c) 2008, 2009 - 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 Switch;
+
+use base qw(OpenSLX::DistroUtils::Base);
+
+
+sub _renderCasePrefix
+{
+ return "rc_reset\n";
+}
+
+sub _renderFooter
+{
+ return "rc_exit\n";
+}
+
+
+sub _renderHighlevelConfig {
+ my $self = shift;
+ my $initFile = shift;
+
+ my $element;
+ my $hlc = $initFile->{'configHash'}->{'highlevelConfig'};
+
+ while ( $element = shift(@$hlc)){
+ switch ($element->{type}) {
+ case 'daemon' {
+ my $tpl;
+ $tpl = "%s_BIN=%s \n";
+ $tpl .= "[ -x %s_BIN ] || exit 5\n\n";
+ $tpl .= "%s_OPTS=\"%s\" \n";
+ $tpl .= "[ -f /etc/sysconfig/%s ] . /etc/sysconfig/%s \n\n";
+ $tpl .= "%s_PIDFILE=\"/var/run/%s.init.pid\" \n\n";
+ $initFile->addToBlock('head',
+ sprintf(
+ $tpl,
+ uc($element->{shortname}),
+ $element->{binary},
+ uc($element->{shortname}),
+ uc($element->{shortname}),
+ $element->{parameters},
+ $element->{shortname},
+ $element->{shortname},
+ uc($element->{shortname}),
+ $element->{shortname}
+ )
+ );
+
+ $tpl = "echo -n \"Starting %s \"\n";
+ $tpl .= "startproc -f -p \$%s_PIDFILE \$%s_BIN \$%s_OPTS\n";
+ $tpl .= "rc_status -v";
+ $initFile->addToCase('start',
+ sprintf(
+ $tpl,
+ $element->{desc},
+ uc($element->{shortname}),
+ uc($element->{shortname}),
+ uc($element->{shortname})
+ )
+ );
+
+ $tpl = "echo -n \"Shutting down %s\" \n";
+ $tpl .= "killproc -p \$%s_PIDFILE -TERM \$%s_BIN\n";
+ $tpl .= "rc_status -v";
+ $initFile->addToCase('stop',
+ sprintf(
+ $tpl,
+ $element->{desc},
+ uc($element->{shortname}),
+ uc($element->{shortname})
+ )
+ );
+
+ $tpl = "## Stop the service and if this succeeds (i.e. the \n";
+ $tpl .= "## service was running before), start it again.\n";
+ $tpl .= "\$0 status >/dev/null && \$0 restart\n\n";
+ $tpl .= "# Remember status and be quiet\n";
+ $tpl .= "rc_status";
+ $initFile->addToCase('try-restart',
+ $tpl
+ );
+
+ $tpl = "## Stop the service and regardless of whether it was \n";
+ $tpl .= "## running or not, start it again.\n";
+ $tpl .= "\$0 stop\n";
+ $tpl .= "\$0 start\n\n";
+ $tpl .= "# Remember status and be quiet\n";
+ $tpl .= "rc_status";
+ $initFile->addToCase('restart',
+ $tpl
+ );
+
+ $tpl = "echo -n \"Reload service %s\"\n";
+ $tpl .= "killproc -p \$%s_PIDFILE -HUP \$%s_BIN\n";
+ $tpl .= "rc_status -v";
+ $initFile->addToCase('reload',
+ sprintf(
+ $tpl,
+ $element->{desc},
+ uc($element->{shortname}),
+ uc($element->{shortname}),
+ uc($element->{shortname})
+ )
+ );
+
+ $tpl = "echo -n \"Checking for service %s\"\n";
+ $tpl .= "checkproc -p \$%s_PIDFILE \$%s_BIN\n";
+ $tpl .= "rc_status -v";
+ $initFile->addToCase('status',
+ sprintf(
+ $tpl,
+ $element->{desc},
+ uc($element->{shortname}),
+ uc($element->{shortname})
+ )
+ );
+
+
+ }
+ case 'function' {
+ my $tpl;
+ $tpl = "%s () { \n";
+ $tpl .= "%s";
+ $tpl .= "\n}\n";
+ $initFile->addToBlock('functions',
+ sprintf(
+ $tpl,
+ $element->{name},
+ $element->{script}
+ )
+ );
+
+ }
+ case 'functionCall' {
+ my $tpl;
+ $tpl = "%s %s\n";
+ #$tpl .= "%s\n ";
+ $initFile->addToCase($element->{block},
+ sprintf(
+ $tpl,
+ $element->{function},
+ $element->{parameters},
+ ""
+ ),
+ $element->{priority}
+ );
+
+ }
+ }
+ }
+}
+
+sub _getInitsystemIncludes
+{
+ return ". /etc/rc.status\n\n";
+}
+
+1; \ No newline at end of file
diff --git a/src/lib/OpenSLX/DistroUtils/Ubuntu.pm b/src/lib/OpenSLX/DistroUtils/Ubuntu.pm
new file mode 100644
index 00000000..915c19c6
--- /dev/null
+++ b/src/lib/OpenSLX/DistroUtils/Ubuntu.pm
@@ -0,0 +1,172 @@
+# Copyright (c) 2008, 2009 - 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 _getInitsystemIncludes
+{
+ return ". /lib/lsb/init-functions\n\n";
+}
+
+sub _renderCasePrefix
+{
+ return "";
+}
+
+sub _renderFooter
+{
+ return "exit 0\n";
+}
+
+
+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 .= "if [ -f /etc/default/%s ]; then . /etc/default/%s; fi \n";
+ $initFile->addToBlock('head',
+ sprintf(
+ $tpl,
+ uc($shortname),
+ $element->{parameters},
+ $shortname,
+ $shortname
+ )
+ );
+
+
+ $tpl = "log_daemon_msg \"Starting %s\" \"%s\" \n";
+ $tpl .= "start-stop-daemon --start --quiet --oknodo ";
+ $tpl .= "--pidfile /var/run/%s.pid --exec %s -- \$%s_PARAMS \n";
+ $tpl .= "log_end_msg \$?";
+ $initFile->addToCase('start',
+ sprintf(
+ $tpl,
+ $element->{description},
+ $shortname,
+ $shortname,
+ $element->{binary},
+ uc($shortname)
+ )
+ );
+
+ $tpl = "start-stop-daemon --stop --quiet --oknodo ";
+ $tpl .= "--pidfile /var/run/%s.pid \n";
+ $tpl .= "log_end_msg \$?";
+ $initFile->addToCase('stop',
+ sprintf(
+ $tpl,
+ $shortname
+ )
+ );
+
+ $tpl = "log_daemon_msg \"Restarting %s\" \"%s\"\n";
+ $tpl .= "\$0 stop\n";
+ $tpl .= "case \"\$?\" in\n";
+ $tpl .= " 0|1)\n";
+ $tpl .= " \$0 start\n";
+ $tpl .= " case \"\$?\" in\n";
+ $tpl .= " 0) log_end_msg 0 ;;\n";
+ $tpl .= " 1) log_end_msg 1 ;; # Old process is still running\n";
+ $tpl .= " *) log_end_msg 1 ;; # Failed to start\n";
+ $tpl .= " esac\n";
+ $tpl .= " ;;\n";
+ $tpl .= " *)\n";
+ $tpl .= " # Failed to stop\n";
+ $tpl .= " log_end_msg 1\n";
+ $tpl .= " ;;\n";
+ $tpl .= "esac\n";
+ $tpl .= ";;\n";
+
+ $initFile->addToCase('restart',
+ sprintf(
+ $tpl,
+ $shortname
+ )
+ );
+
+
+ $tpl = "start-stop-daemon --stop --signal 1 --quiet ";
+ $tpl .= "--pidfile /var/run/%s.pid --name \$s\n";
+ $tpl .= "return 0\n";
+ $initFile->addToCase('reload',
+ sprintf(
+ $tpl,
+ $shortname,
+ $element->{binary}
+ )
+ );
+
+ $tpl = "status_of_proc -p /var/run/%s.pid %s_BIN %s && exit 0 || exit \$?";
+ $initFile->addToCase('status',
+ sprintf(
+ $tpl,
+ $element->{shortname},
+ $element->{binary},
+ $element->{shortname}
+ )
+ );
+
+
+ }
+ case 'function' {
+ my $tpl;
+ $tpl = "%s () { \n";
+ $tpl .= "%s";
+ $tpl .= "\n}\n";
+ $initFile->addToBlock('functions',
+ sprintf(
+ $tpl,
+ $element->{name},
+ $element->{script}
+ )
+ );
+
+ }
+ case 'functionCall' {
+ my $tpl;
+ $tpl = "%s %s\n";
+ #$tpl .= "%s\n ";
+ $initFile->addToCase($element->{block},
+ sprintf(
+ $tpl,
+ $element->{function},
+ $element->{parameters},
+ ""
+ ),
+ $element->{priority}
+ );
+
+ }
+
+ }
+ }
+
+}
+
+1; \ No newline at end of file