diff options
author | Lars Wirzenius <liw@liw.fi> | 2017-04-02 14:30:36 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2017-04-02 14:30:36 +0300 |
commit | dc01099e0346c831f27009b7cd9d2c34b75593fe (patch) | |
tree | d12f8cc2ae81a4108ef31c0f34e9ef20324b517a | |
parent | 67820bd260bbad934885b8223aa863dba5e09341 (diff) | |
download | distixapi-dc01099e0346c831f27009b7cd9d2c34b75593fe.tar.gz |
Add dummy distix-backend
-rwxr-xr-x | distix-backend | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/distix-backend b/distix-backend new file mode 100755 index 0000000..559ff9d --- /dev/null +++ b/distix-backend @@ -0,0 +1,45 @@ +#!/usr/bin/env python2 + + +import os +import random +import sys + +import bottle + + +@bottle.route('/') +def root(): + return 'This is the root' + +@bottle.route('/version') +def version(): + return { 'version': '1.0' } + + +# Command line args. + +pid_file = sys.argv[1] +port_file = sys.argv[2] + + + +log_file = open('log', 'a') +def log(msg): + log_file.write('{} {}\n'.format(os.getpid(), msg)) + log_file.flush() + + +# Write pid to named file. + +with open(pid_file, 'w') as f: + f.write('{}\n'.format(os.getpid())) + + +# Pick a random port and write it to named file. +port = random.randint(1025, 32767) +with open(port_file, 'w') as f: + f.write('{}\n'.format(port)) + + +bottle.run(port=port, quiet=True) |