Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
supervisor
#!/bin/bash
# next package does not valid supervisor : system starting problem
dpkg -l | egrep "\<supervisor\>" >/dev/null 2>/dev/null
if [ $? -ne 0 ]; then
sudo apt-get update
sudo apt-get install supervisor
fi
grep "\[inet_http_server\]" /etc/supervisor/supervisord.conf >/dev/null 2>/dev/null
if [ $? -ne 0 ];then
cp -f /etc/supervisor/supervisord.conf /tmp/supervisord.conf
echo "
[inet_http_server]
port = 0.0.0.0:9001
username = future
password = future_01
" >> /tmp/supervisord.conf
sudo mv -f /tmp/supervisord.conf /etc/supervisor/supervisord.conf
sudo chown root:root /etc/supervisor/supervisord.conf
fi
sudo mkdir -p /opt/log
sudo cp -f *.py /opt
sudo service supervisor stop
sudo rm -f /etc/supervisor/conf.d/*.conf
sudo cp -f *.conf /etc/supervisor/conf.d
sudo service supervisor start
#!/usr/bin/env python
#coding=utf8
import os
import sys
import time
import xmlrpclib
pid = os.getpid()
##########################################################################################
def do_client(port):
svcurl = "http://localhost:%d/TestSvc" % port
print "[%d] xmlrpc_client service_url=%s" % (pid, svcurl)
proxy = xmlrpclib.ServerProxy(svcurl)
cnt=3
print "[%d] TestSvc.ping(%d)=%s" % (pid, cnt, proxy.ping(pid, cnt))
for i in xrange(4):
err_cause = i % 2 == 1
print "TestSvc.err_func(%s)=%s" % (err_cause, proxy.err_func(pid, err_cause))
##########################################################################################
def usage():
sys.stderr.write("usage: %s port\n" % sys.argv[0])
sys.exit(9)
##########################################################################################
if __name__=='__main__':
if len(sys.argv) != 2:
usage()
port = int(sys.argv[1])
do_client(port)
#!/usr/bin/env python
#coding=utf8
"""
====================================
:mod: 테스트용 non-blocking XML-RPC 서버
====================================
.. moduleauthor:: 채문창 <mcchae@gmail.com>
.. note:: GNU
설명
=====
테스트용 non-blocking XML-RPC 서버
"""
##########################################################################################
import os
import sys
import time
import signal
import datetime
from SimpleXMLRPCServer import SimpleXMLRPCServer, SimpleXMLRPCRequestHandler
now=datetime.datetime.now
##########################################################################################
class TestSvc(object):
def ping(self, pid, _sleep=0):
for i in xrange(_sleep):
print "{%s} [%d] %d" % (now(), pid, i)
time.sleep(1)
return True
def err_func(self, pid, err_cause=True):
if err_cause:
sys.stderr.write('{%s} [%d] err_func: error\n'%(now(),pid))
else:
sys.stdout.write('{%s} [%d] err_func: not error\n'%(now(),pid))
return err_cause
@staticmethod
def receive_signal(signum, stack):
"""시그널 핸들러
.. warning:: 외부에서 직접 호출되지 않고 run() 에서 핸들러 지정
"""
S2N = dict((getattr(signal, n), n) for n in dir(signal)
if n.startswith('SIG') and '_' not in n )
if signum in [signal.SIGTERM, signal.SIGHUP, signal.SIGINT] or self.foreground:
sys.stderr.write('{%s} Caught signal %s, exiting.\n' %(now(), S2N[signum]))
sys.exit()
else:
sys.stderr.write('{%s} Caught unknown signal %s, ignoring.' %(now(), S2N[signum]))
##########################################################################################
def doSvc(port):
print "{%s} [%d] doSvc(port=%d) starting..." % (now(), os.getpid(), port)
PYPATH = os.getenv('PYTHONPATH')
if not PYPATH:
sys.stderr.write('{%s} Invalid PYTHONPATH Error\n' %(now()))
sys.exit(1)
else:
sys.stdout.write('{%s} PYTHONPATH="%s"\n' %(now(), PYPATH))
mgr = TestSvc()
signal.signal(signal.SIGTERM, TestSvc.receive_signal)
signal.signal(signal.SIGHUP, TestSvc.receive_signal)
signal.signal(signal.SIGINT, TestSvc.receive_signal)
from SocketServer import ThreadingMixIn
class SimpleThreadXMLRPCServer(ThreadingMixIn, SimpleXMLRPCServer):
pass
class RequestHandler(SimpleXMLRPCRequestHandler):
rpc_paths = ('/TestSvc')
server = SimpleThreadXMLRPCServer(('0.0.0.0', port),
requestHandler=RequestHandler,
logRequests=False,
allow_none=True,
)
server.register_introspection_functions()
server.register_instance(mgr)
print "{%s} [%d] doSvc before serve_forever..." % (now(), os.getpid())
server.serve_forever()
##########################################################################################
def usage():
sys.stderr.write("usage: %s port\n" % sys.argv[0])
sys.exit(9)
##########################################################################################
if __name__=='__main__':
if len(sys.argv) != 2:
usage()
port = int(sys.argv[1])
doSvc(port)
[program:xmlrpc_test_8997]
command=/usr/bin/python /opt/xmlrpc_server.py 8997
environment=PYTHONPATH='/opt/F3work',MYENV='another secret'
directory=/opt
autostart=true
autorestart=true
startretries=3
stderr_logfile=/opt/log/8997_stderr.log
stderr_logfile_maxbytes=10MB
stderr_logfile_backups=5
stdout_logfile=/opt/log/8997_stdout.log
stdout_logfile_maxbytes=10MB
stdout_logfile_backups=5
[program:xmlrpc_test_8998]
command=/usr/bin/python /opt/xmlrpc_server.py 8998
environment=PYTHONPATH='/opt/F3work',MYENV='another secret'
directory=/opt
autostart=true
autorestart=true
startretries=3
stderr_logfile=/opt/log/8998_stderr.log
stderr_logfile_maxbytes=10MB
stderr_logfile_backups=5
stdout_logfile=/opt/log/8998_stdout.log
stdout_logfile_maxbytes=10MB
stdout_logfile_backups=5
[program:xmlrpc_test_8999]
command=/usr/bin/python /opt/xmlrpc_server.py 8999
environment=PYTHONPATH='/opt/F3work',MYENV='another secret'
directory=/opt
autostart=true
autorestart=true
startretries=3
stderr_logfile=/opt/log/8999_stderr.log
stderr_logfile_maxbytes=10MB
stderr_logfile_backups=5
stdout_logfile=/opt/log/8999_stdout.log
stdout_logfile_maxbytes=10MB
stdout_logfile_backups=5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment