diff options
-rw-r--r-- | whatmaps/debiandistro.py | 10 | ||||
-rw-r--r-- | whatmaps/distro.py | 8 |
2 files changed, 15 insertions, 3 deletions
diff --git a/whatmaps/debiandistro.py b/whatmaps/debiandistro.py index 4a3d0db..3a47d50 100644 --- a/whatmaps/debiandistro.py +++ b/whatmaps/debiandistro.py @@ -26,7 +26,7 @@ except ImportError: lsb_release = None import logging -import string +import os import subprocess import sys @@ -35,7 +35,7 @@ from . debianpkg import DebianPkg from . pkg import PkgError class DebianDistro(Distro): - "Debian (dpkg) based distribution""" + "Debian (dpkg) based distribution" id = 'Debian' _pkg_services = { 'apache2-mpm-worker': [ 'apache2' ], @@ -73,9 +73,15 @@ class DebianDistro(Distro): @classmethod def restart_service_cmd(klass, name): + """The command that should be used to start a service""" return ['invoke-rc.d', name, 'restart'] @classmethod + def is_service_installed(klass, name): + """Whether the system has this service""" + return os.path.exists('/etc/init.d/%s' % name) + + @classmethod def has_apt(klass): return True diff --git a/whatmaps/distro.py b/whatmaps/distro.py index e4f417f..5625955 100644 --- a/whatmaps/distro.py +++ b/whatmaps/distro.py @@ -49,12 +49,18 @@ class Distro(object): subprocess.call(klass.restart_service_cmd(service)) @classmethod + def is_service_installed(klass, service): + """Check wether a service exists on the system""" + return True + + @classmethod def pkg_services(klass, pkg): """ List of services that package pkg needs restarted that aren't part of pkg itself """ - return klass._pkg_services.get(pkg.name, []) + return [ s for s in klass._pkg_services.get(pkg.name, []) + if klass.is_service_installed(s) ] @classmethod def pkg_service_blacklist(klass, pkg): |