summaryrefslogtreecommitdiffstats
path: root/lib/OpenSLX/DistroUtils/Suse.pm
diff options
context:
space:
mode:
authorSebastian Schmelzer2008-12-15 17:32:49 +0100
committerSebastian Schmelzer2008-12-15 17:32:49 +0100
commit2c1a0999f2d765190af4ff3e5249d3bcd635e07c (patch)
treead554bcc2e9371037343386822e86c1c7f416be5 /lib/OpenSLX/DistroUtils/Suse.pm
parentgit-svn-id: http://svn.openslx.org/svn/openslx/openslx/trunk@2407 95ad53e4-c2... (diff)
downloadcore-2c1a0999f2d765190af4ff3e5249d3bcd635e07c.tar.gz
core-2c1a0999f2d765190af4ff3e5249d3bcd635e07c.tar.xz
core-2c1a0999f2d765190af4ff3e5249d3bcd635e07c.zip
git-svn-id: http://svn.openslx.org/svn/openslx/openslx/trunk@2408 95ad53e4-c205-0410-b2fa-d234c58c8868
Diffstat (limited to 'lib/OpenSLX/DistroUtils/Suse.pm')
-rw-r--r--lib/OpenSLX/DistroUtils/Suse.pm194
1 files changed, 193 insertions, 1 deletions
diff --git a/lib/OpenSLX/DistroUtils/Suse.pm b/lib/OpenSLX/DistroUtils/Suse.pm
index 9bf52eb4..d3d4ae96 100644
--- a/lib/OpenSLX/DistroUtils/Suse.pm
+++ b/lib/OpenSLX/DistroUtils/Suse.pm
@@ -15,9 +15,201 @@ package OpenSLX::DistroUtils::Suse;
use strict;
use warnings;
+use Switch;
use base qw(OpenSLX::DistroUtils::Base);
-# need to be implemented..
+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->addToBlock('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->addToBlock('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->addToBlock('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->addToBlock('restart',
+ $tpl
+ );
+
+ $tpl = "echo -n \"Reload service %s\"\n";
+ $tpl .= "killproc -p \$%s_PIDFILE -HUP \$%s_BIN\n";
+ $tpl .= "rc_status -v";
+ $initFile->addToBlock('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->addToBlock('status',
+ sprintf(
+ $tpl,
+ $element->{desc},
+ uc($element->{shortname}),
+ uc($element->{shortname})
+ )
+ );
+
+
+ }
+ }
+ }
+
+}
+
+sub generateInitFile
+{
+ my $self = shift;
+ my $initFile = shift;
+ my $block;
+
+ $self->_renderHighlevelConfig($initFile);
+
+ my $config = $initFile->{'configHash'};
+ my $output;
+
+ $output = "#!/bin/sh\n\n";
+ $output .= $self->_renderInfoBlock($config);
+ $output .= ". /etc/rc.status \n\n";
+ if (keys(%{$config->{'head'}->{'content'}}) > 0) {
+ $output .= $self->_combineBlock($config->{'head'});
+ }
+ if (keys(%{$config->{'functions'}->{'content'}}) > 0) {
+ $output .= $self->_combineBlock($config->{'functions'});
+ }
+ $output .= "rc.reset \n\n";
+ $output .= "case \"\$1\" in \n";
+ if (keys(%{$config->{'start'}->{'content'}}) > 0) {
+ $output .= " start)\n";
+ $block .= $self->_combineBlock($config->{'start'});
+ $block =~ s/^/ /mg;
+ $output .= $block;
+ $output .= " ;;\n";
+ } else {
+ # trigger error
+ # start is essential
+ }
+ if (keys(%{$config->{'stop'}->{'content'}}) > 0) {
+ $output .= " stop)\n";
+ $block = $self->_combineBlock($config->{'stop'});
+ $block =~ s/^/ /mg;
+ $output .= $block;
+ $output .= " ;;\n";
+ } else {
+ # trigger error
+ # stop is essential
+ }
+ if (keys(%{$config->{'reload'}->{'content'}}) > 0) {
+ $output .= " reload)\n";
+ $block = $self->_combineBlock($config->{'reload'});
+ $block =~ s/^/ /mg;
+ $output .= $block;
+ $output .= " ;;\n";
+ }
+ if (keys(%{$config->{'restart'}->{'content'}}) > 0) {
+ $output .= " restart)\n";
+ $block = $self->_combineBlock($config->{'restart'});
+ $block =~ s/^/ /mg;
+ $output .= $block;
+ $output .= " ;;\n";
+ }
+ if (keys(%{$config->{'try-restart'}->{'content'}}) > 0) {
+ $output .= " try-restart)\n";
+ $block = $self->_combineBlock($config->{'try-restart'});
+ $block =~ s/^/ /mg;
+ $output .= $block;
+ $output .= " ;;\n";
+ }
+ if (keys(%{$config->{'status'}->{'content'}}) > 0) {
+ $output .= " status)\n";
+ $block = $self->_combineBlock($config->{'status'});
+ $block =~ s/^/ /mg;
+ $output .= $block;
+ $output .= " ;;\n";
+ }
+ if (keys(%{$config->{'usage'}->{'content'}}) > 0) {
+ $output .= " *)\n";
+ $block = $self->_combineBlock($config->{'usage'});
+ $block =~ s/^/ /mg;
+ $output .= $block;
+ $output .= " exit 1\n";
+ } else {
+ # try to generate usage
+ # $this->_generateUsage();
+ }
+ $output .= "esac\n\n";
+ $output .= "rc_exit\n";
+ return $output;
+
+}
1; \ No newline at end of file