def restart():
    print('Restarting nginx:', end=' ')
    try:
        sudo.nginx('-p', CONF_DIR, '-c',
                   os.path.join(CONF_DIR, 'nginx.conf'),
                   '-s', 'stop')
    except ErrorReturnCode:
        pass  # ignore
    finally:
        try:
            sh.nginx('-p', CONF_DIR, '-c',
                     os.path.join(CONF_DIR, 'nginx.conf'))
        except ErrorReturnCode:
            print(colored('failed', 'red', attrs=['bold']) + '.')
        else:
            print(colored('nginx', 'green', attrs=['bold']) + '.')
Esempio n. 2
0
File: ng.py Progetto: fohnwind/fae
    def save(self):
        if self.name and self.ip:
            os.chdir('/home/fohnwind/ng/conf/')
            filename = self.name + "." + DefaultConfig.SITE_NAME + ".conf"

            fp = open(filename, 'w')

            conf = Template(filename="ngconf.default").render(ip=self.ip, name=self.name)

            print >> fp, conf
            fp.close()

            nginx("-s","reload")

            return True

        return False
Esempio n. 3
0
    def Proxy(self):
        ngx_user_conf = os.path.join(Config.PROXY_DIR, self.name) + '.conf'
        ngx_conf_content = r'''server {
    listen 80;
    server_name %s;
    index index.htm index.html index.php index.jsp;
    location / {
        proxy_pass http://%s:%s/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}''' %(self.dn, self.ip, int(self.port))
        with open(ngx_user_conf, 'w') as f:
            f.write(ngx_conf_content)
        from sh import nginx
        nginx('-s', 'reload')
Esempio n. 4
0
    def Proxy(self):
        ngx_user_conf = os.path.join(Config.PROXY_DIR, self.name) + '.conf'
        ngx_conf_content = r'''server {
    listen 80;
    server_name %s;
    index index.htm index.html index.php index.jsp;
    location / {
        proxy_pass http://%s:%s/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}''' % (self.dn, self.ip, int(self.port))
        with open(ngx_user_conf, 'w') as f:
            f.write(ngx_conf_content)
        from sh import nginx
        nginx('-s', 'reload')
Esempio n. 5
0
 def stop(self):
     self.print("Stopping server")
     sh.nginx("-s", 'stop')
Esempio n. 6
0
 def reload(self):
     self.print("Reloading server")
     sh.nginx("-s", 'reload')
Esempio n. 7
0
 def start(self):
     self.print("Starting server")
     sh.nginx("-g", 'daemon off;')