#!/usr/bin/python
import sys
import os
import subprocess

def main(args):
  contents = args[2]
  hostname = os.environ['REMOTE_HOST'].lower()
  f = file('/etc/conserver/conf.d/'+hostname, 'w')
  f.write(contents)
  f.close()
  p = subprocess.Popen(['/usr/sbin/invoke-rc.d', 'conserver-server', 'reload'],
                       stdout=subprocess.PIPE)
  p.wait()
  return 0

if __name__ == '__main__':
  sys.exit(main(sys.argv))
