From dd7c2ad79e469ac36d45577457c2e9a8f9ffaa7f Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sun, 16 Apr 2017 16:55:59 +0300 Subject: Allow user to set fixed port --- distix-backend | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/distix-backend b/distix-backend index 3172a5e..146f67f 100755 --- a/distix-backend +++ b/distix-backend @@ -49,6 +49,11 @@ class API(object): class DistixBackend(cliapp.Application): def add_settings(self): + self.settings.integer( + ['port'], + 'listen on PORT', + metavar='PORT') + self.settings.string( ['port-file'], 'pick random ports, write to FILE', @@ -66,7 +71,10 @@ class DistixBackend(cliapp.Application): def process_args(self, args): users = self.read_user_file() - port = self.pick_random_port() + if self.settings['port']: + port = self.settings['port'] + else: + port = self.pick_random_port() self.write_pid_file() api = API(users) api.run(port) @@ -85,8 +93,9 @@ class DistixBackend(cliapp.Application): def write_pid_file(self): filename = self.settings['pid-file'] - with open(filename, 'w') as f: - f.write('{}\n'.format(os.getpid())) + if filename: + with open(filename, 'w') as f: + f.write('{}\n'.format(os.getpid())) DistixBackend(version=distixapi.__version__).run() -- cgit v1.2.1