Example #1
0
 def post_restore(self, site, dbpasswd):
     nodejs.install_from_package(site.path, 'production', 
         {'sqlite': '/usr/bin/sqlite3', 'python': '/usr/bin/python2'})
     users.SystemUser("ghost").add()
     uid = users.get_system("ghost").uid
     for r, d, f in os.walk(site.path):
         for x in d:
             os.chown(os.path.join(r, x), uid, -1)
         for x in f:
             os.chown(os.path.join(r, x), uid, -1)
     s = services.get(site.id)
     if s:
         s.remove()
     cfg = {
             'directory': site.path,
             'user': '******',
             'command': 'node %s'%os.path.join(site.path, 'index.js'),
             'autostart': 'true',
             'autorestart': 'true',
             'environment': 'NODE_ENV="production"',
             'stdout_logfile': '/var/log/ghost.log',
             'stderr_logfile': '/var/log/ghost.log'
         }
     s = services.Service(site.id, "supervisor", cfg=cfg)
     s.add()
Example #2
0
    def post_install(self, extra_vars, dbpasswd=""):
        users.SystemUser("mailpile").add()

        st = os.stat(os.path.join(self.path, 'scripts/mailpile'))
        os.chmod(os.path.join(self.path, 'scripts/mailpile'),
                 st.st_mode | 0o111)
        cfg = {
            'directory':
            self.path,
            'user':
            '******',
            'command':
            '{0} --www=0.0.0.0:{1} --wait'.format(
                os.path.join(self.path, 'mp'), self.backend_port),
            'autostart':
            'true',
            'autorestart':
            'false',
            'stdout_logfile':
            '/var/log/mailpile.log',
            'stderr_logfile':
            '/var/log/mailpile.log'
        }
        s = services.Service(self.id, "supervisor", cfg=cfg)
        s.add()
Example #3
0
 def post_restore(self, site, dbpasswd):
     users.SystemUser("mailpile").add()
     for r, d, f in os.walk(site.path):
         for x in d:
             os.chmod(os.path.join(r, x), 0o755)
         for x in f:
             os.chmod(os.path.join(r, x), 0o644)
     services.get(site.name).enable()
Example #4
0
def setup(addr, port):
    # Make sure Radicale is installed and ready
    if not python.is_installed('Radicale'):
        python.install('radicale')
    # due to packaging bugs, make extra sure perms are readable
    st = os.stat('/usr/lib/python2.7/site-packages/radicale')
    for r, d, f in os.walk('/usr/lib/python2.7/site-packages/radicale'):
        for x in d:
            os.chmod(os.path.join(r, x),
                     st.st_mode | stat.S_IROTH | stat.S_IRGRP)
        for x in f:
            os.chmod(os.path.join(r, x),
                     st.st_mode | stat.S_IROTH | stat.S_IRGRP)
    if not os.path.exists('/etc/radicale/config'):
        if not os.path.isdir('/etc/radicale'):
            os.mkdir('/etc/radicale')
        with open('/etc/radicale/config', 'w') as f:
            f.write(default_config)
    if not os.path.isdir('/usr/lib/radicale'):
        os.mkdir('/usr/lib/radicale')
    # Add the site process
    u = users.SystemUser("radicale")
    u.add()
    g = groups.SystemGroup("radicale", users=["radicale"])
    g.add()
    wsgi_file = 'import radicale\n'
    wsgi_file += 'radicale.log.start()\n'
    wsgi_file += 'application = radicale.Application()\n'
    with open('/etc/radicale/radicale.wsgi', 'w') as f:
        f.write(wsgi_file)
    os.chmod('/etc/radicale/radicale.wsgi', 0766)
    cfg = {
        'directory': '/etc/radicale',
        'user': '******',
        'command':
        'uwsgi -s /tmp/radicale.sock -C --plugin python2 --wsgi-file radicale.wsgi',
        'stdout_logfile': '/var/log/radicale.log',
        'stderr_logfile': '/var/log/radicale.log'
    }
    s = services.Service("radicale", "supervisor", cfg=cfg)
    s.add()
    block = [
        nginx.Location(
            '/',
            nginx.Key('include', 'uwsgi_params'),
            nginx.Key('uwsgi_pass', 'unix:///tmp/radicale.sock'),
        )
    ]
    s = websites.get("radicale")
    if s: s.remove()
    s = websites.ReverseProxy(id="radicale",
                              name="Calendar/Contacts",
                              addr=addr,
                              port=port,
                              base_path="/usr/lib/radicale",
                              block=block)
    s.install()
Example #5
0
 def post_restore(self, site, dbpasswd):
     nodejs.install_from_package(site.path)
     users.SystemUser("haste").add()
     uid = users.get_system("haste").uid
     for r, d, f in os.walk(site.path):
         for x in d:
             os.chown(os.path.join(r, x), uid, -1)
         for x in f:
             os.chown(os.path.join(r, x), uid, -1)
     services.get(site.id).enable()
Example #6
0
    def post_install(self, vars, dbpasswd=""):
        users.SystemUser("mailpile").add()

        cfg = {
            'directory': self.path,
            'user': '******',
            'command': '%s --www=0.0.0.0:%s --wait' % (os.path.join(self.path, 'mp'), self.backend_port),
            'autostart': 'true',
            'autorestart': 'false',
            'stdout_logfile': '/var/log/mailpile.log',
            'stderr_logfile': '/var/log/mailpile.log'
        }
        s = services.Service(self.id, "supervisor", cfg=cfg)
        s.add()
Example #7
0
    def post_install(self, vars, dbpasswd=""):
        with open(os.path.join(self.path, 'config.js'), 'r') as f:
            d = json.loads(f.read())
        d["port"] = self.backend_port
        if d["storage"]["type"] == "redis":
            d["storage"]["type"] = "file"
            d["storage"]["path"] = "./data"
            if d["storage"].has_key("host"):
                del d["storage"]["host"]
            if d["storage"].has_key("port"):
                del d["storage"]["port"]
            if d["storage"].has_key("db"):
                del d["storage"]["db"]
            if d["storage"].has_key("expire"):
                del d["storage"]["expire"]
        with open(os.path.join(self.path, 'config.js'), 'w') as f:
            f.write(
                json.dumps(d, sort_keys=True, indent=4,
                           separators=(',', ': ')))

        nodejs.install_from_package(self.path)
        users.SystemUser("haste").add()

        # Finally, make sure that permissions are set so that Haste
        # can save its files properly.
        uid = users.get_system("haste").uid
        if not os.path.exists(os.path.join(self.path, 'data')):
            os.mkdir(os.path.join(self.path, 'data'))
        for r, d, f in os.walk(self.path):
            for x in d:
                os.chown(os.path.join(r, x), uid, -1)
            for x in f:
                os.chown(os.path.join(r, x), uid, -1)

        cfg = {
            'directory': self.path,
            'user': '******',
            'command': 'node %s' % os.path.join(self.path, 'server.js'),
            'autostart': 'true',
            'autorestart': 'true',
            'environment': 'NODE_ENV="production"',
            'stdout_logfile': '/var/log/haste.log',
            'stderr_logfile': '/var/log/haste.log'
        }
        s = services.Service(self.id, "supervisor", cfg=cfg)
        s.add()
Example #8
0
def on_load(app):
    if app.id != "syncthing":
        return
    if not users.get_system("syncthing"):
        u = users.SystemUser('syncthing')
        u.add()
    u = users.get_system('syncthing')
    if not os.path.exists("/home/syncthing"):
        os.makedirs("/home/syncthing")
        os.chown("/home/syncthing", u.uid, 0o100)
    config_path = "/home/syncthing/.config/syncthing/config.xml"
    s = services.get("syncthing@syncthing")
    if not os.path.exists(config_path) and s.state != "running":
        s.restart()
        count = 0
        while count < 5:
            if not os.path.exists(config_path):
                time.sleep(5)
                count += 1
            else:
                break
        if not os.path.exists(config_path):
            raise Exception("Syncthing taking too long to generate config,"
                            " try again later")
Example #9
0
    def post_install(self, extra_vars, dbpasswd=""):
        with open(os.path.join(self.path, 'package.json'), 'r') as f:
            d = json.loads(f.read())
        del d['dependencies']['bcryptjs']
        d['dependencies']['bcrypt'] = '0.8.5'
        d['engines']['node'] = '~0.10.0 || ~0.12.0 || ^4.2.0 || ^5.6.0'
        with open(os.path.join(self.path, 'package.json'), 'w') as f:
            f.write(json.dumps(d))
        with open(os.path.join(self.path, 'core/server/models/user.js'),
                  'r') as f:
            d = f.read()
        d = d.replace('bcryptjs', 'bcrypt')
        with open(os.path.join(self.path, 'core/server/models/user.js'),
                  'w') as f:
            f.write(d)
        if os.path.exists(os.path.join(self.path, 'npm-shrinkwrap.json')):
            os.unlink(os.path.join(self.path, 'npm-shrinkwrap.json'))

        nodejs.install_from_package(self.path, 'production',
                                    {'python': '/usr/bin/python2'})
        users.SystemUser("ghost").add()

        # Get Mail settings
        mail_settings = {
            'transport': extra_vars.get('gh-transport') or "",
            'service': extra_vars.get('gh-service') or "",
            'mail_user': extra_vars.get('gh-mail-user') or "",
            'mail_pass': extra_vars.get('gh-mail-pass') or "",
            'from_address': extra_vars.get('gh-from-address') or ""
        }

        # Create/Edit the Ghost config file
        with open(os.path.join(self.path, 'config.example.js'), 'r') as f:
            data = f.read()
        data = data.replace("port: '2368'",
                            "port: '{0}'".format(self.backend_port))
        data = data.replace(
            'http://my-ghost-blog.com', 'http://{0}' +
            (':' + str(self.port) if str(self.port) != '80' else '').format(
                self.addr))
        if len(set(mail_settings.values())) != 1 and\
           mail_settings['transport'] != '':
            # If the mail settings exist, add them
            data = data.replace(
                "mail: {},", 'mail: {\n'
                "\tfromaddress: '" + mail_settings['from_address'] + "',\n"
                "\ttransport: '" + mail_settings['transport'] + "',\n"
                "\t\toptions: {\n"
                "\t\t\tservice: '" + mail_settings['service'] + "',\n"
                "\t\t\tauth: {\n"
                "\t\t\t\tuser: '******'mail_user'] + "',\n"
                "\t\t\t\tpass: '******'mail_pass'] + "'\n"
                "\t\t\t}\n"
                "\t\t}\n"
                "},\n")
        with open(os.path.join(self.path, 'config.js'), 'w') as f:
            f.write(data)

        # Finally, make sure that permissions are set so that Ghost
        # can make adjustments and save plugins when need be.
        uid = users.get_system("ghost").uid
        for r, d, f in os.walk(self.path):
            for x in d:
                os.chown(os.path.join(r, x), uid, -1)
            for x in f:
                os.chown(os.path.join(r, x), uid, -1)

        cfg = {
            'directory': self.path,
            'user': '******',
            'command': 'node {0}'.format(os.path.join(self.path, 'index.js')),
            'autostart': 'true',
            'autorestart': 'true',
            'environment': 'NODE_ENV="production"',
            'stdout_logfile': '/var/log/ghost.log',
            'stderr_logfile': '/var/log/ghost.log'
        }
        s = services.Service(self.id, "supervisor", cfg=cfg)
        s.add()