def get_ui(self): ui = self.app.inflate('sysconfig:main') # General ui.find('hostname').set('value', self.hostname) if os.path.exists('/etc/localtime'): tz_active = os.path.realpath('/etc/localtime').split('/usr/share/zoneinfo/')[1] tz_sel = [UI.SelectOption(text=x, value=x, selected=True if tz_active in x else False) for x in zonelist.zones] ui.appendAll('zoneselect', *tz_sel) # Tools if shell_cs('which logrunnerd')[0] != 0: lrstat = 'Not installed' else: if self._mgr.get_status('logrunner') == 'running': lrstat = 'Running' ui.find('fllogrunner').append(UI.Button(text="Stop", id="svc/logrunner/stop")) else: lrstat = 'Not running' ui.find('fllogrunner').append(UI.Button(text="Start", id="svc/logrunner/start")) if self._mgr.get_enabled('logrunner') == 'enabled': lrstat += ' and enabled on boot' ui.find('fllogrunner').append(UI.Button(text="Disable on boot", id="svc/logrunner/disable")) else: lrstat += ' and not enabled on boot' ui.find('fllogrunner').append(UI.Button(text="Enable on boot", id="svc/logrunner/enable")) if shell_cs('which beacond')[0] != 0: bestat = 'Not installed' else: if self._mgr.get_status('beacon') == 'running': lrstat = 'Running' ui.find('flbeacon').append(UI.Button(text="Stop", id="svc/beacon/stop")) else: lrstat = 'Not running' ui.find('flbeacon').append(UI.Button(text="Start", id="svc/beacon/start")) if self._mgr.get_enabled('beacon') == 'enabled': lrstat += ' and enabled on boot' ui.find('flbeacon').append(UI.Button(text="Disable on boot", id="svc/beacon/disable")) else: lrstat += ' and not enabled on boot' ui.find('flbeacon').append(UI.Button(text="Enable on boot", id="svc/beacon/enable")) ui.find('logrunner').set('text', lrstat) ui.find('beacon').set('text', bestat) if self._changed: self.put_message('warn', 'A restart is required for this setting change to take effect.') return ui
def composer_install(self, path): self.verify_composer() s = shell_cs('cd %s; composer install' % path) if s[0] != 0: raise Exception( 'Composer failed to install this app\'s bundle. Error: %s' % str(s[1]))
def remove(self, *mods): s = shell_cs( "pip%s uninstall %s" % ("2" if self.app.platform in ["arkos", "arch"] else "", " ".join(x for x in mods)) ) if s[0] != 0: self.app.log.error("Failed to remove %s via PyPI; %s" % (" ".join(x for x in mods), s[1])) raise Exception("Failed to remove %s via PyPI, check logs for info" % " ".join(x for x in mods))
def remove(self, *mods): s = shell_cs('pip%s uninstall %s' % \ ('2' if self.app.platform in ['arkos', 'arch'] else '', ' '.join(x for x in mods))) if s[0] != 0: self.app.log.error('Failed to remove %s via PyPI; %s'%(' '.join(x for x in mods),s[1])) raise Exception('Failed to remove %s via PyPI, check logs for info'%' '.join(x for x in mods))
def install_composer(self): self.enable_mod('phar') s = shell_cs('curl -sS https://getcomposer.org/installer | php') if s[0] != 0: raise Exception('Composer download/config failed. Error: %s'%str(s[1])) os.rename('composer.phar', '/usr/local/bin/composer') os.chmod('/usr/bin/composer', 755) self.open_basedir('add', '/usr/local/bin')
def install_gem(self, *gems, **kwargs): self.verify_path() gemlist = shell('gem list').split('\n') for x in gems: if not any(x==s for s in gemlist) or force: d = shell_cs('gem install -N --no-user-install %s' % x) if d[0] != 0: self.app.log.error('Gem install \'%s\' failed: %s'%(x,str(d[1]))) raise Exception('Gem install \'%s\' failed. See logs for more info'%x)
def install_composer(self): self.enable_mod('phar') s = shell_cs('curl -sS https://getcomposer.org/installer | php') if s[0] != 0: raise Exception('Composer download/config failed. Error: %s' % str(s[1])) os.rename('composer.phar', '/usr/local/bin/composer') os.chmod('/usr/bin/composer', 755) self.open_basedir('add', '/usr/local/bin')
def install_gem(self, *gems, **kwargs): self.verify_path() gemlist = shell("gem list").split("\n") for x in gems: if not any(x == s for s in gemlist) or force: d = shell_cs("gem install -N --no-user-install %s" % x, stderr=True) if d[0] != 0: self.app.log.error("Gem install '%s' failed: %s" % (x, str(d[1]))) raise Exception("Gem install '%s' failed. See logs for more info" % x)
def regenerate_site(self, site): s = shell_cs( "jekyll build --source " + site.path.rstrip("_site") + " --destination " + os.path.join(site.path), stderr=True, ) if s[0] != 0: raise Exception("Jekyll failed to build: %s" % str(s[1])) shell("chmod 755 $(find %s -type d)" % site.path.rstrip("_site")) shell("chmod 644 $(find %s -type f)" % site.path.rstrip("_site"))
def remove(self, *mods): s = shell_cs('pip%s uninstall %s' % \ ('2' if self.app.platform in ['arkos', 'arch'] else '', ' '.join(x for x in mods))) if s[0] != 0: self.app.log.error('Failed to remove %s via PyPI; %s' % (' '.join(x for x in mods), s[1])) raise Exception( 'Failed to remove %s via PyPI, check logs for info' % ' '.join(x for x in mods))
def install_gem(self, *gems, **kwargs): self.verify_path() gemlist = shell('gem list').split('\n') for x in gems: if not any(x == s for s in gemlist) or force: d = shell_cs('gem install -N --no-user-install %s' % x) if d[0] != 0: self.app.log.error('Gem install \'%s\' failed: %s' % (x, str(d[1]))) raise Exception( 'Gem install \'%s\' failed. See logs for more info' % x)
def install_composer(self): cwd = os.getcwd() os.environ['COMPOSER_HOME'] = '/root' self.enable_mod('phar') self.open_basedir('add', '/root') s = shell_cs('cd /root; curl -sS https://getcomposer.org/installer | php', stderr=True) if s[0] != 0: raise Exception('Composer download/config failed. Error: %s'%str(s[1])) os.rename('/root/composer.phar', '/usr/local/bin/composer') os.chmod('/usr/local/bin/composer', 755) self.open_basedir('add', '/usr/local/bin') shell('cd %s'%cwd)
def post_install(self, name, path, vars): # Make sure the webapps config points to the _site directory and generate it. c = nginx.loadf(os.path.join('/etc/nginx/sites-available', name)) for x in c.servers: if x.filter('Key', 'root'): x.filter('Key', 'root')[0].value = os.path.join(path, '_site') nginx.dumpf(c, os.path.join('/etc/nginx/sites-available', name)) s = shell_cs('jekyll build --source '+path+' --destination '+os.path.join(path, '_site'), stderr=True) if s[0] != 0: raise Exception('Jekyll failed to build: %s'%str(s[1])) # Return an explicatory message. return 'Jekyll has been setup, with a sample site at '+path+'. Modify these files as you like. To learn how to use Jekyll, visit http://jekyllrb.com/docs/usage. After making changes, click the Configure button next to the site, then "Regenerate Site" to bring your changes live.'
def add_project(self, name, crypto=False): self.setup() if crypto: name = name + '-crypto' s = shell_cs('git init --quiet --bare "%s"' % os.path.join('/home/sparkleshare', name)) if s[0] != 0: self.app.log.error( 'Creation of Git repository failed. Error:\n%s' % s[1]) raise Exception( 'Creation of Git repository failed. See the logs for details') shell('git config --file %s receive.denyNonFastForwards true' % os.path.join('/home/sparkleshare', name, 'config')) # Add list of files that Git should not compress extensions = [ 'jpg', 'jpeg', 'png', 'tiff', 'gif', 'flac', 'mp3', 'ogg', 'oga', 'avi', 'mov', 'mpg', 'mpeg', 'mkv', 'ogv', 'ogx', 'webm', 'zip', 'gz', 'bz', 'bz2', 'rpm', 'deb', 'tgz', 'rar', 'ace', '7z', 'pak', 'iso', 'dmg' ] if os.path.exists( os.path.join('/home/sparkleshare', name, 'info/attributes')): f = open( os.path.join('/home/sparkleshare', name, 'info/attributes'), 'r').read() else: f = '' for x in extensions: f += '*.%s -delta\n' % x f += '*.%s -delta\n' % x.upper() open(os.path.join('/home/sparkleshare', name, 'info/attributes'), 'w').write(f) uid = pwd.getpwnam('sparkleshare').pw_uid gid = grp.getgrnam('sparkleshare').gr_gid for r, d, f in os.walk(os.path.join('/home/sparkleshare', name)): for x in d: os.chown(os.path.join(r, x), uid, gid) os.chmod(os.path.join(r, x), 0770) for x in f: os.chown(os.path.join(r, x), uid, gid) os.chmod(os.path.join(r, x), 0770) return ('ssh://sparkleshare@%s' % self.app.get_backend(IHostnameManager).gethostname().lower(), os.path.join('/home/sparkleshare', name))
class WebappControl(Plugin): def add(self, cat, name, wa, vars, enable=True): specialmsg = '' webapp = apis.webapps(self.app).get_interface(wa.wa_plugin) if not wa.dpath: ending = '' elif wa.dpath.endswith('.tar.gz'): ending = '.tar.gz' elif wa.dpath.endswith('.tar.bz2'): ending = '.tar.bz2' else: raise InstallError('Only gzip and bzip packages supported for now') # Run webapp preconfig, if any try: cat.put_statusmsg('Running pre-install configuration...') webapp.pre_install(name, vars) except Exception, e: raise InstallError('Webapp config - ' + str(e)) # Make sure the target directory exists, but is empty # Testing for sites with the same name should have happened by now target_path = os.path.join('/srv/http/webapps', name) pkg_path = '/tmp/' + name + ending if os.path.isdir(target_path): shutil.rmtree(target_path) os.makedirs(target_path) # Download and extract the source package if wa.dpath: try: cat.put_statusmsg('Downloading webapp package...') download(wa.dpath, file=pkg_path, crit=True) except Exception, e: raise InstallError('Couldn\'t download - %s' % str(e)) status = shell_cs( 'tar ' + ('xzf' if ending is '.tar.gz' else 'xjf') + ' /tmp/' + name + ending + ' -C ' + target_path + ' --strip 1', stderr=True) if status[0] >= 1: raise InstallError(status[1]) os.remove(pkg_path)
def post_install(self, name, path, vars, dbinfo={}): # Make sure the webapps config points to the _site directory and generate it. c = nginx.loadf(os.path.join("/etc/nginx/sites-available", name)) for x in c.servers: if x.filter("Key", "root"): x.filter("Key", "root")[0].value = os.path.join(path, "_site") nginx.dumpf(c, os.path.join("/etc/nginx/sites-available", name)) s = shell_cs("jekyll build --source " + path + " --destination " + os.path.join(path, "_site"), stderr=True) if s[0] != 0: raise Exception("Jekyll failed to build: %s" % str(s[1])) shell("chmod 755 $(find %s -type d)" % path) shell("chmod 644 $(find %s -type f)" % path) shell("chown -R http:http %s" % path) # Return an explicatory message. return ( "Jekyll has been setup, with a sample site at " + path + '. Modify these files as you like. To learn how to use Jekyll, visit http://jekyllrb.com/docs/usage. After making changes, click the Configure button next to the site, then "Regenerate Site" to bring your changes live.' )
def add_project(self, name, crypto=False): self.setup() if crypto: name = name + '-crypto' s = shell_cs('git init --quiet --bare "%s"'%os.path.join('/home/sparkleshare', name)) if s[0] != 0: self.app.log.error('Creation of Git repository failed. Error:\n%s'%s[1]) raise Exception('Creation of Git repository failed. See the logs for details') shell('git config --file %s receive.denyNonFastForwards true'%os.path.join('/home/sparkleshare', name, 'config')) # Add list of files that Git should not compress extensions = ['jpg', 'jpeg', 'png', 'tiff', 'gif', 'flac', 'mp3', 'ogg', 'oga', 'avi', 'mov', 'mpg', 'mpeg', 'mkv', 'ogv', 'ogx', 'webm', 'zip', 'gz', 'bz', 'bz2', 'rpm', 'deb', 'tgz', 'rar', 'ace', '7z', 'pak', 'iso', 'dmg'] if os.path.exists(os.path.join('/home/sparkleshare', name, 'info/attributes')): f = open(os.path.join('/home/sparkleshare', name, 'info/attributes'), 'r').read() else: f = '' for x in extensions: f += '*.%s -delta\n' % x f += '*.%s -delta\n' % x.upper() open(os.path.join('/home/sparkleshare', name, 'info/attributes'), 'w').write(f) uid = pwd.getpwnam('sparkleshare').pw_uid gid = grp.getgrnam('sparkleshare').gr_gid for r, d, f in os.walk(os.path.join('/home/sparkleshare', name)): for x in d: os.chown(os.path.join(r, x), uid, gid) os.chmod(os.path.join(r, x), 0770) for x in f: os.chown(os.path.join(r, x), uid, gid) os.chmod(os.path.join(r, x), 0770) return ('ssh://sparkleshare@%s'%self.app.get_backend(IHostnameManager).gethostname().lower(), os.path.join('/home/sparkleshare', name))
def chpasswd(self, name, dom, passwd): x = shell_cs('echo -e "%s\n%s\n" | prosodyctl passwd %s@%s' % (passwd,passwd,name,dom)) if x[0] != 0: raise Exception('XMPP Password change failed: %s' % x[1])
def remove(self, *mods): s = shell_cs('npm uninstall %s' % ' '.join(x for x in mods), stderr=True) if s[0] != 0: self.app.log.error('Failed to remove %s via npm; log output follows:\n%s'%(' '.join(x for x in mods),s[1])) raise Exception('Failed to remove %s via npm, check logs for info'%' '.join(x for x in mods))
def add_user(self, name, dom, passwd): x = shell_cs('echo -e "%s\n%s\n" | prosodyctl adduser %s@%s' % (passwd,passwd,name,dom)) if x[0] != 0: raise Exception('XMPP Add user failed: %s' % x[1])
except: raise SoftwareRequirementError(dep) else: raise SoftwareRequirementError(dep) if dep['type'] == 'plugin': if not dep['package'] in PluginLoader.list_plugins() or \ PluginLoader.__plugins[dep['package']].problem: raise PluginRequirementError(dep) if dep['type'] == 'module': if dep.has_key('binary') and dep['binary']: try: exec('import %s' % dep['binary']) except: # Let's try to install it anyway s = shell_cs('pip%s install %s' % ('2' if platform in ['arkos', 'arch'] else '', dep['package'])) if s[0] != 0: raise ModuleRequirementError(dep, False) else: return 'Restart Genesis for changes to take effect.' raise ModuleRequirementError(dep, False) else: p = False s = shell('pip%s freeze' % '2' if platform in ['arkos', 'arch'] else '') for x in s.split('\n'): if dep['package'].lower() in x.split('==')[0].lower(): p = True if not p: shell('pip%s install %s' %
def nginx_reload(self): status = shell_cs('systemctl restart nginx') if status[0] >= 1: raise
def php_reload(self): status = shell_cs('systemctl restart php-fpm') if status[0] >= 1: raise Exception('PHP FastCGI failed to reload.')
def nginx_reload(self): status = shell_cs('systemctl restart nginx') if status[0] >= 1: raise Exception('nginx failed to reload.')
def install_from_package(self, path, stat='production'): s = shell_cs('cd %s; npm install %s' % (path, '--'+stat if stat else ''), stderr=True, env={'HOME': '/root'}) if s[0] != 0: self.app.log.error('Failed to install %s via npm; log output follows:\n%s'%(path,s[1])) raise Exception('Failed to install %s via npm, check logs for info'%path)
dbase.usermod(dbinfo['user'], 'add', dbinfo['passwd'], conn) dbase.chperm(dbinfo['name'], dbinfo['user'], 'grant', conn) except Exception, e: raise InstallError('Databases could not be created - %s' % str(e)) # Make sure the target directory exists, but is empty # Testing for sites with the same name should have happened by now target_path = os.path.join('/srv/http/webapps', name) pkg_path = '/tmp/'+name+ending if os.path.isdir(target_path): shutil.rmtree(target_path) os.makedirs(target_path) # Download and extract the source package if wa.dpath and ending == '.git': status = shell_cs('git clone %s %s'%(wa.dpath,target_path), stderr=True) if status[0] >= 1: raise InstallError(status[1]) elif wa.dpath: try: cat.statusmsg('Downloading webapp package...') download(wa.dpath, file=pkg_path, crit=True) except Exception, e: raise InstallError('Couldn\'t download - %s' % str(e)) if ending in ['.tar.gz', '.tar.bz2']: extract_cmd = 'tar ' extract_cmd += 'xzf' if ending is '.tar.gz' else 'xjf' extract_cmd += ' /tmp/%s -C %s --strip 1' % (name+ending, target_path) else: extract_cmd = 'unzip -d %s /tmp/%s' % (target_path, name+ending)
class SysConfigPlugin(CategoryPlugin): text = 'System Settings' iconfont = 'gen-cog' folder = False def on_init(self): self._mgr = self.app.get_backend(apis.services.IServiceManager) self._be = backend.Config(self.app) self._st = SystemTime() self.hostname = self._be.gethostname() def get_ui(self): ui = self.app.inflate('sysconfig:main') systime = self._st.get_datetime('%s, %s' \ % (self.app.gconfig.get('genesis', 'dformat', '%d %b %Y'), self.app.gconfig.get('genesis', 'tformat', '%H:%M'))) offset = 0 try: offset = self._st.get_offset() except Exception, e: self.app.log.error( 'Could not get Internet time. Please check your connection. Error: %s' % str(e)) self.put_message( 'err', 'Could not get Internet time. Please check your connection.') # General ui.find('hostname').set('value', self.hostname) tz_active = os.path.realpath('/etc/localtime').split( '/usr/share/zoneinfo/')[1] if os.path.exists( '/etc/localtime') else '' tz_sel = [ UI.SelectOption(text=x, value=x, selected=True if tz_active in x else False) for x in zonelist.zones ] ui.appendAll('zoneselect', *tz_sel) # Time ui.find('systime').set('text', systime) ui.find('offset').set('text', '%s seconds' % offset) # Tools if shell_cs('which logrunnerd')[0] != 0: lrstat = 'Not installed' else: if self._mgr.get_status('logrunner') == 'running': lrstat = 'Running' ui.find('fllogrunner').append( UI.Button(text="Stop", id="svc/logrunner/stop")) else: lrstat = 'Not running' ui.find('fllogrunner').append( UI.Button(text="Start", id="svc/logrunner/start")) if self._mgr.get_enabled('logrunner') == 'enabled': lrstat += ' and enabled on boot' ui.find('fllogrunner').append( UI.Button(text="Disable on boot", id="svc/logrunner/disable")) else: lrstat += ' and not enabled on boot' ui.find('fllogrunner').append( UI.Button(text="Enable on boot", id="svc/logrunner/enable")) if shell_cs('which beacond')[0] != 0: bestat = 'Not installed' else: if self._mgr.get_status('beacon') == 'running': bestat = 'Running' ui.find('flbeacon').append( UI.Button(text="Stop", id="svc/beacon/stop")) else: bestat = 'Not running' ui.find('flbeacon').append( UI.Button(text="Start", id="svc/beacon/start")) if self._mgr.get_enabled('beacon') == 'enabled': bestat += ' and enabled on boot' ui.find('flbeacon').append( UI.Button(text="Disable on boot", id="svc/beacon/disable")) else: bestat += ' and not enabled on boot' ui.find('flbeacon').append( UI.Button(text="Enable on boot", id="svc/beacon/enable")) ui.find('logrunner').set('text', lrstat) ui.find('beacon').set('text', bestat) if self._changed: self.put_message( 'warn', 'A restart is required for this setting change to take effect.' ) return ui
shell('yum -y install '+dep['package']) except: raise SoftwareRequirementError(dep) else: raise SoftwareRequirementError(dep) if dep['type'] == 'plugin': if not dep['package'] in PluginLoader.list_plugins() or \ PluginLoader.__plugins[dep['package']].problem: raise PluginRequirementError(dep) if dep['type'] == 'module': if dep.has_key('binary') and dep['binary']: try: exec('import %s'%dep['binary']) except: # Let's try to install it anyway s = shell_cs('pip%s install %s' % ('2' if platform in ['arkos', 'arch'] else '', dep['package'])) if s[0] != 0: raise ModuleRequirementError(dep, False) else: return 'Restart Genesis for changes to take effect.' raise ModuleRequirementError(dep, False) else: p = False s = shell('pip%s freeze'%'2' if platform in ['arkos', 'arch'] else '') for x in s.split('\n'): if dep['package'].lower() in x.split('==')[0].lower(): p = True if not p: shell('pip%s install %s' % ('2' if platform in ['arkos', 'arch'] else '', dep['package'])) raise ModuleRequirementError(dep, True)
def composer_install(self, path): self.verify_composer() s = shell_cs('cd %s; composer install'%path, stderr=True) if s[0] != 0: raise Exception('Composer failed to install this app\'s bundle. Error: %s'%str(s[1]))
def del_user(self, name, dom): x = shell_cs('prosodyctl deluser %s@%s' % (name,dom)) if x[0] != 0: raise Exception('XMPP Delete user failed: %s' % x[1])
def nginx_reload(self): status = shell_cs('systemctl restart nginx') if status[0] >= 1: raise ReloadError('nginx failed to reload.', "Edit")
def install(self, *mods, **kwargs): s = shell_cs('npm install %s%s' % (' '.join(x for x in mods), (' --'+' --'.join(x for x in kwargs['opts']) if kwargs.has_key('opts') else '')), stderr=True) if s[0] != 0: self.app.log.error('Failed to install %s via npm; log output follows:\n%s'%(' '.join(x for x in mods),s[1])) raise Exception('Failed to install %s via npm, check logs for info'%' '.join(x for x in mods))
def verify_dep(dep, cat=''): """ Verifies that given plugin dependency is satisfied. """ platform = PluginLoader.platform log = PluginLoader.log if dep['type'] == 'app': if ((dep['binary'] and shell_status('which '+dep['binary']) != 0) \ or not dep['binary']) and shell_status('pacman -Q '+dep['package']) != 0: if platform == 'arch' or platform == 'arkos': if cat: cat.statusmsg('Installing dependency %s...' % dep['name']) log.warn('Missing %s, which is required by a plugin. Attempting to install...' % dep['name']) s = shell_cs('pacman -Sy --noconfirm --needed '+dep['package'], stderr=True) if s[0] != 0: log.error('Failed to install %s - %s' % (dep['name'], str(s[1]))) raise SoftwareRequirementError(dep) if dep['binary']: shell('systemctl enable '+dep['binary']) elif platform == 'debian': try: shell('apt-get -y --force-yes install '+dep['package']) except: raise SoftwareRequirementError(dep) elif platform == 'gentoo': try: shell('emerge '+dep['package']) except: raise SoftwareRequirementError(dep) elif platform == 'freebsd': try: shell('portupgrade -R '+dep['package']) except: raise SoftwareRequirementError(dep) elif platform == 'centos' or platform == 'fedora': try: shell('yum -y install '+dep['package']) except: raise SoftwareRequirementError(dep) else: raise SoftwareRequirementError(dep) if dep['type'] == 'plugin': if not dep['package'] in PluginLoader.list_plugins() or \ PluginLoader.__plugins[dep['package']].problem: raise PluginRequirementError(dep) if dep['type'] == 'module': if dep.has_key('binary') and dep['binary']: try: exec('import %s'%dep['binary']) except: # Let's try to install it anyway s = shell_cs('pip%s install %s' % ('2' if platform in ['arkos', 'arch'] else '', dep['package'])) if s[0] != 0: raise ModuleRequirementError(dep, False) else: return 'Restart Genesis for changes to take effect.' raise ModuleRequirementError(dep, False) else: p = False s = shell('pip%s freeze'%'2' if platform in ['arkos', 'arch'] else '') for x in s.split('\n'): if dep['package'].lower() in x.split('==')[0].lower(): p = True if not p: shell('pip%s install %s' % ('2' if platform in ['arkos', 'arch'] else '', dep['package'])) raise ModuleRequirementError(dep, True)
def regenerate_site(self, site): s = shell_cs('jekyll build --source '+site.path.rstrip('_site')+' --destination '+os.path.join(site.path), stderr=True) if s[0] != 0: raise Exception('Jekyll failed to build: %s'%str(s[1]))
# Make sure the target directory exists, but is empty # Testing for sites with the same name should have happened by now target_path = os.path.join('/srv/http/webapps', name) pkg_path = '/tmp/'+name+ending if os.path.isdir(target_path): shutil.rmtree(target_path) os.makedirs(target_path) # Download and extract the source package try: download(webapp.dpath, file=pkg_path) except Exception, e: raise InstallError('Couldn\'t download - %s' % str(e)) status = shell_cs('tar ' +('xzf' if ending is '.tar.gz' else 'xjf') +' /tmp/'+name+ending+' -C ' +target_path+' --strip 1', stderr=True) if status[0] >= 1: raise InstallError(status[1]) os.remove(pkg_path) # Setup the webapp and create an nginx serverblock try: webapp.post_install(name, target_path, vars) except Exception, e: raise InstallError('Webapp config - '+str(e)) try: self.nginx_add( name=name, stype=webapp.name, path=target_path,
def php_reload(self): status = shell_cs("systemctl restart php-fpm") if status[0] >= 1: raise Exception("nginx failed to reload.")
def php_reload(self): status = shell_cs('systemctl restart php-fpm') if status[0] >= 1: raise
def install(self, *mods, **kwargs): cd = ('cd %s;' % kwargs['install_path']) if 'install_path' in kwargs else '' s = shell_cs('%s npm install %s%s' % (cd, ' '.join(x for x in mods), (' --'+' --'.join(x for x in kwargs['opts']) if kwargs.has_key('opts') else '')), stderr=True) if s[0] != 0: self.app.log.error('Failed to install %s via npm; log output follows:\n%s'%(' '.join(x for x in mods),s[1])) raise Exception('Failed to install %s via npm, check logs for info'%' '.join(x for x in mods))
def verify_dep(dep, cat=''): """ Verifies that given plugin dependency is satisfied. """ platform = PluginLoader.platform log = PluginLoader.log if dep['type'] == 'app': if ((dep['binary'] and shell_status('which '+dep['binary']) != 0) \ or not dep['binary']) and shell_status('pacman -Q '+dep['package']) != 0: if platform == 'arch' or platform == 'arkos': if cat: cat.statusmsg('Installing dependency %s...' % dep['name']) log.warn( 'Missing %s, which is required by a plugin. Attempting to install...' % dep['name']) s = shell_cs('pacman -Sy --noconfirm --needed ' + dep['package'], stderr=True) if s[0] != 0: log.error('Failed to install %s - %s' % (dep['name'], str(s[1]))) raise SoftwareRequirementError(dep) if dep['binary']: shell('systemctl enable ' + dep['binary']) elif platform == 'debian': try: shell('apt-get -y --force-yes install ' + dep['package']) except: raise SoftwareRequirementError(dep) elif platform == 'gentoo': try: shell('emerge ' + dep['package']) except: raise SoftwareRequirementError(dep) elif platform == 'freebsd': try: shell('portupgrade -R ' + dep['package']) except: raise SoftwareRequirementError(dep) elif platform == 'centos' or platform == 'fedora': try: shell('yum -y install ' + dep['package']) except: raise SoftwareRequirementError(dep) else: raise SoftwareRequirementError(dep) if dep['type'] == 'plugin': if not dep['package'] in PluginLoader.list_plugins() or \ PluginLoader.__plugins[dep['package']].problem: raise PluginRequirementError(dep) if dep['type'] == 'module': if dep.has_key('binary') and dep['binary']: try: exec('import %s' % dep['binary']) except: # Let's try to install it anyway s = shell_cs('pip%s install %s' % ('2' if platform in ['arkos', 'arch'] else '', dep['package'])) if s[0] != 0: raise ModuleRequirementError(dep, False) else: return 'Restart Genesis for changes to take effect.' raise ModuleRequirementError(dep, False) else: p = False s = shell('pip%s freeze' % '2' if platform in ['arkos', 'arch'] else '') for x in s.split('\n'): if dep['package'].lower() in x.split('==')[0].lower(): p = True if not p: shell('pip%s install %s' % ('2' if platform in ['arkos', 'arch'] else '', dep['package'])) raise ModuleRequirementError(dep, True)