#!/usr/bin/env python3

import http.client

PORTS = [8668, 8669, 8670]

for port in PORTS:
    try:
        print('Terminating App Manager on port {} ...'.format(str(port)), end=' ')
        conn = http.client.HTTPConnection('localhost', port=port, timeout=0.1)
        conn.request('GET', '/stop')
        res = conn.getresponse()
        if res.status in [200, 302]:
            print('done')
        else:
            print('{} error'.format(str(res.status)))
    except:
        print('nothing')
