mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +00:00
Add a framework for working with services
- Basic information about each service is available for consumers - Information about whether service is enabled or disabled is available - Interested parties may listen to enabling/disabling of a service - Information about some core services are made available
This commit is contained in:
parent
3fe40c223c
commit
0f8050d031
2
Makefile
2
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
|
||||
|
||||
@ -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()
|
||||
|
||||
73
service.py
Normal file
73
service.py
Normal file
@ -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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
"""
|
||||
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)
|
||||
Loading…
x
Reference in New Issue
Block a user