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()
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()
def post_install(self, extra_vars, dbpasswd=""): # Get around top-level zip restriction (FIXME 0.7.2) if "paperwork-master" in os.listdir(self.path): tmp_path = os.path.abspath(os.path.join(self.path, "../pwrk-tmp")) os.rename(os.path.join(self.path, "paperwork-master/frontend"), tmp_path) os.rename(os.path.join(self.path, ".arkos"), os.path.join(tmp_path, ".arkos")) shutil.rmtree(self.path) os.rename(tmp_path, self.path) # Make sure that the correct PHP settings are enabled php.enable_mod('gd', 'opcache', 'mysql', 'pdo_mysql', 'mcrypt') php.enable_mod('apcu', config_file="/etc/php/conf.d/apcu.ini") dbstr = "mysql, localhost, 3389, {0}, {1}, {0}"\ .format(self.id, dbpasswd) with open(os.path.join(self.path, 'app/storage/db_settings'), 'w') as f: f.write(dbstr) php.composer_install(self.path) nodejs.install("gulp", as_global=True) nodejs.install_from_package(self.path, stat=None) cwd = os.getcwd() os.chdir(self.path) s = shell("bower install --allow-root", stdin='y\n') if s["code"] != 0: raise Exception("Failed to run bower: {0}".format(s["stderr"])) s = shell("gulp") if s["code"] != 0: raise Exception("Failed to run gulp: {0}".format(s["stderr"])) s = shell("php artisan migrate --force") if s["code"] != 0: raise Exception("Failed to run artisan: {0}".format(s["stderr"])) os.chdir(cwd) # Make sure the webapps config points to the public directory. c = nginx.loadf(os.path.join('/etc/nginx/sites-available', self.id)) for x in c.servers: if x.filter('Key', 'root'): x.filter('Key', 'root')[0].value = \ os.path.join(self.path, 'public') nginx.dumpf(c, os.path.join('/etc/nginx/sites-available', self.id)) uid, gid = users.get_system("http").uid, groups.get_system("http").gid for r, d, f in os.walk(os.path.join(self.path, 'app')): for x in d: os.chmod(os.path.join(r, x), 0o755) os.chown(os.path.join(r, x), uid, gid) for x in f: os.chmod(os.path.join(r, x), 0o644) os.chown(os.path.join(r, x), uid, gid) if os.path.exists(os.path.join(self.path, 'app/storage/setup')): os.unlink(os.path.join(self.path, 'app/storage/setup'))
def update(self, pkg, ver): # General update procedure shell('unzip -o -d %s %s' % (self.path, pkg)) 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) nodejs.install_from_package(self.path, 'production', {'sqlite': '/usr/bin/sqlite3', 'python': '/usr/bin/python2'}) services.get(self.id).restart()
def post_install(self, vars, dbpasswd=""): # Get around top-level zip restriction (FIXME 0.7.2) if "paperwork-master" in os.listdir(self.path): tmp_path = os.path.abspath(os.path.join(self.path, "../pwrk-tmp")) os.rename(os.path.join(self.path, "paperwork-master/frontend"), tmp_path) os.rename(os.path.join(self.path, ".arkos"), os.path.join(tmp_path, ".arkos")) shutil.rmtree(self.path) os.rename(tmp_path, self.path) # Make sure that the correct PHP settings are enabled php.enable_mod('gd', 'opcache', 'mysql', 'pdo_mysql', 'mcrypt') php.enable_mod('apcu', config_file="/etc/php/conf.d/apcu.ini") dbstr = "mysql, localhost, 3389, {0}, {1}, {0}".format(self.id, dbpasswd) with open(os.path.join(self.path, 'app/storage/db_settings'), 'w') as f: f.write(dbstr) php.composer_install(self.path) nodejs.install("gulp", as_global=True) nodejs.install_from_package(self.path, stat=None) cwd = os.getcwd() os.chdir(self.path) s = shell("bower install --allow-root", stdin='y\n') if s["code"] != 0: raise Exception("Failed to run bower: %s" % s["stderr"]) s = shell("gulp") if s["code"] != 0: raise Exception("Failed to run gulp: %s" % s["stderr"]) s = shell("php artisan migrate --force") if s["code"] != 0: raise Exception("Failed to run artisan: %s" % s["stderr"]) os.chdir(cwd) # Make sure the webapps config points to the public directory. c = nginx.loadf(os.path.join('/etc/nginx/sites-available', self.id)) for x in c.servers: if x.filter('Key', 'root'): x.filter('Key', 'root')[0].value = os.path.join(self.path, 'public') nginx.dumpf(c, os.path.join('/etc/nginx/sites-available', self.id)) uid, gid = users.get_system("http").uid, groups.get_system("http").gid for r, d, f in os.walk(os.path.join(self.path, 'app')): for x in d: os.chmod(os.path.join(r, x), 0755) os.chown(os.path.join(r, x), uid, gid) for x in f: os.chmod(os.path.join(r, x), 0644) os.chown(os.path.join(r, x), uid, gid) if os.path.exists(os.path.join(self.path, 'app/storage/setup')): os.unlink(os.path.join(self.path, 'app/storage/setup'))
def update(self, pkg, ver): # General update procedure shell('unzip -o -d {0} {1}'.format(self.path, pkg)) 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) nodejs.install_from_package(self.path, 'production', { 'sqlite': '/usr/bin/sqlite3', 'python': '/usr/bin/python2' }) services.get(self.id).restart()
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()
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()
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()
def post_install(self, 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.1' 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', {'sqlite': '/usr/bin/sqlite3', 'python': '/usr/bin/python2'}) users.SystemUser("ghost").add() # Get Mail settings mail_settings = { 'transport' : vars.get('ghost-transport') or "", 'service' : vars.get('ghost-service') or "", 'mail_user' : vars.get('ghost-mail-user') or "", 'mail_pass' : vars.get('ghost-mail-pass') or "", 'from_address' : vars.get('ghost-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: '%s'" % self.backend_port) data = data.replace('http://my-ghost-blog.com', 'http://'+self.addr+(':'+str(self.port) if str(self.port) != '80' else'')) 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 %s'%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()