diff --git a/Makefile b/Makefile index 8d26d8ba9..9ab77cbeb 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,7 @@ default: config dirs template css docs all: default predepend: - sudo sh -c "apt-get install augeas-tools libpython2.7 pandoc psmisc python2.7 python-augeas python-passlib python-bcrypt python-bjsonrpc python-cheetah python-cherrypy3 python-simplejson python-contract sudo" + sudo sh -c "apt-get install augeas-tools libpython2.7 pandoc psmisc python2.7 python-augeas python-passlib python-bcrypt python-bjsonrpc python-cheetah python-cherrypy3 python-simplejson python-contract python-django sudo" git submodule init git submodule update touch predepend diff --git a/plinth.py b/plinth.py index d4f17f601..2d10aa089 100755 --- a/plinth.py +++ b/plinth.py @@ -12,6 +12,7 @@ from cherrypy.process.plugins import Daemonizer Daemonizer(cherrypy.engine).subscribe() import plugin_mount +import service import util as u from logger import Logger @@ -177,6 +178,9 @@ def setup(): cherrypy.engine.signal_handler.subscribe() def main(): + # Initialize basic services + service.init() + setup() cherrypy.engine.start() diff --git a/service.py b/service.py new file mode 100644 index 000000000..e310eceea --- /dev/null +++ b/service.py @@ -0,0 +1,73 @@ +# +# This file is part of Plinth. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# + +""" +Framework for working with servers and theirs services +""" + +from gettext import gettext as _ + +import django.dispatch + +ENABLED = django.dispatch.Signal(providing_args=['service_id', 'enabled']) + +SERVICES = {} + + +class Service(object): + """ + Representation of an application service provided by the machine + containing information such as current status and ports required + for operation. + """ + + def __init__(self, service_id, name, ports=None, enabled=True): + if not ports: + ports = [service_id] + + self.service_id = service_id + self.name = name + self.ports = ports + self._enabled = enabled + + # Maintain a complete list of services + SERVICES[service_id] = self + + def is_enabled(self): + """Return whether the service is enabled""" + if callable(self._enabled): + return self._enabled() + + return self._enabled + + def notify_enabled(self, sender, enabled): + """Notify observers about change in state of service""" + if not callable(self._enabled): + self._enabled = enabled + + ENABLED.send_robust(sender=sender, service_id=self.service_id, + enabled=enabled) + + +def init(): + """Register some misc. services that don't fit elsewhere""" + Service('http', _('Web Server'), ['http'], True) + Service('https', _('Web Server over Secure Socket Layer'), + ['https'], True) + Service('ssh', _('Secure Shell (SSH) Server'), ['ssh'], True) + Service('plinth', _('FreedomBox Web Interface (Plinth)'), + ['https'], True)