#!/usr/bin/env python

import sys
import os.path
root_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
sys.path.insert(0, root_path)

import os
import os.path
import sapi

app_path = os.path.abspath(os.path.join(os.path.dirname(sapi.__file__), '..'))
os.chdir(app_path)

import subprocess
cmd = ['gunicorn', '-c', 'sapi/resources/data/gunicorn.conf.prod', 'sapi.wsgi:wsgi']
p = subprocess.Popen(cmd)
r = p.wait()
if r != 0:
    raise EnvironmentError("Gunicorn launch failed.")
