Skip to content

Commit

Permalink
Merge pull request #11 from pbenas/devel
Browse files Browse the repository at this point in the history
subprocesses and restapi server based on flask
  • Loading branch information
Filip Pytloun committed Jan 27, 2015
2 parents bfed615 + 069b844 commit 462f3e2
Show file tree
Hide file tree
Showing 7 changed files with 432 additions and 799 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ It doesn't have much dependencies, follow instructions bellow to install them:

With PIP:

pip install psutil PyAML argparse simplejson
pip install psutil PyAML argparse simplejson setproctitle Flask-RESTful

Or install packages from your distribution repository.

Expand All @@ -75,7 +75,7 @@ Usage
### Smoker Daemon (smokerd)
Configuration can be done in two different ways:

* final configuration in single/multiple yaml files (if GENCONFIG option is 0, this is default), simply edit `/etc/smokerd/smokerd.yaml`
* final configuration in single/multiple yaml files (if GENCONFIG option is 0, this is default), simply create `/etc/smokerd/smokerd.yaml`
* generated configuration from directories (eg. for easier Puppet deploy) by init script (see structure bellow)

```
Expand Down Expand Up @@ -120,7 +120,7 @@ When Smoker is started this way, it doesn't log into syslog. Standard and error
#### Manual start
Use following command to start smokerd in foreground with verbose output:

/usr/local/bin/smokerd.py -v -fg
/usr/bin/smokerd.py -v -fg

This is very good for testing and development purposees.

Expand Down
2 changes: 1 addition & 1 deletion etc/smokerd-example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ plugins:
Enabled: True
# This Python module, class Plugin, method run()
# will be executed to get result
Module: smoker.plugins.uname
Module: smoker.server.plugins.uname

# Inherits default parameters
ConnectorZendesk3:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
],
'platforms' : ['POSIX'],
'provides' : ['smoker'],
'install_requires' : ['PyYAML', 'argparse', 'simplejson', 'psutil'],
'install_requires' : ['PyYAML', 'argparse', 'simplejson', 'psutil', 'setproctitle', 'Flask-RESTful'],
}

setup(**params)
37 changes: 18 additions & 19 deletions smoker/server/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
lg = logging.getLogger('smokerd.daemon')

from smoker.server.plugins import PluginManager
from smoker.server.httpserver import ThreadedHTTPServer, HTTPHandler
from smoker.server.restserver import RestServer

import yaml

Expand All @@ -16,7 +16,7 @@
import os

import signal
import select
import time

class Smokerd(object):
"""
Expand Down Expand Up @@ -48,13 +48,6 @@ def __init__(self, **kwargs):

self._load_config()

# Catch SIGINT and SIGTERM if supported
if hasattr(signal, 'SIGINT'):
signal.signal(signal.SIGINT, self._shutdown)

if hasattr(signal, 'SIGTERM'):
signal.signal(signal.SIGTERM, self._shutdown)

def _yaml_include(self, loader, node):
"""
Include another yaml file from main file
Expand Down Expand Up @@ -156,20 +149,25 @@ def run(self):

lg.info("Starting webserver on %(bind_host)s:%(bind_port)s" % self.conf)
try:
self.server = ThreadedHTTPServer((self.conf['bind_host'], self.conf['bind_port']), HTTPHandler, self)
try:
self.server.serve_forever()
except select.error as e:
# Suppress exception during shutdown
# (4, 'Interrupted system call')
pass
except KeyboardInterrupt:
lg.info("Interrupted")
self.server = RestServer(self.conf['bind_host'], self.conf['bind_port'], self)
self.server.start()
except Exception as e:
lg.error("Can't start HTTP server: %s" % e)
lg.exception(e)
self._shutdown(exitcode=1)

# Catch SIGINT and SIGTERM if supported
if hasattr(signal, 'SIGINT'):
signal.signal(signal.SIGINT, self._shutdown)

if hasattr(signal, 'SIGTERM'):
signal.signal(signal.SIGTERM, self._shutdown)
# API server loop now runs in a separate process and we don't want
# to terminate to keep an instance of pluginmanager
while True:
time.sleep(1)


def stop(self):
"""
Kill running daemon
Expand Down Expand Up @@ -265,7 +263,8 @@ def _shutdown(self, signum=None, frame=None, exitcode=0, exception=False):
try:
# Shutdown webserver
if self.server:
self.server.socket.close()
self.server.terminate()
self.server.join()

# Shutdown pluginmanager and all plugins
if self.pluginmgr:
Expand Down
Loading

0 comments on commit 462f3e2

Please sign in to comment.