def create_pmadb (root): path = os.path.join (root, 'phpMyAdmin', 'scripts', 'create_tables.sql') pre = "tmp!market!install!db" dbname = CTK.cfg.get_val('%s!db_name' %(pre)) dbuser = CTK.cfg.get_val('%s!db_user' %(pre)) dbpass = CTK.cfg.get_val('%s!db_pass' %(pre)) sql = open(path, 'r').read() sql = sql.replace (SOURCE_SQL, TARGET_SQL %(locals())) try: open (path, 'w').write(sql) except: Install_Log.log ("Error: template for pmadb structure not created.") raise mysql_bin = database.mysql_bins (database.MYSQL_BIN_NAMES) if dbpass: ret = popen.popen_sync ('%(mysql_bin)s -u%(dbuser)s -p%(dbpass)s < %(path)s' %(locals())) else: ret = popen.popen_sync ('%(mysql_bin)s -u%(dbuser)s < %(path)s' %(locals())) if ret['retcode']: Install_Log.log ("Error: pmadb structure not created.") raise EnvironmentError, ret['stderr'] else: Install_Log.log ("Success: pmadb structure created.")
def create_pmadb(root): path = os.path.join(root, 'phpMyAdmin', 'scripts', 'create_tables.sql') pre = "tmp!market!install!db" dbname = CTK.cfg.get_val('%s!db_name' % (pre)) dbuser = CTK.cfg.get_val('%s!db_user' % (pre)) dbpass = CTK.cfg.get_val('%s!db_pass' % (pre)) sql = open(path, 'r').read() sql = sql.replace(SOURCE_SQL, TARGET_SQL % (locals())) try: open(path, 'w').write(sql) except: Install_Log.log("Error: template for pmadb structure not created.") raise mysql_bin = database.mysql_bins(database.MYSQL_BIN_NAMES) if dbpass: ret = popen.popen_sync( '%(mysql_bin)s -u%(dbuser)s -p%(dbpass)s < %(path)s' % (locals())) else: ret = popen.popen_sync('%(mysql_bin)s -u%(dbuser)s < %(path)s' % (locals())) if ret['retcode']: Install_Log.log("Error: pmadb structure not created.") raise EnvironmentError, ret['stderr'] else: Install_Log.log("Success: pmadb structure created.")
def fix_context (root, target_directory): """Change Liferay context from / to target_directory""" market.Install_Log.log ("Root Context adjustment.") if not target_directory: market.Install_Log.log (" Installing as Virtual Server. Root context change not needed.") return src = os.path.join (root, 'liferay', 'tomcat', 'webapps', 'ROOT') dst = os.path.join (root, 'liferay', 'tomcat', 'webapps', target_directory.strip('/')) ret = popen.popen_sync ('mv %s %s' %(src, dst), retcode=True) if ret['retcode']: msg = "Error: Unable to move ROOT directory." market.Install_Log.log (" %s" %(msg)) raise EnvironmentError, msg try: path = os.path.join (dst, 'WEB-INF', 'classes', 'portal-ext.properties') open(path, 'w').write ('portal.ctx=%s\n' %(target_directory)) except: msg = "Error: Unable to write portal-ext.properties." market.Install_Log.log (" %s" %(msg)) raise EnvironmentError, msg src = os.path.join (root, 'liferay', 'tomcat', 'conf', 'Catalina', 'localhost', 'ROOT.xml') dst = os.path.join (root, 'liferay', 'tomcat', 'conf', 'Catalina', 'localhost', '%s.xml' % (target_directory.strip('/'))) ret = popen.popen_sync ('mv %s %s' %(src, dst), retcode=True) if ret['retcode']: msg = "Error: Unable to move XML file." market.Install_Log.log (" %s" %(msg)) raise EnvironmentError, msg market.Install_Log.log (" Root Context successfuly changed to %s." %(target_directory))
def make_install_init (self): # System Info system_info = SystemInfo.get_info() OS = system_info.get('system','').lower() # Fetch Parameters root = CTK.cfg.get_val ('%s!root' %(PRE)) nagiosuser = CTK.cfg.get_val ('%s!nagiosuser' %(PRE)) if OS == 'linux': ret = popen.popen_sync ("make install-init", cd="%(root)s/nagios_core"%(locals())) if ret['retcode']: return ret elif OS == 'darwin': path_pre = os.path.join (root, 'nrpe.plist.pre') path_plist = os.path.join (root, 'nrpe.plist') # Build plist file plist = open (path_pre, 'r').read() plist = plist.replace ('${UserName}', nagiosuser) plist = plist.replace ('${WorkingDirectory}', os.path.join (root, 'nagios')) f = open (path_plist, 'w+') f.write (plist) f.close() else: # Default case. ret = popen.popen_sync ("make install-init", cd="%(root)s/nagios_core"%(locals())) if ret['retcode']: return ret return {'retcode': 0}
def configure_database (root): pre = "tmp!market!install!db" dbname = CTK.cfg.get_val('%s!db_name' %(pre)) dbuser = CTK.cfg.get_val('%s!db_user' %(pre)) dbpass = CTK.cfg.get_val('%s!db_pass' %(pre)) source = os.path.join (root, 'wordpress', 'wp-config-sample.php') target = os.path.join (root, 'wordpress', 'wp-config.php') popen.popen_sync ('cp -p %s %s'%(source, target)) # Read lines = open(target,'r').readlines() # Modify DB related config entries content = '' for line in lines: if re.findall (r'define.+DB_NAME.+;', line): content += "define('DB_NAME', '%s');\n" %(dbname) elif re.findall (r'define.+DB_USER.+;', line): content += "define('DB_USER', '%s');\n" %(dbuser) elif re.findall (r'define.+DB_PASSWORD.+;', line): content += "define('DB_PASSWORD', '%s');\n" %(dbpass) else: content += line # Write try: open(target,'w').write (content) market.Install_Log.log ("DB details added to %s." %(target)) except: market.Install_Log.log ("DB details were not added to %s." %(target)) raise
def __safe_call__(self): box = CTK.Box() pre = 'tmp!market!install' # Replacements app_id = CTK.cfg.get_val('%s!app!application_id' % (pre)) app_name = CTK.cfg.get_val('%s!app!application_name' % (pre)) root = CTK.cfg.get_val('%s!root' % (pre)) target_type = CTK.cfg.get_val('%s!target' % (pre)) target_vserver = CTK.cfg.get_val('%s!target!vserver' % (pre)) target_vserver_n = CTK.cfg.get_val('%s!target!vserver_n' % (pre)) target_directory = CTK.cfg.get_val('%s!target!directory' % (pre)) deployment_lang = CTK.cfg.get_val('%s!wordpress!lang' % (pre), 'en') pre_vsrv = 'vserver!%s' % (target_vserver_n) # PHP info php_info = php.get_info(pre_vsrv) # More replacements props = cfg_get_surrounding_repls('pre_rule', php_info['rule']) props.update(locals()) # Link correct language popen.popen_sync( 'ln -fs %(root)s/wp-%(deployment_lang)s/wordpress %(root)s/wordpress' % (locals())) popen.popen_sync( 'cp -r %(root)s/plugins/* %(root)s/wordpress/wp-content/plugins' % (locals())) # Provide DB details tools.configure_database(root) # Optional steps (if Cache module is present) if os.path.isfile(os.path.join(root, 'wp-cache-config.php')): tools.extend_sample_config_file(root) tools.move_cache_advanced(root) tools.move_cache_config(root) # Apply the config if target_type == 'vserver': config = CONFIG_VSERVER % (props) CTK.cfg.apply_chunk(config) AddUsualStaticFiles(props['pre_rule_plus1'], ['/favicon.ico', '/crossdomain.xml']) CTK.cfg.normalize('%s!rule' % (pre_vsrv)) elif target_type == 'directory': config = CONFIG_DIR % (props) CTK.cfg.apply_chunk(config) box += CTK.RawHTML( js=CTK.DruidContent__JS_to_goto(box.id, URL_POST_INSTALL)) return box.Render().toStr()
def __safe_call__ (self): box = CTK.Box() pre = 'tmp!market!install' # Replacements app_id = CTK.cfg.get_val ('%s!app!application_id' %(pre)) app_name = CTK.cfg.get_val ('%s!app!application_name'%(pre)) root = CTK.cfg.get_val ('%s!root' %(pre)) target_type = CTK.cfg.get_val ('%s!target' %(pre)) target_vserver = CTK.cfg.get_val ('%s!target!vserver' %(pre)) target_vserver_n = CTK.cfg.get_val ('%s!target!vserver_n' %(pre)) target_directory = CTK.cfg.get_val ('%s!target!directory' %(pre)) deployment_lang = CTK.cfg.get_val ('%s!wordpress!lang' %(pre),'en') pre_vsrv = 'vserver!%s' %(target_vserver_n) # PHP info php_info = php.get_info (pre_vsrv) # More replacements props = cfg_get_surrounding_repls ('pre_rule', php_info['rule']) props.update (locals()) # Link correct language popen.popen_sync ('ln -fs %(root)s/wp-%(deployment_lang)s/wordpress %(root)s/wordpress' %(locals())) popen.popen_sync ('cp -r %(root)s/plugins/* %(root)s/wordpress/wp-content/plugins' %(locals())) # Provide DB details tools.configure_database (root) # Optional steps (if Cache module is present) if os.path.isfile (os.path.join (root, 'wp-cache-config.php')): tools.extend_sample_config_file (root) tools.move_cache_advanced (root) tools.move_cache_config (root) # Apply the config if target_type == 'vserver': config = CONFIG_VSERVER %(props) CTK.cfg.apply_chunk (config) AddUsualStaticFiles (props['pre_rule_plus1'], ['/favicon.ico','/crossdomain.xml']) CTK.cfg.normalize ('%s!rule'%(pre_vsrv)) elif target_type == 'directory': config = CONFIG_DIR %(props) CTK.cfg.apply_chunk (config) box += CTK.RawHTML (js = CTK.DruidContent__JS_to_goto (box.id, URL_POST_INSTALL)) return box.Render().toStr()
def detect_cpp(specific_version='', cache=False): """Detect binary for a C++ compiler. If a specific_version string is provided, the check will be restricted to a matching string in the binarie's output. The cache parameter determines whether subsequent calls will reissue the detection commands or use a cached value. detect_cpp() returns the absolute path to the binary found.""" global _cpp_bin_cache global _cpp_bin_checked def cpp_bin_test(path_cpp): # Sometimes this outputs stdout info to stderr ret = popen.popen_sync('%s -v' % (path_cpp), stdout=True, stderr=True) if specific_version and not specific_version in ret.get( 'stdout', '') + ret.get('stderr', ''): return False return True # Cache miss if not _cpp_bin_checked or cache == False: _cpp_bin_checked = True _cpp_bin_cache = path_find_binary(CPP_BINS, CPP_PATHS, cpp_bin_test) if not _cpp_bin_cache and cpp_bin_test('c++'): _cpp_bin_cache = popen.popen_sync('which c++') # Find the cc binary return _cpp_bin_cache
def Wiki_Config_Replacements (params): path = os.path.join (params['root'], 'moin', 'wikiconfig.py') config = open (path, 'r').read() url_prefix_static = '/moin_static' if params.get('target_directory'): url_prefix_static = os.path.join (params['target_directory'], url_prefix_static) config = config.replace('#${url_prefix_static}', 'url_prefix_static = "%s"' %(url_prefix_static)) config = config.replace('#${sitename}', 'sitename = u"%(sitename)s"' %(params)) config = config.replace('#${superuser}', 'superuser = [u"%(user)s", ]' %(params)) config = config.replace('#${acl_rights_before}', 'acl_rights_before = u"%(user)s:read,write,delete,revert,admin"' %(params)) try: open (path, 'w').write(config) Install_Log.log ('Success: wikiconfig.py modified.') except: Install_Log.log ('Error: wikiconfig.py not modified.') raise server_user = CTK.cfg.get_val ('server!user', str(os.getuid())) server_group = CTK.cfg.get_val ('server!group', str(os.getgid())) root = params['root'] ret = popen.popen_sync ('chown -R %(server_user)s:%(server_group)s %(root)s/moin' %(locals())) if ret['retcode']: Install_Log.log ('Error: Moin permissions not correctly set.') raise ret['stderr'] Install_Log.log ('Success: Moin permissions correctly set.')
def detect_gem (specific_version='', cache=False): """Detect binary for Ruby Gems. If a specific_version string is specified, it will only check for that version string. If the cache parameter is enabled, it will cache the results to avoid making redundant system calls on successive executions. detect_gem() returns the absolute path to the binary found.""" global _gem_bin_cache global _gem_bin_checked # Cache miss if not _gem_bin_checked or cache==False: _gem_bin_checked = True # Ruby path ruby_bin_path = detect_ruby (specific_version) if not ruby_bin_path: return None # Gem ought to be beside Ruby ruby_path = os.path.dirname (ruby_bin_path) for bin in GEM_BINS: gem_bin = os.path.join (ruby_path, bin) if os.access (gem_bin, os.X_OK): if specific_version: ret = popen.popen_sync ('%s -v'%(gem_bin), stdout=True, stderr=True) if not specific_version in ret.get('stdout',''): continue _gem_bin_cache = gem_bin # Return the binary return _gem_bin_cache
def app_database_remove (app, user, passw, db_type): if db_type == 'MySQL': cmd = "mysql -u'%(user)s' -p'%(passw)s' -e 'DROP DATABASE IF EXISTS market_%(app)s'" %(locals()) ret = popen.popen_sync (cmd) if ret['retcode'] != 0: return ret['stderr']
def figure_php_information(): """Parse PHP settings into a dictionary""" php_path = figure_phpcgi_binary() ret = popen.popen_sync ('%s -i' %(php_path)) # Output can either be in HTML format or as a PHP array. if 'Content-type: text/html' in ret['stdout']: regex = """^<tr><td class="e">(.*?)</td><td class="v">(.*?)</td>(.*?)</tr>$""" else: regex = """^(.*?) => (.*?)( => .*)?$""" settings = {} tags = re.compile(r'<.*?>') matches = re.findall(regex, ret['stdout'], re.MULTILINE) for setting in matches: key, val = setting[0].strip(), setting[1].strip() val = tags.sub('', val) settings[key] = val # Double check PHP Version (sometimes previous pattern differs) if not settings.get('PHP Version'): tmp = re.findall('PHP Version.+(\d+\.\d+\.\d+)',ret['stdout']) if tmp: settings['PHP Version'] = tmp[0] return settings
def __init__(self): # Get server info try: ret = popen.popen_sync("%s -i" % (CHEROKEE_WORKER)) self._server_info = ret['stdout'] except: self._server_info = ''
def detect_gem(specific_version='', cache=False): """Detect binary for Ruby Gems. If a specific_version string is specified, it will only check for that version string. If the cache parameter is enabled, it will cache the results to avoid making redundant system calls on successive executions. detect_gem() returns the absolute path to the binary found.""" global _gem_bin_cache global _gem_bin_checked # Cache miss if not _gem_bin_checked or cache == False: _gem_bin_checked = True # Ruby path ruby_bin_path = detect_ruby(specific_version) if not ruby_bin_path: return None # Gem ought to be beside Ruby ruby_path = os.path.dirname(ruby_bin_path) for bin in GEM_BINS: gem_bin = os.path.join(ruby_path, bin) if os.access(gem_bin, os.X_OK): if specific_version: ret = popen.popen_sync('%s -v' % (gem_bin), stdout=True, stderr=True) if not specific_version in ret.get('stdout', ''): continue _gem_bin_cache = gem_bin # Return the binary return _gem_bin_cache
def detect_cpp (specific_version='', cache=False): """Detect binary for a C++ compiler. If a specific_version string is provided, the check will be restricted to a matching string in the binarie's output. The cache parameter determines whether subsequent calls will reissue the detection commands or use a cached value. detect_cpp() returns the absolute path to the binary found.""" global _cpp_bin_cache global _cpp_bin_checked def cpp_bin_test (path_cpp): # Sometimes this outputs stdout info to stderr ret = popen.popen_sync ('%s -v'%(path_cpp), stdout=True, stderr=True) if specific_version and not specific_version in ret.get('stdout','')+ret.get('stderr', ''): return False return True # Cache miss if not _cpp_bin_checked or cache==False: _cpp_bin_checked = True _cpp_bin_cache = path_find_binary (CPP_BINS, CPP_PATHS, cpp_bin_test) if not _cpp_bin_cache and cpp_bin_test ('c++'): _cpp_bin_cache = popen.popen_sync ('which c++') # Find the cc binary return _cpp_bin_cache
def cpp_bin_test (path_cpp): # Sometimes this outputs stdout info to stderr ret = popen.popen_sync ('%s -v'%(path_cpp), stdout=True, stderr=True) if specific_version and not specific_version in ret.get('stdout','')+ret.get('stderr', ''): return False return True
def __init__ (self): # Get server info try: ret = popen.popen_sync ("%s -i" %(CHEROKEE_WORKER)) self._server_info = ret['stdout'] except: self._server_info = ''
def java_bin_test (path_java): # Sometimes this outputs stdout info to stderr ret = popen.popen_sync ('%s -version'%(path_java), stdout=True, stderr=True) output = ret.get('stdout','') + ret.get('stderr', '') if specific_version and not specific_version in output: return False return True
def figure_modules(): """Return list of modules available to PHP""" php_path = path_find_binary(DEFAULT_BINS, extra_dirs=DEFAULT_PATHS, custom_test=__test_php_fcgi) ret = popen.popen_sync("%s -m" % (php_path)) modules = re.findall("(^[a-zA-Z0-9].*$)", ret["stdout"], re.MULTILINE) return modules
def cpp_bin_test(path_cpp): # Sometimes this outputs stdout info to stderr ret = popen.popen_sync('%s -v' % (path_cpp), stdout=True, stderr=True) if specific_version and not specific_version in ret.get( 'stdout', '') + ret.get('stderr', ''): return False return True
def _Setup_unpack(): url_download = CTK.cfg.get_val("tmp!market!install!download") # has it been downloaded? pkg_filename = url_download.split("/")[-1] package_path = CTK.cfg.get_val("tmp!market!install!local_package") if not package_path or not os.path.exists(package_path): down_entry = CTK.DownloadEntry_Factory(url_download) package_path = down_entry.target_path # Create the local directory target_path = os.path.join(CHEROKEE_OWS_ROOT, str(int(time.time() * 100))) os.mkdir(target_path, 0700) CTK.cfg["tmp!market!install!root"] = target_path # Create the log file Install_Log.set_file(os.path.join(target_path, "install.log")) # Uncompress try: if sys.version_info < ( 2, 5, ): # tarfile module prior to 2.5 is useless to us: http://bugs.python.org/issue1509889 raise tarfile.CompressionError Install_Log.log("Unpacking %s with Python" % (package_path)) tar = tarfile.open(package_path, "r:gz") for tarinfo in tar: Install_Log.log(" %s" % (tarinfo.name)) tar.extract(tarinfo, target_path) ret = {"retcode": 0} except tarfile.CompressionError: command = "gzip -dc '%s' | tar xfv -" % (package_path) Install_Log.log( "Unpacking %(package_path)s with the GZip binary (cd: %(target_path)s): %(command)s" % (locals()) ) ret = popen.popen_sync(command, cd=target_path) Install_Log.log(ret["stdout"]) Install_Log.log(ret["stderr"]) # Set default permission Install_Log.log("Setting default permission 755 for directory %s" % (target_path)) os.chmod( target_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH, ) # Remove the package if package_path.startswith(CHEROKEE_OWS_DIR): Install_Log.log("Skipping removal of: %s" % (package_path)) else: Install_Log.log("Removing %s" % (package_path)) os.unlink(package_path) return ret
def __safe_call__ (self): box = CTK.Box() buttons = CTK.DruidButtonsPanel() pre = 'tmp!market!install' root = CTK.cfg.get_val ('%s!root' %(pre)) project = os.path.join (root, 'project') trac_src = os.path.join (root, 'trac') trac_admin = os.path.join (root, 'bin', 'trac-admin') easy_bin = os.path.join (root, 'bin', 'easy_install') group_root = SystemInfo.get_info()['group_root'] server_user = CTK.cfg.get_val ('server!user', 'root') server_group = CTK.cfg.get_val ('server!group', group_root) # Figure out PYTHONPATH ret = popen.popen_sync ('python setup.py install --prefix=%(root)s'%(locals()), cd = '%(root)s/Genshi-0.6'%(locals())) err = ret['stderr'] + ret['stdout'] # Python 2.4.3 actually succeeds tmp = re.findall (r' (%(root)s.+site-packages)'%(locals()), err) PYTHONPATH = tmp[0] CTK.cfg['tmp!market!install!trac!PYTHONPATH'] = PYTHONPATH # Create site-packages if not os.path.isdir (PYTHONPATH): os.makedirs (PYTHONPATH) # Build PYTHONPATH env = os.environ.copy() if 'PYTHONPATH' in env: env['PYTHONPATH'] = '%s:%s' %(PYTHONPATH, env['PYTHONPATH']) else: env['PYTHONPATH'] = PYTHONPATH # Installation tasks = [ # Install dependencies ({'command': "python setup.py install --prefix=${app_root}", 'env': env, 'cd': '%(root)s/flup-1.0.2' %(locals())}), ({'command': "python setup.py install --prefix=${app_root}", 'env': env, 'cd': '%(root)s/Genshi-0.6' %(locals())}), #({'command': "python setup.py install --prefix=${app_root}", 'env': env, 'cd': '%(root)s/pysqlite-2.6.0'%(locals())}), ({'function': tools.install_pysqlite, 'description': _('Satisfying pysqlite requirements'), 'params' : {'root':root, 'env':str(env)}}), ({'command': "python %(trac_src)s/setup.py install --prefix=${app_root}" %(locals()), 'env': env, 'cd': trac_src}), # Create Project ({'command': "%(trac_admin)s %(project)s initenv <<EOF\nTrac\n\nEOF\n" %(locals()), 'env': env}), ({'command': "chown -R %(server_user)s:%(server_group)s %(project)s" %(locals())})] box += CTK.RawHTML ('<h2>%s</h2>' %(_('Installing Trac'))) box += CTK.RawHTML ('<p>%s</p>' %(_('This process may take a while. Please, hold on.'))) box += CommandProgress (tasks, URL_USER_CONFIG) buttons = CTK.DruidButtonsPanel() buttons += CTK.DruidButton_Close(_('Cancel')) box += buttons return box.Render().toStr()
def _read_cpu_info (self): ret = popen.popen_sync ("/usr/sbin/psrinfo -v") tmp = re.findall ("^Status of.+processor", ret['stdout'], re.I) self.cpu.num = len(tmp) tmp = re.findall ("operates at (\d+) MHz", ret['stdout'], re.I) if tmp: self.cpu.speed = '%s MHz' %(max([int(x) for x in tmp]))
def _read_cpu_info(self): ret = popen.popen_sync("/usr/sbin/psrinfo -v") tmp = re.findall("^Status of.+processor", ret['stdout'], re.I) self.cpu.num = len(tmp) tmp = re.findall("operates at (\d+) MHz", ret['stdout'], re.I) if tmp: self.cpu.speed = '%s MHz' % (max([int(x) for x in tmp]))
def _read_profiler(self): ret = popen.popen_sync("/usr/sbin/system_profiler SPHardwareDataType") self.cpu.speed = re.findall(r'Processor Speed: (.*?)\n', ret['stdout'], re.I)[0] self.cpu.num = re.findall(r'Number of Processors: (\d+)', ret['stdout'], re.I)[0] self.cpu.cores = re.findall(r'Total Number of Cores: (\d+)', ret['stdout'], re.I)[0]
def _Setup_unpack(): url_download = CTK.cfg.get_val('tmp!market!install!download') # has it been downloaded? pkg_filename = url_download.split('/')[-1] package_path = CTK.cfg.get_val('tmp!market!install!local_package') if not package_path or not os.path.exists(package_path): down_entry = CTK.DownloadEntry_Factory(url_download) package_path = down_entry.target_path # Create the local directory target_path = os.path.join(CHEROKEE_OWS_ROOT, str(int(time.time() * 100))) os.mkdir(target_path, 0700) CTK.cfg['tmp!market!install!root'] = target_path # Create the log file Install_Log.set_file(os.path.join(target_path, "install.log")) # Uncompress try: if sys.version_info < ( 2, 5 ): # tarfile module prior to 2.5 is useless to us: http://bugs.python.org/issue1509889 raise tarfile.CompressionError Install_Log.log("Unpacking %s with Python" % (package_path)) tar = tarfile.open(package_path, 'r:gz') for tarinfo in tar: Install_Log.log(" %s" % (tarinfo.name)) tar.extract(tarinfo, target_path) ret = {'retcode': 0} except tarfile.CompressionError: command = "gzip -dc '%s' | tar xfv -" % (package_path) Install_Log.log( "Unpacking %(package_path)s with the GZip binary (cd: %(target_path)s): %(command)s" % (locals())) ret = popen.popen_sync(command, cd=target_path) Install_Log.log(ret['stdout']) Install_Log.log(ret['stderr']) # Set default permission Install_Log.log("Setting default permission 755 for directory %s" % (target_path)) os.chmod( target_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH) # Remove the package if package_path.startswith(CHEROKEE_OWS_DIR): Install_Log.log("Skipping removal of: %s" % (package_path)) else: Install_Log.log("Removing %s" % (package_path)) os.unlink(package_path) return ret
def ruby_version (): """Report version of Ruby interpreter detected on the system. ruby_version() will return the version found, or nothing""" bin = detect_ruby() ret = popen.popen_sync ('%s -v'%(bin), stdout=True, stderr=True) tmp = re.findall ('ruby ([\d.]+)', ret.get('stdout','')) if tmp: return tmp[0]
def _exe(cmd, error_msg): Install_Log.log(" %s" % (cmd)) ret = popen.popen_sync(cmd) if ret["retcode"]: Install_Log.log(" ERROR: %s" % (error_msg)) ret["command"] = cmd ret["error"] = error_msg return ret
def ruby_version(): """Report version of Ruby interpreter detected on the system. ruby_version() will return the version found, or nothing""" bin = detect_ruby() ret = popen.popen_sync('%s -v' % (bin), stdout=True, stderr=True) tmp = re.findall('ruby ([\d.]+)', ret.get('stdout', '')) if tmp: return tmp[0]
def _figure_pid (self): # Execture ps ret = popen.popen_sync ("ps aux") ps = ret['stdout'] # Try to find the Cherokee process for l in ps.split("\n"): if "cherokee " in l and "-C %s"%(CTK.cfg.file) in l: pid = filter (lambda x: x.isdigit(), l.split())[0] self.pid = int(pid)
def figure_modules(): """Return list of modules available to PHP""" php_path = path_find_binary (DEFAULT_BINS, extra_dirs = DEFAULT_PATHS, custom_test = __test_php_fcgi) ret = popen.popen_sync ('%s -m' %(php_path)) modules = re.findall('(^[a-zA-Z0-9].*$)', ret['stdout'], re.MULTILINE) return modules
def _exe(cmd, error_msg): Install_Log.log(" %s" % (cmd)) ret = popen.popen_sync(cmd) if ret['retcode']: Install_Log.log(" ERROR: %s" % (error_msg)) ret['command'] = cmd ret['error'] = error_msg return ret
def java_bin_test(path_java): # Sometimes this outputs stdout info to stderr ret = popen.popen_sync('%s -version' % (path_java), stdout=True, stderr=True) output = ret.get('stdout', '') + ret.get('stderr', '') if specific_version and not specific_version in output: return False return True
def _is_bin_version (bin, required_version): ret = popen.popen_sync ("'%s' -V"%(bin)) tmp = re.findall (r'Python ([\d.]+)', ret['stderr'], re.M) if not tmp: return v_int = version_to_int (tmp[0]) r_int = version_to_int (required_version) return v_int >= r_int
def _figure_pid(self): # Execture ps ret = popen.popen_sync("ps aux") ps = ret['stdout'] # Try to find the Cherokee process for l in ps.split("\n"): if "cherokee " in l and "-C %s" % (CTK.cfg.file) in l: pid = filter(lambda x: x.isdigit(), l.split())[0] self.pid = int(pid)
def _read_hostname(self): # Read /etc/hostname if os.access("/etc/hostname", os.R_OK): fd = open("/etc/hostname", 'r') self.hostname = fd.readline().strip() fd.close() return # Execute /bin/hostname ret = popen.popen_sync("/bin/hostname") self.hostname = ret['stdout'].split('\n')[0].strip()
def _read_hostname (self): # Read /etc/hostname if os.access ("/etc/hostname", os.R_OK): fd = open ("/etc/hostname", 'r') self.hostname = fd.readline().strip() fd.close() return # Execute /bin/hostname ret = popen.popen_sync ("/bin/hostname") self.hostname = ret['stdout'].split('\n')[0].strip()
def delete_sample_data (root): market.Install_Log.log ("Sample Data Removal.") props = os.path.join (root, 'liferay', 'data', 'hsql', 'lportal.properties') script = os.path.join (root, 'liferay', 'data', 'hsql', 'lportal.script') hook = os.path.join (root, 'liferay', 'tomcat', 'webapps', 'sevencogs-hook') ret = popen.popen_sync ('rm -rf %s %s %s' %(props, script, hook), retcode=True) if ret['retcode']: msg = "Error: Unable to remove 7Cogs sample data." market.Install_Log.log (" %s" %(msg)) raise EnvironmentError, msg market.Install_Log.log (" 7Cogs sample data removed.")
def __safe_call__ (self): pre = 'tmp!market!install' root = CTK.cfg.get_val ('%s!root' %(pre)) # Paths dirpath = os.path.join (root, 'wsgidav') envpath = os.path.join (dirpath, 'installation') # Python interpreter py_interpreter = python.find_python("2.5", or_greater=True) # Create path ret = popen.popen_sync ('%(py_interpreter)s setup.py install --prefix=%(envpath)s'%(locals()), cd = '%(root)s/setuptools-0.6c11'%(locals())) err = ret['stderr'] tmp = re.findall (r' (%(root)s.+site-packages)'%(locals()), err) if tmp: PYTHONPATH = tmp[0] else: # Something like {root}/wsgidav/installation/lib/python2.5/site-packages/ py_version = 'pyton' + '.'.join (map(str, sys.version_info[0:2])) PYTHONPATH = os.path.join (envpath, lib, py_version, site-packages) os.makedirs (PYTHONPATH) # Python path env = os.environ.copy() if 'PYTHONPATH' in env: env['PYTHONPATH'] = '%s:%s:%s' %(envpath, PYTHONPATH, env['PYTHONPATH']) else: env['PYTHONPATH'] = '%s:%s' %(envpath, PYTHONPATH) # Commands tasks = [ # Setuptools ({'command': "${py_interpreter} setup.py install --prefix=${envpath}", 'env': env, 'cd': '%(root)s/setuptools-0.6c11' %(locals())}), # uWSGI ({'command': "${py_interpreter} uwsgiconfig.py --build", 'env': env, 'cd': os.path.join (root, 'uwsgi')}), # WSGIDav ({'command': "${py_interpreter} setup.py develop --install-dir=${envpath}", 'env': env, 'cd': dirpath})] box = CTK.Box() box += CTK.RawHTML ('<h2>%s</h2>' %(_('Installing WsgiDAV'))) box += CTK.RawHTML ('<p>%s</p>' %(_('This process may take a while. Please, hold on.'))) command = CommandProgress (tasks, URL_DAV_CONFIG) command['envpath'] = envpath command['dirpath'] = dirpath command['py_interpreter'] = py_interpreter box += command return box.Render().toStr()
def _get_PHP_modules (self): # PHP binary php_path = php_fpm._find_binary() if not php_path: return [] # Execute php -m ret = popen.popen_sync ('%s -m' %(php_path)) # Parse output modules = re.findall('(^[a-zA-Z0-9].*$)', ret['stdout'], re.MULTILINE) return modules
def _get_PHP_modules(self): # PHP binary php_path = php_fpm._find_binary() if not php_path: return [] # Execute php -m ret = popen.popen_sync("%s -m" % (php_path)) # Parse output modules = re.findall("(^[a-zA-Z0-9].*$)", ret["stdout"], re.MULTILINE) return modules
def figure_connection_params (username, password): ret = popen.popen_sync ("mysqladmin '-u%(username)s' '-p%(password)s' variables"%(locals())) # Socket tmp = re.findall (r' socket +\| (.+?) ', ret['stdout'], re.M) if tmp: return tmp[0] # Port tmp = re.findall (r' port +\| (.+?) ', ret['stdout'], re.M) if tmp: port = tmp[0] return ("localhost", port)
def delete_sample_data(root): market.Install_Log.log("Sample Data Removal.") props = os.path.join(root, 'liferay', 'data', 'hsql', 'lportal.properties') script = os.path.join(root, 'liferay', 'data', 'hsql', 'lportal.script') hook = os.path.join(root, 'liferay', 'tomcat', 'webapps', 'sevencogs-hook') ret = popen.popen_sync('rm -rf %s %s %s' % (props, script, hook), retcode=True) if ret['retcode']: msg = "Error: Unable to remove 7Cogs sample data." market.Install_Log.log(" %s" % (msg)) raise EnvironmentError, msg market.Install_Log.log(" 7Cogs sample data removed.")
def fix_context(root, target_directory): """Change Liferay context from / to target_directory""" market.Install_Log.log("Root Context adjustment.") if not target_directory: market.Install_Log.log( " Installing as Virtual Server. Root context change not needed." ) return src = os.path.join(root, 'liferay', 'tomcat', 'webapps', 'ROOT') dst = os.path.join(root, 'liferay', 'tomcat', 'webapps', target_directory.strip('/')) ret = popen.popen_sync('mv %s %s' % (src, dst), retcode=True) if ret['retcode']: msg = "Error: Unable to move ROOT directory." market.Install_Log.log(" %s" % (msg)) raise EnvironmentError, msg try: path = os.path.join(dst, 'WEB-INF', 'classes', 'portal-ext.properties') open(path, 'w').write('portal.ctx=%s\n' % (target_directory)) except: msg = "Error: Unable to write portal-ext.properties." market.Install_Log.log(" %s" % (msg)) raise EnvironmentError, msg src = os.path.join(root, 'liferay', 'tomcat', 'conf', 'Catalina', 'localhost', 'ROOT.xml') dst = os.path.join(root, 'liferay', 'tomcat', 'conf', 'Catalina', 'localhost', '%s.xml' % (target_directory.strip('/'))) ret = popen.popen_sync('mv %s %s' % (src, dst), retcode=True) if ret['retcode']: msg = "Error: Unable to move XML file." market.Install_Log.log(" %s" % (msg)) raise EnvironmentError, msg market.Install_Log.log(" Root Context successfuly changed to %s." % (target_directory))
def _read_hostname(self): # First try: uname() self.hostname = os.uname()[1] if self.hostname: return # Second try: sysctl() ret = popen.popen_sync("/sbin/sysctl -n kern.hostname") self.hostname = ret['stdout'].rstrip() if self.hostname: return # Could not figure it out self.hostname = "Unknown"
def figure_connection_params(username, password): ret = popen.popen_sync( "mysqladmin '-u%(username)s' '-p%(password)s' variables" % (locals())) # Socket tmp = re.findall(r' socket +\| (.+?) ', ret['stdout'], re.M) if tmp: return tmp[0] # Port tmp = re.findall(r' port +\| (.+?) ', ret['stdout'], re.M) if tmp: port = tmp[0] return ("localhost", port)
def _read_hostname (self): # First try: uname() self.hostname = os.uname()[1] if self.hostname: return # Second try: sysctl() ret = popen.popen_sync ("/sbin/sysctl -n kern.hostname") self.hostname = ret['stdout'].rstrip() if self.hostname: return # Could not figure it out self.hostname = "Unknown"
def launch (root): cmd = 'nohup %(root)s/liferay/tomcat/bin/startup.sh > /dev/null 2>&1' %(locals()) if os.getuid() == 0: web_user = CTK.cfg.get_val ('server!user', str(os.getuid())) cmd = 'su %s -c "%s"' %(web_user, cmd) market.Install_Log.log ("Launching Liferay. Command: %s" %(cmd)) ret = popen.popen_sync (cmd) if ret['retcode'] == 0: market.Install_Log.log ("Success: Liferay launched") else: market.Install_Log.log ("Error: Liferay not launched.\n%s" %(ret['stderr'])) return ret
def make_install_init(self): # System Info system_info = SystemInfo.get_info() OS = system_info.get('system', '').lower() # Fetch Parameters root = CTK.cfg.get_val('%s!root' % (PRE)) nagiosuser = CTK.cfg.get_val('%s!nagiosuser' % (PRE)) if OS == 'linux': ret = popen.popen_sync("make install-init", cd="%(root)s/nagios_core" % (locals())) if ret['retcode']: return ret elif OS == 'darwin': path_pre = os.path.join(root, 'nrpe.plist.pre') path_plist = os.path.join(root, 'nrpe.plist') # Build plist file plist = open(path_pre, 'r').read() plist = plist.replace('${UserName}', nagiosuser) plist = plist.replace('${WorkingDirectory}', os.path.join(root, 'nagios')) f = open(path_plist, 'w+') f.write(plist) f.close() else: # Default case. ret = popen.popen_sync("make install-init", cd="%(root)s/nagios_core" % (locals())) if ret['retcode']: return ret return {'retcode': 0}
def launch (root): cmd = 'nohup %(root)s/nuxeo/bin/nuxeoctl startbg' %(locals()) if os.getuid() == 0: web_user = CTK.cfg.get_val ('server!user', str(os.getuid())) cmd = 'su %s -c "%s"' %(web_user, cmd) market.Install_Log.log ("Launching Nuxeo. Command: %s" %(cmd)) ret = popen.popen_sync (cmd) if ret['retcode'] == 0: market.Install_Log.log ("Success: Nuxeo launched") else: market.Install_Log.log ("Error: Nuxeo not launched.\n%s" %(ret['stderr'])) return ret
def _read_info_cpu_and_mem(self): # cpu related ncpus = 0 vcpus = 0 clock = '' # mem related psize = 0 pcount = 0 # Execute sysctl. Depending on the version of FreeBSD some of # these keys might not exist. Thus, /sbin/sysctl is executed # with a single key, so in case one were not supported the # rest would not be ignored. (~ Reliability for efficiency) # for key in ("hw.ncpu", "hw.clockrate", "hw.pagesize", "kern.threads.virtual_cpu", "vm.stats.vm.v_page_count"): ret = popen.popen_sync("/sbin/sysctl %s" % (key)) lines = filter(lambda x: x, ret['stdout'].split('\n')) for line in lines: parts = line.split() if parts[0] == 'hw.ncpu:': ncpus = int(parts[1]) elif parts[0] == 'hw.clockrate:': clock = parts[1] elif parts[0] == 'kern.threads.virtual_cpu:': vcpus = parts[1] elif parts[0] == 'vm.stats.vm.v_page_count:': pcount = int(parts[1]) elif parts[0] == 'hw.pagesize:': psize = int(parts[1]) # Deal with cores if vcpus: self.cpu.num = str(int(vcpus) / int(ncpus)) self.cpu.cores = vcpus else: self.cpu.num = int(ncpus) self.cpu.cores = int(ncpus) # Global speed self.cpu.speed = '%s MHz' % (clock) # Physical mem self.mem.total = (psize * pcount) / 1024
def _read_info_cpu_and_mem (self): # cpu related ncpus = 0 vcpus = 0 clock = '' # mem related psize = 0 pcount = 0 # Execute sysctl. Depending on the version of FreeBSD some of # these keys might not exist. Thus, /sbin/sysctl is executed # with a single key, so in case one were not supported the # rest would not be ignored. (~ Reliability for efficiency) # for key in ("hw.ncpu", "hw.clockrate", "hw.pagesize", "kern.threads.virtual_cpu", "vm.stats.vm.v_page_count"): ret = popen.popen_sync ("/sbin/sysctl %s"%(key)) lines = filter (lambda x: x, ret['stdout'].split('\n')) for line in lines: parts = line.split() if parts[0] == 'hw.ncpu:': ncpus = int(parts[1]) elif parts[0] == 'hw.clockrate:': clock = parts[1] elif parts[0] == 'kern.threads.virtual_cpu:': vcpus = parts[1] elif parts[0] == 'vm.stats.vm.v_page_count:': pcount = int(parts[1]) elif parts[0] == 'hw.pagesize:': psize = int(parts[1]) # Deal with cores if vcpus: self.cpu.num = str (int(vcpus) / int(ncpus)) self.cpu.cores = vcpus else: self.cpu.num = int (ncpus) self.cpu.cores = int (ncpus) # Global speed self.cpu.speed = '%s MHz' %(clock) # Physical mem self.mem.total = (psize * pcount) / 1024
def launch(root): cmd = 'nohup %(root)s/liferay/tomcat/bin/startup.sh > /dev/null 2>&1' % ( locals()) if os.getuid() == 0: web_user = CTK.cfg.get_val('server!user', str(os.getuid())) cmd = 'su %s -c "%s"' % (web_user, cmd) market.Install_Log.log("Launching Liferay. Command: %s" % (cmd)) ret = popen.popen_sync(cmd) if ret['retcode'] == 0: market.Install_Log.log("Success: Liferay launched") else: market.Install_Log.log("Error: Liferay not launched.\n%s" % (ret['stderr'])) return ret
def launch(root): cmd = 'nohup %(root)s/nuxeo/bin/nuxeoctl startbg' % (locals()) if os.getuid() == 0: web_user = CTK.cfg.get_val('server!user', str(os.getuid())) cmd = 'su %s -c "%s"' % (web_user, cmd) market.Install_Log.log("Launching Nuxeo. Command: %s" % (cmd)) ret = popen.popen_sync(cmd) if ret['retcode'] == 0: market.Install_Log.log("Success: Nuxeo launched") else: market.Install_Log.log("Error: Nuxeo not launched.\n%s" % (ret['stderr'])) return ret
def _Handle_Unpacking(self): if not self.targz_path: return [] assert self.app_dir # Create the app directory if not os.path.exists(self.app_dir): os.makedirs(self.app_dir) # Unpack command = "gzip -dc '%s' | tar xfv -" % (self.targz_path) Install_Log.log("(cd: %s): %s" % (self.app_dir, command)) ret = popen.popen_sync(command, cd=self.app_dir) Install_Log.log(ret['stdout']) Install_Log.log(ret['stderr']) return []
def app_database_remove(app, user, passw, db_type): # MySQL if db_type == 'MySQL': params = "-u'%(user)s'" % (locals()) if passw: params += " -p'%(passw)s'" % (locals()) cmd = "mysql %(params)s -e 'DROP DATABASE IF EXISTS market_%(app)s'" % ( locals()) # PostgreSQL elif db_type == 'PostgreSQL': cmd = "PGUSER='******' PGPASSWORD='******' psql -c 'DROP DATABASE IF EXISTS market_%(app)s'" % ( locals()) else: return ret = popen.popen_sync(cmd) if ret['retcode'] != 0: return ret['stderr']
def drush_site_install(): dbtype = CTK.cfg.get_val('tmp!market!install!db!db_type') kwargs = cli_installation_command() ret = popen.popen_sync(**kwargs) if ret['retcode'] != 0 and dbtype == 'mysql': # # Workaround -- http://drupal.org/node/898152 # "trying to connect via unix:///var/mysql/mysql.sock" # By some reason, PDO uses the wrong socket to access MySQL. # # 1.- Find out what PHP's PDO tried to access pdo_path_re = re.findall(r'\(trying to connect via unix\:\/\/(.+?)\)', ret['stdout'] + ret['stderr'], re.M) # 2.- Check where MySQL's socket is actually dbuser = CTK.cfg.get_val('tmp!market!install!db!db_user') dbpass = CTK.cfg.get_val('tmp!market!install!db!db_pass') mysqladmin_bin = database.mysql_bins(database.MYSQLADMIN_BIN_NAMES) ret_vars = popen.popen_sync( "%(mysqladmin_bin)s '-u%(dbuser)s' '-p%(dbpass)s' variables" % (locals())) mysql_vars_re = re.findall(r' socket +\| (.+?) ', ret_vars['stdout'], re.M) if mysql_vars_re: mysql_sock = mysql_vars_re[0] else: mysql_sock = "/tmp/mysql.sock" # 3.- Create a link if pdo_path_re: pdo_sock = pdo_path_re[0] pdo_sock_dir = os.path.dirname(pdo_sock) if os.path.exists(mysql_sock) and not os.path.exists(pdo_sock): popen.popen_sync("mkdir -p '%s'" % (pdo_sock_dir)) popen.popen_sync("ln -s '%s' '%s'" % (mysql_sock, pdo_sock)) ret = popen.popen_sync(**kwargs) return ret