diff options
author | Lars Wirzenius <liw@liw.fi> | 2017-04-16 16:55:59 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2017-04-16 16:55:59 +0300 |
commit | dd7c2ad79e469ac36d45577457c2e9a8f9ffaa7f (patch) | |
tree | dbba998b8ab61e2d4be3a32ec1944fa7326aaeca | |
parent | d1b1cf62e613390845e9f97f8cb38d1af20618ef (diff) | |
download | distixapi-dd7c2ad79e469ac36d45577457c2e9a8f9ffaa7f.tar.gz |
Allow user to set fixed port
-rwxr-xr-x | distix-backend | 15 |
1 files 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() |