unlink pid file on exit, exec server in ctl script

This commit is contained in:
j 2015-03-07 13:08:26 +05:30
parent 2a7122d7fb
commit 8b23ea9658
2 changed files with 10 additions and 16 deletions

16
ctl
View file

@ -48,9 +48,7 @@ if [ "$1" == "start" ]; then
python3 oml install_update python3 oml install_update
cd "$BASE/$NAME" cd "$BASE/$NAME"
fi fi
python3 oml server $PID exec python3 oml server $PID
rm -f $PID
exit $?
fi fi
if [ "$1" == "debug" ]; then if [ "$1" == "debug" ]; then
cd "$BASE/$NAME" cd "$BASE/$NAME"
@ -59,8 +57,7 @@ if [ "$1" == "debug" ]; then
exit 1 exit 1
fi fi
shift shift
python3 oml server $@ exec python3 oml server $@
exit $?
fi fi
if [ "$1" == "stop" ]; then if [ "$1" == "stop" ]; then
test -e $PID && kill `cat $PID` test -e $PID && kill `cat $PID`
@ -89,8 +86,7 @@ if [ "$1" == "open" ]; then
fi fi
if [ "$1" == "ui" ]; then if [ "$1" == "ui" ]; then
shift shift
python3 $NAME/oml/ui.py $@ exec python3 $NAME/oml/ui.py $@
exit $?
fi fi
if [ "$1" == "update" ]; then if [ "$1" == "update" ]; then
cd "$BASE/$NAME" cd "$BASE/$NAME"
@ -114,10 +110,8 @@ fi
if [ "$1" == "python" ]; then if [ "$1" == "python" ]; then
cd "$BASE/$NAME" cd "$BASE/$NAME"
shift shift
python3 $@ exec python3 $@
exit $?
fi fi
cd "$BASE/$NAME" cd "$BASE/$NAME"
python3 oml $@ exec python3 oml $@
exit $?

View file

@ -29,7 +29,7 @@ import logging
class MainHandler(OMLHandler): class MainHandler(OMLHandler):
def get(self, path): def get(self, path):
path = os.path.join(settings.static_path, 'html/oml.html') path = os.path.join(settings.static_path, 'html', 'oml.html')
with open(path) as fd: with open(path) as fd:
content = fd.read() content = fd.read()
version = settings.MINOR_VERSION version = settings.MINOR_VERSION
@ -42,10 +42,8 @@ class MainHandler(OMLHandler):
def run(): def run():
setup.create_db() setup.create_db()
root_dir = os.path.normpath(os.path.join(os.path.abspath(os.path.dirname(__file__)), '..'))
PID = sys.argv[2] if len(sys.argv) > 2 else None PID = sys.argv[2] if len(sys.argv) > 2 else None
static_path = os.path.join(root_dir, 'static')
#FORMAT = '%(asctime)-15s %(clientip)s %(user)-8s %(message)s' #FORMAT = '%(asctime)-15s %(clientip)s %(user)-8s %(message)s'
#logging.basicConfig(format=FORMAT) #logging.basicConfig(format=FORMAT)
#logger = logging.getLogger('oml.app') #logger = logging.getLogger('oml.app')
@ -59,8 +57,8 @@ def run():
} }
handlers = [ handlers = [
(r'/(favicon.ico)', StaticFileHandler, {'path': static_path}), (r'/(favicon.ico)', StaticFileHandler, {'path': settings.static_path}),
(r'/static/(.*)', StaticFileHandler, {'path': static_path}), (r'/static/(.*)', StaticFileHandler, {'path': settings.static_path}),
(r'/(.*)/epub/(.*)', EpubHandler), (r'/(.*)/epub/(.*)', EpubHandler),
(r'/(.*?)/reader/', ReaderHandler), (r'/(.*?)/reader/', ReaderHandler),
(r'/(.*?)/pdf/', FileHandler), (r'/(.*?)/pdf/', FileHandler),
@ -116,6 +114,8 @@ def run():
if state.nodes: if state.nodes:
state.nodes.join() state.nodes.join()
http_server.stop() http_server.stop()
if PID and os.path.exists(PID):
os.unlink(PID)
signal.signal(signal.SIGTERM, shutdown) signal.signal(signal.SIGTERM, shutdown)