Added solard cli for starting it + adjusted actions
Added child recycler in solard
This commit is contained in:
parent
51ba1dde80
commit
b7a412289d
@ -2,6 +2,6 @@
|
|||||||
sudo: yes
|
sudo: yes
|
||||||
tasks:
|
tasks:
|
||||||
- shell: pip install -e /vagrant/solard
|
- shell: pip install -e /vagrant/solard
|
||||||
- shell: start-stop-daemon --stop --make-pidfile --pidfile /tmp/solard.pid --chdir /vagrant/solard --startas /bin/bash -- -c "exec python /vagrant/solard/solard/tcp_server.py > /tmp/solard.log 2>&1"
|
- shell: start-stop-daemon --stop --make-pidfile --pidfile /tmp/solard.pid --chdir /vagrant/solard --startas /bin/bash -- -c "exec /usr/local/bin/solard run --port {{solard_port}} --base tcp > /tmp/solard.log 2>&1"
|
||||||
ignore_errors: True
|
ignore_errors: True
|
||||||
- shell: start-stop-daemon -b --start --make-pidfile --pidfile /tmp/solard.pid --chdir /vagrant/solard --startas /bin/bash -- -c "exec python /vagrant/solard/solard/tcp_server.py > /tmp/solard.log 2>&1"
|
- shell: start-stop-daemon -b --start --make-pidfile --pidfile /tmp/solard.pid --chdir /vagrant/solard --startas /bin/bash -- -c "exec /usr/local/bin/solard run --port {{solard_port}} --base tcp > /tmp/solard.log 2>&1"
|
||||||
|
@ -44,5 +44,8 @@ setup(
|
|||||||
packages=find_packages(),
|
packages=find_packages(),
|
||||||
zip_safe=False,
|
zip_safe=False,
|
||||||
install_requires=find_requires(),
|
install_requires=find_requires(),
|
||||||
include_package_data=True
|
include_package_data=True,
|
||||||
|
entry_points={
|
||||||
|
'console_scripts':
|
||||||
|
['solard = solard.server:cli']}
|
||||||
)
|
)
|
||||||
|
26
solard/solard/server.py
Normal file
26
solard/solard/server.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import click
|
||||||
|
|
||||||
|
@click.group()
|
||||||
|
def cli():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def validate_class(ctx, param, value):
|
||||||
|
supported = ('tcp', )
|
||||||
|
if not value in supported:
|
||||||
|
raise click.BadParameter("%r is not one of %r" % (value, supported))
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
@cli.command()
|
||||||
|
@click.option('--base', default='tcp', callback=validate_class, type=str)
|
||||||
|
@click.option('--port', default=5555, type=int)
|
||||||
|
def run(base, port):
|
||||||
|
if base == 'tcp':
|
||||||
|
from solard.tcp_server import SolardTCPServer
|
||||||
|
runner = SolardTCPServer.run_solard
|
||||||
|
runner(port)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
cli()
|
@ -20,7 +20,10 @@
|
|||||||
from SocketServer import ThreadingTCPServer, BaseRequestHandler
|
from SocketServer import ThreadingTCPServer, BaseRequestHandler
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
|
import threading
|
||||||
|
import errno
|
||||||
import msgpack
|
import msgpack
|
||||||
|
import time
|
||||||
import struct
|
import struct
|
||||||
import errno
|
import errno
|
||||||
import sys
|
import sys
|
||||||
@ -29,6 +32,7 @@ import pwd
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
from types import GeneratorType
|
from types import GeneratorType
|
||||||
|
|
||||||
from solard.logger import logger
|
from solard.logger import logger
|
||||||
from solard.core import SolardContext, SolardIface
|
from solard.core import SolardContext, SolardIface
|
||||||
from solard.tcp_core import *
|
from solard.tcp_core import *
|
||||||
@ -251,7 +255,6 @@ class SolardTCPHandler(object):
|
|||||||
class SolardReqHandler(BaseRequestHandler):
|
class SolardReqHandler(BaseRequestHandler):
|
||||||
|
|
||||||
def handle(self):
|
def handle(self):
|
||||||
close = True
|
|
||||||
sock = self.request
|
sock = self.request
|
||||||
address = self.client_address
|
address = self.client_address
|
||||||
h = SolardTCPHandler(sock, address)
|
h = SolardTCPHandler(sock, address)
|
||||||
@ -263,7 +266,7 @@ class SolardReqHandler(BaseRequestHandler):
|
|||||||
return
|
return
|
||||||
if auth_state is None:
|
if auth_state is None:
|
||||||
# child forked
|
# child forked
|
||||||
close = False
|
# we don't wait there, but in recycler
|
||||||
return
|
return
|
||||||
while True:
|
while True:
|
||||||
if not h.process():
|
if not h.process():
|
||||||
@ -290,8 +293,28 @@ class SolardTCPServer(ThreadingTCPServer):
|
|||||||
# StreamServer.__init__(self, *args, **kwargs)
|
# StreamServer.__init__(self, *args, **kwargs)
|
||||||
ThreadingTCPServer.__init__(self, *args, **kwargs)
|
ThreadingTCPServer.__init__(self, *args, **kwargs)
|
||||||
|
|
||||||
|
def dummy_recycle_childs(self):
|
||||||
|
# dummy child recycler, turns each 3 seconds
|
||||||
|
def child_recycler():
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
pid, status = os.waitpid(-1, 0)
|
||||||
|
logger.debug("Child %r ended with status=%d", pid, status)
|
||||||
|
except OSError as e:
|
||||||
|
if e.errno != errno.ECHILD:
|
||||||
|
raise
|
||||||
|
time.sleep(3)
|
||||||
|
th = threading.Thread(target=child_recycler)
|
||||||
|
th.daemon = True
|
||||||
|
th.start()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def run_solard(port):
|
||||||
|
s = SolardTCPServer(('0.0.0.0', port), SolardReqHandler)
|
||||||
|
s.dummy_recycle_childs()
|
||||||
|
return s.serve_forever()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
s = SolardTCPServer(('0.0.0.0', 5555), SolardReqHandler)
|
SolardTCPServer.run_solard(5555)
|
||||||
s.serve_forever()
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user