Skip to main content

noseapp extension for linux daemon testing

Project description

Installation

pip install noseapp_daemon

Create Runner

from noseapp.ext.daemon import DaemonRunner

class MyPythonDaemon(DaemonRunner):

    CMD_PREFIX = 'python'
    DAEMON_BIN = '/path/to/daemon/daemon.py'


my_daemon = MyPythonDaemon('my_daemon')
my_daemon.add_cmd_option('-c', '/path/to/config')
my_daemon.start()

Create daemon plugin

from noseapp.ext.daemon import DaemonPlugin


class MyPythonDaemonPlugin(DaemonPlugin):

    def init(self, daemon):
        # do something

    def before_start(self, daemon):
        # do something

    def after_start(self, daemon):
        # do something

    def before_stop(self, daemon):
        # do something

    def after_stop(self, daemon):
        # do something


my_daemon = MyPythonDaemon('my_daemon', plugin=MyPythonDaemonPlugin())

Create Service

from noseapp.ext.daemon import DaemonService

class MyDaemonService(DaemonService):

  name = 'my_service'

  def setup(self):
      self.daemon = MyPythonDaemon('my_daemon')

  def start(self):
      self.daemon.start()

  def stop(self):
      self.daemon.stop()

  ...


service = MyDaemonService()
service.start()
service.restart()

Create Management

from noseapp.ext.daemon import DaemonManagement

management = DaemonManagement(app)
management.add_daemon(
    MyPythonDaemon('my_daemon', plugin=MyPythonDaemonPlugin()),
)
daemon = management.daemon('my_daemon')

def error_handler(daemon, e):
    # do something

with management.checkout_daemon('my_daemon', except_exc=Exception, error_handler=error_handler) as daemon:
    daemon.restart()

management.add_service(MyDaemonService())
service = management.service('my_service')

# to install as extension
management.install(app)

suite = Suite(__name__, require=['my_daemon'])

# management.stop_all()
# management.stop_daemons()
# management.stop_services()
# management.restart_all()
# etc ...

Presets

noseapp.ext.daemon.presets import NGINXDaemon
noseapp.ext.daemon.presets import UWSGIDaemon
...


nginx = NGINXDaemon()
uwsgi = UWSGIDaemon()

nginx.add_cmd_option('-c', '/path/to/config')
uwsgi.add_dmd_option('--ini', '/path/to/config')

nginx.start()
uwsgi.start()
...

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

noseapp_daemon-2.3.0.tar.gz (7.8 kB view details)

Uploaded Source

File details

Details for the file noseapp_daemon-2.3.0.tar.gz.

File metadata

File hashes

Hashes for noseapp_daemon-2.3.0.tar.gz
Algorithm Hash digest
SHA256 b56864e3c7511c366329b34e72e9551d996f0baab942938c0374667187519ccd
MD5 0df2bd45bd6bdc799053787a3cf6d34e
BLAKE2b-256 bb1ccdfa8dcb71187f3756f34f0df77a989b1b16ca91a770e8407711e0774c81

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page