Move commands into cmd
Change-Id: Ieb51e4af8ce88b725d8bf9c2753757261e39fea6
This commit is contained in:
parent
8cb3549b0c
commit
6f8133341b
@ -28,7 +28,7 @@ warnerrors = True
|
|||||||
|
|
||||||
[entry_points]
|
[entry_points]
|
||||||
console_scripts =
|
console_scripts =
|
||||||
turbo-hipster = turbo_hipster.worker_server:main
|
turbo-hipster = turbo_hipster.cmd.server:main
|
||||||
turbo-hipster-analyse = turbo_hipster.analyse_historical:main
|
turbo-hipster-analyse = turbo_hipster.analyse_historical:main
|
||||||
turbo-hipster-report = turbo_hipster.report_historical:main
|
turbo-hipster-report = turbo_hipster.report_historical:main
|
||||||
turbo-hipster-queue-logger = turbo_hipster.queue_logger:main
|
turbo-hipster-queue-logger = turbo_hipster.queue_logger:main
|
||||||
|
0
turbo_hipster/cmd/__init__.py
Normal file
0
turbo_hipster/cmd/__init__.py
Normal file
62
turbo_hipster/cmd/server.py
Normal file
62
turbo_hipster/cmd/server.py
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
#!/usr/bin/python2
|
||||||
|
#
|
||||||
|
# Copyright 2013 Rackspace Australia
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
# a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# License for the specific language governing permissions and limitations
|
||||||
|
# under the License.
|
||||||
|
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import daemon
|
||||||
|
import extras
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from turbo_hipster import worker_server
|
||||||
|
|
||||||
|
# as of python-daemon 1.6 it doesn't bundle pidlockfile anymore
|
||||||
|
# instead it depends on lockfile-0.9.1 which uses pidfile.
|
||||||
|
PID_FILE_MODULE = extras.try_imports(['daemon.pidlockfile', 'daemon.pidfile'])
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument('-c', '--config',
|
||||||
|
default=
|
||||||
|
'/etc/turbo-hipster/config.json',
|
||||||
|
help='Path to json config file.')
|
||||||
|
parser.add_argument('-b', '--background', action='store_true',
|
||||||
|
help='Run as a daemon in the background.')
|
||||||
|
parser.add_argument('-p', '--pidfile',
|
||||||
|
default='/var/run/turbo-hipster/'
|
||||||
|
'turbo-hipster-worker-server.pid',
|
||||||
|
help='PID file to lock during daemonization.')
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
with open(args.config, 'r') as config_stream:
|
||||||
|
config = json.load(config_stream)
|
||||||
|
|
||||||
|
server = worker_server.Server(config)
|
||||||
|
|
||||||
|
if args.background:
|
||||||
|
pidfile = PID_FILE_MODULE.TimeoutPIDLockFile(args.pidfile, 10)
|
||||||
|
with daemon.DaemonContext(pidfile=pidfile):
|
||||||
|
server.main()
|
||||||
|
else:
|
||||||
|
server.main()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
sys.path.insert(0, os.path.abspath(
|
||||||
|
os.path.join(os.path.dirname(__file__), '../')))
|
||||||
|
main()
|
@ -18,10 +18,6 @@
|
|||||||
""" worker_server.py is an executable worker server that loads and runs
|
""" worker_server.py is an executable worker server that loads and runs
|
||||||
task_plugins. """
|
task_plugins. """
|
||||||
|
|
||||||
import argparse
|
|
||||||
import daemon
|
|
||||||
import extras
|
|
||||||
import json
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import signal
|
import signal
|
||||||
@ -29,10 +25,6 @@ import sys
|
|||||||
|
|
||||||
import worker_manager
|
import worker_manager
|
||||||
|
|
||||||
# as of python-daemon 1.6 it doesn't bundle pidlockfile anymore
|
|
||||||
# instead it depends on lockfile-0.9.1 which uses pidfile.
|
|
||||||
PID_FILE_MODULE = extras.try_imports(['daemon.pidlockfile', 'daemon.pidfile'])
|
|
||||||
|
|
||||||
|
|
||||||
class Server(object):
|
class Server(object):
|
||||||
|
|
||||||
@ -125,36 +117,3 @@ class Server(object):
|
|||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print "Ctrl + C: asking tasks to exit nicely...\n"
|
print "Ctrl + C: asking tasks to exit nicely...\n"
|
||||||
self.exit_handler(signal.SIGINT)
|
self.exit_handler(signal.SIGINT)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
parser = argparse.ArgumentParser()
|
|
||||||
parser.add_argument('-c', '--config',
|
|
||||||
default=
|
|
||||||
'/etc/turbo-hipster/config.json',
|
|
||||||
help='Path to json config file.')
|
|
||||||
parser.add_argument('-b', '--background', action='store_true',
|
|
||||||
help='Run as a daemon in the background.')
|
|
||||||
parser.add_argument('-p', '--pidfile',
|
|
||||||
default='/var/run/turbo-hipster/'
|
|
||||||
'turbo-hipster-worker-server.pid',
|
|
||||||
help='PID file to lock during daemonization.')
|
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
with open(args.config, 'r') as config_stream:
|
|
||||||
config = json.load(config_stream)
|
|
||||||
|
|
||||||
server = Server(config)
|
|
||||||
|
|
||||||
if args.background:
|
|
||||||
pidfile = PID_FILE_MODULE.TimeoutPIDLockFile(args.pidfile, 10)
|
|
||||||
with daemon.DaemonContext(pidfile=pidfile):
|
|
||||||
server.main()
|
|
||||||
else:
|
|
||||||
server.main()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
sys.path.insert(0, os.path.abspath(
|
|
||||||
os.path.join(os.path.dirname(__file__), '../')))
|
|
||||||
main()
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user