mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
Service object to handle services on a system-level
The Service object now offers handling services on a system level, and gathering information whether it's enabled or running. New methods: enable, disable, is_enabled, is_running; For this it needs the correct (system-level) service name. All of the methods can be overridden/customized. This changes all modules to the new Service object and deletes action scripts that are not required anymore.
This commit is contained in:
1 parent
9fe49f881f
commit
a9528c56d9
30 files changed
+243
-629
No files matched your search
@@ -1,59 +0,0 @@
|
||||
#!/usr/bin/python3
|
||||
#
|
||||
# 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/>.
|
||||
#
|
||||
|
||||
"""
|
||||
Configuration helper for service discovery.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
|
||||
from plinth import action_utils
|
||||
|
||||
|
||||
def parse_arguments():
|
||||
"""Return parsed command line arguments as dictionary."""
|
||||
parser = argparse.ArgumentParser()
|
||||
subparsers = parser.add_subparsers(dest='subcommand', help='Sub command')
|
||||
|
||||
subparsers.add_parser('enable', help='Enable avahi-daemon service')
|
||||
subparsers.add_parser('disable', help='Disable avahi-daemon service')
|
||||
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def subcommand_enable(_):
|
||||
"""Start service."""
|
||||
action_utils.service_enable('avahi-daemon')
|
||||
|
||||
|
||||
def subcommand_disable(_):
|
||||
"""Stop service."""
|
||||
action_utils.service_disable('avahi-daemon')
|
||||
|
||||
|
||||
def main():
|
||||
"""Parse arguments and perform all duties."""
|
||||
arguments = parse_arguments()
|
||||
|
||||
subcommand = arguments.subcommand.replace('-', '_')
|
||||
subcommand_method = globals()['subcommand_' + subcommand]
|
||||
subcommand_method(arguments)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -1,60 +0,0 @@
|
||||
#!/usr/bin/python3
|
||||
# -*- mode: python -*-
|
||||
#
|
||||
# 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/>.
|
||||
#
|
||||
|
||||
"""
|
||||
Configuration helper for date and time
|
||||
"""
|
||||
|
||||
import argparse
|
||||
|
||||
from plinth import action_utils
|
||||
|
||||
|
||||
def parse_arguments():
|
||||
"""Return parsed command line arguments as dictionary."""
|
||||
parser = argparse.ArgumentParser()
|
||||
subparsers = parser.add_subparsers(dest='subcommand', help='Sub command')
|
||||
|
||||
subparsers.add_parser('enable', help='Enable NTP service')
|
||||
subparsers.add_parser('disable', help='Disable NTP service')
|
||||
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def subcommand_enable(_):
|
||||
"""Start service."""
|
||||
action_utils.service_enable('ntp')
|
||||
|
||||
|
||||
def subcommand_disable(_):
|
||||
"""Stop service."""
|
||||
action_utils.service_disable('ntp')
|
||||
|
||||
|
||||
def main():
|
||||
"""Parse arguments and perform all duties."""
|
||||
arguments = parse_arguments()
|
||||
|
||||
subcommand = arguments.subcommand.replace('-', '_')
|
||||
subcommand_method = globals()['subcommand_' + subcommand]
|
||||
subcommand_method(arguments)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -1,59 +0,0 @@
|
||||
#!/usr/bin/python3
|
||||
#
|
||||
# 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/>.
|
||||
#
|
||||
|
||||
"""
|
||||
Configuration helper for Minetest server.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
|
||||
from plinth import action_utils
|
||||
|
||||
|
||||
def parse_arguments():
|
||||
"""Return parsed command line arguments as dictionary."""
|
||||
parser = argparse.ArgumentParser()
|
||||
subparsers = parser.add_subparsers(dest='subcommand', help='Sub command')
|
||||
|
||||
subparsers.add_parser('enable', help='Enable Minetest server')
|
||||
subparsers.add_parser('disable', help='Disable Minetest server')
|
||||
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def subcommand_enable(_):
|
||||
"""Enable and start server."""
|
||||
action_utils.service_enable('minetest-server')
|
||||
|
||||
|
||||
def subcommand_disable(_):
|
||||
"""Disable and stop server."""
|
||||
action_utils.service_disable('minetest-server')
|
||||
|
||||
|
||||
def main():
|
||||
"""Parse arguments and perform all duties."""
|
||||
arguments = parse_arguments()
|
||||
|
||||
subcommand = arguments.subcommand.replace('-', '_')
|
||||
subcommand_method = globals()['subcommand_' + subcommand]
|
||||
subcommand_method(arguments)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -1,63 +0,0 @@
|
||||
#!/usr/bin/python3
|
||||
# -*- mode: python -*-
|
||||
#
|
||||
# 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/>.
|
||||
#
|
||||
|
||||
"""
|
||||
Configuration helper for Mumble server
|
||||
"""
|
||||
|
||||
import argparse
|
||||
|
||||
from plinth import action_utils
|
||||
|
||||
|
||||
SERVICE_CONFIG = '/etc/default/mumble-server'
|
||||
|
||||
|
||||
def parse_arguments():
|
||||
"""Return parsed command line arguments as dictionary."""
|
||||
parser = argparse.ArgumentParser()
|
||||
subparsers = parser.add_subparsers(dest='subcommand', help='Sub command')
|
||||
|
||||
subparsers.add_parser('enable', help='Enable Mumble service')
|
||||
subparsers.add_parser('disable', help='Disable Mumble service')
|
||||
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def subcommand_enable(_):
|
||||
"""Start service."""
|
||||
action_utils.service_enable('mumble-server')
|
||||
|
||||
|
||||
def subcommand_disable(_):
|
||||
"""Stop service."""
|
||||
action_utils.service_disable('mumble-server')
|
||||
|
||||
|
||||
def main():
|
||||
"""Parse arguments and perform all duties."""
|
||||
arguments = parse_arguments()
|
||||
|
||||
subcommand = arguments.subcommand.replace('-', '_')
|
||||
subcommand_method = globals()['subcommand_' + subcommand]
|
||||
subcommand_method(arguments)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -98,9 +98,6 @@ def parse_arguments():
|
||||
subparsers.add_parser('is-setup', help='Return whether setup is completed')
|
||||
subparsers.add_parser('setup', help='Setup OpenVPN server configuration')
|
||||
|
||||
subparsers.add_parser('enable', help='Enable OpenVPN server')
|
||||
subparsers.add_parser('disable', help='Disable OpenVPN server')
|
||||
|
||||
get_profile = subparsers.add_parser(
|
||||
'get-profile', help='Return the OpenVPN profile of a user')
|
||||
get_profile.add_argument('username', help='User to get profile for')
|
||||
@@ -156,16 +153,6 @@ def _create_certificates():
|
||||
subprocess.check_call(['/usr/share/easy-rsa/build-dh'], **COMMON_ARGS)
|
||||
|
||||
|
||||
def subcommand_enable(_):
|
||||
"""Start OpenVPN service."""
|
||||
action_utils.service_enable('openvpn@freedombox')
|
||||
|
||||
|
||||
def subcommand_disable(_):
|
||||
"""Stop OpenVPN service."""
|
||||
action_utils.service_disable('openvpn@freedombox')
|
||||
|
||||
|
||||
def subcommand_get_profile(arguments):
|
||||
"""Return the profile for a user."""
|
||||
username = arguments.username
|
||||
|
||||
@@ -37,8 +37,6 @@ def parse_arguments():
|
||||
|
||||
subparsers.add_parser('setup',
|
||||
help='Perform Privoxy configuration setup')
|
||||
subparsers.add_parser('enable', help='Enable Privoxy service')
|
||||
subparsers.add_parser('disable', help='Disable Privoxy service')
|
||||
|
||||
return parser.parse_args()
|
||||
|
||||
@@ -63,16 +61,6 @@ def subcommand_setup(_):
|
||||
action_utils.service_restart('privoxy')
|
||||
|
||||
|
||||
def subcommand_enable(_):
|
||||
"""Start service."""
|
||||
action_utils.service_enable('privoxy')
|
||||
|
||||
|
||||
def subcommand_disable(_):
|
||||
"""Stop service."""
|
||||
action_utils.service_disable('privoxy')
|
||||
|
||||
|
||||
def main():
|
||||
"""Parse arguments and perform all duties."""
|
||||
arguments = parse_arguments()
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
#!/usr/bin/python3
|
||||
#
|
||||
# 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/>.
|
||||
#
|
||||
|
||||
"""
|
||||
Configuration helper for Quassel core.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
|
||||
from plinth import action_utils
|
||||
|
||||
|
||||
def parse_arguments():
|
||||
"""Return parsed command line arguments as dictionary."""
|
||||
parser = argparse.ArgumentParser()
|
||||
subparsers = parser.add_subparsers(dest='subcommand', help='Sub command')
|
||||
|
||||
subparsers.add_parser('enable', help='Enable Quassel core service')
|
||||
subparsers.add_parser('disable', help='Disable Quassel core service')
|
||||
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def subcommand_enable(_):
|
||||
"""Start service."""
|
||||
action_utils.service_enable('quasselcore')
|
||||
|
||||
|
||||
def subcommand_disable(_):
|
||||
"""Stop service."""
|
||||
action_utils.service_disable('quasselcore')
|
||||
|
||||
|
||||
def main():
|
||||
"""Parse arguments and perform all duties."""
|
||||
arguments = parse_arguments()
|
||||
|
||||
subcommand = arguments.subcommand.replace('-', '_')
|
||||
subcommand_method = globals()['subcommand_' + subcommand]
|
||||
subcommand_method(arguments)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -33,8 +33,6 @@ def parse_arguments():
|
||||
subparsers = parser.add_subparsers(dest='subcommand', help='Sub command')
|
||||
|
||||
subparsers.add_parser('setup', help='Configure repro')
|
||||
subparsers.add_parser('enable', help='Enable repro service')
|
||||
subparsers.add_parser('disable', help='Disable repro service')
|
||||
|
||||
return parser.parse_args()
|
||||
|
||||
@@ -61,16 +59,6 @@ def subcommand_setup(_):
|
||||
action_utils.webserver_enable('repro-plinth')
|
||||
|
||||
|
||||
def subcommand_enable(_):
|
||||
"""Start service."""
|
||||
action_utils.service_enable('repro')
|
||||
|
||||
|
||||
def subcommand_disable(_):
|
||||
"""Stop service."""
|
||||
action_utils.service_disable('repro')
|
||||
|
||||
|
||||
def main():
|
||||
"""Parse arguments and perform all duties."""
|
||||
arguments = parse_arguments()
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
#!/usr/bin/python3
|
||||
# -*- mode: python -*-
|
||||
#
|
||||
# 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/>.
|
||||
#
|
||||
|
||||
"""
|
||||
Configuration helper for reStore.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
|
||||
from plinth import action_utils
|
||||
|
||||
|
||||
def parse_arguments():
|
||||
"""Return parsed command line arguments as dictionary."""
|
||||
parser = argparse.ArgumentParser()
|
||||
subparsers = parser.add_subparsers(dest='subcommand', help='Sub command')
|
||||
|
||||
subparsers.add_parser('enable', help='Enable reStore')
|
||||
subparsers.add_parser('disable', help='Disable reStore')
|
||||
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def subcommand_enable(_):
|
||||
"""Enable reStore."""
|
||||
action_utils.service_enable('node-restore')
|
||||
|
||||
|
||||
def subcommand_disable(_):
|
||||
"""Disable reStore."""
|
||||
action_utils.service_disable('node-restore')
|
||||
|
||||
|
||||
def main():
|
||||
"""Parse arguments and perform all duties."""
|
||||
arguments = parse_arguments()
|
||||
|
||||
subcommand = arguments.subcommand.replace('-', '_')
|
||||
subcommand_method = globals()['subcommand_' + subcommand]
|
||||
subcommand_method(arguments)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in new issue
Block a user