def setup(setting): print "in python setup: %s" % setting assert_available(setting) if not run("python --version") == "Python 2.7.11": old_python_path = run( "echo `head -n1 /usr/bin/yum`|readlink -f `cut -c3-`") if run("%s --version" % (old_python_path)) == "Python 2.6.6": old_python_path = "/usr/bin/python2.6" run("tar xf %s" % ("Python-2.7.11.tgz")) with cd("Python-2.7.11"): run("./configure >> fabric.log") run("make -j %s >> fabric.log && make install >> fabric.log" % (setting["_cpu_count"])) run("ln -sf /usr/local/bin/python /usr/bin/python") for old_require_file in ("/usr/bin/yum", "/usr/libexec/urlgrabber-ext-down", "/usr/sbin/yum-complete-transaction"): if fab_exists(old_require_file): run("sed -i \"1c #!%s\" %s" % (old_python_path, old_require_file)) run("python get-pip.py >> fabric.log") run("ln -sf /usr/local/bin/pip /usr/bin/pip") if not fab_exists("~/.pip/"): run("/bin/mkdir -p %s" % ("~/.pip/")) run("/bin/cp -f pip.conf ~/.pip/") # use proxy to install pip modules if proxy exists if setting.get("all_proxy"): with ("export all_proxy=\"%s\"" % (setting["all_proxy"])): run("pip install supervisor virtualenv >> fabric.log") else: run("pip install supervisor virtualenv >> fabric.log") if not fab_exists("/etc/supervisor/supervisord.conf"): run("mkdir -p /etc/supervisor/conf") run("/bin/cp -f supervisord.conf /etc/supervisor/") run("/bin/cp -f start /etc/supervisor/") run("chown -R %s /etc/supervisor" % (setting["deployer_name"])) sudo( "/usr/local/bin/supervisord -c /etc/supervisor/supervisord.conf", user=setting["deployer_name"]) if not fab_exists("/home/%s/python_project/logs" % (setting["deployer_name"])): sudo("mkdir -p /home/%s/python_project/logs" % (setting["deployer_name"]), user=setting["deployer_name"]) else: print "%s had been built" % "Python-2.7.11"
def setup(setting): print "in nginx setup: %s" % setting assert_available(setting) # build luajit if luajit do not exists if not fab_exists("/usr/local/bin/%s" % ("luajit-2.0.4")): if fab_exists("LuaJIT-2.0.4"): run("rm %s -rf" % ("LuaJIT-2.0.4")) run("tar xf %s" % ("LuaJIT-2.0.4.tar.gz")) with cd("LuaJIT-2.0.4"): run("make -j %s >> fabric.log && make install >> fabric.log" % (setting["_cpu_count"])) else: print "%s had been built" % "luajit-2.0.4" if not fab_exists("/opt/dependence"): run("/bin/mkdir -p %s" % ("/opt/dependence")) if not fab_exists("/opt/dependence/%s" % ("lua-nginx-module-0.10.2")): run("tar xf %s" % ("lua-nginx-module-0.10.2.tar.gz")) run("/bin/mv -f %s /opt/dependence" % ("lua-nginx-module-0.10.2")) if not fab_exists("/opt/dependence/%s" % ("ngx_devel_kit-0.2.19")): run("tar xf %s" % ("ngx_devel_kit-0.2.19.tar.gz")) run("/bin/mv -f %s /opt/dependence" % ("ngx_devel_kit-0.2.19")) # build nginx if nginx do not exists if not fab_exists("/opt/%s/conf" % ("nginx-1.10.0")): if fab_exists("nginx-1.10.0"): run("rm %s -rf" % ("nginx-1.10.0")) run("tar xf %s" % ("nginx-1.10.0.tar.gz")) with cd("nginx-1.10.0"), prefix( "export LUAJIT_LIB=/usr/local/lib"), prefix( "export LUAJIT_INC=/usr/local/include/luajit-2.0"): run(" ".join([ "./configure --prefix=%s" % ("/opt/nginx-1.10.0"), "--with-ld-opt=\"-Wl,-rpath,/usr/local/lib\"", "--with-http_stub_status_module", "--with-http_ssl_module", "--add-module=/opt/dependence/%s" % ("ngx_devel_kit-0.2.19"), "--add-module=/opt/dependence/%s" % ("lua-nginx-module-0.10.2"), ">> fabric.log", ])) run("make -j %s >> fabric.log && make install >> fabric.log" % (setting["_cpu_count"])) run("chmod 733 /opt/%s/logs" % ("nginx-1.10.0")) run("/bin/cp -f nginx.conf /opt/%s/conf" % ("nginx-1.10.0")) run("/bin/cp -f nginx /etc/init.d/") run("chmod +x /etc/init.d/nginx") run("chkconfig nginx --add") run("chkconfig nginx on") run("service nginx start") run("service nginx status") else: print "%s had been built" % "nginx-1.10.0"
def install(): """Install the pipeline on the specified cluster """ logger.debug("Installing pipeline...") local_root = os.environ['ROOT'] remote_root = app_config['root'] if local_exec: if abspath(local_root) == abspath(remote_root): logger.error("Source and destination folder are the same") exit(1) if exists(remote_root): if confirm("Existing data will be deleted. Do you want to proceed anyway?", default=False): rmtree(remote_root) else: logger.error("Pipeline destination folder already exists") exit(2) copytree(local_root, remote_root) local(remote_root+'/utils/install.sh') else: if app_config["use_sudo"]: run_fn = sudo else: run_fn = run if not fab_exists(remote_root): logging.debug("Building remote directory...") run_fn("mkdir -p "+remote_root) else: if not confirm("Existing data will be deleted. Do you want to proceed anyway?", default=False): logger.error("Pipeline destination folder already exists") exit(2) logging.debug("Uploading project...") upload_project( local_dir=local_root, remote_dir=remote_root, use_sudo=app_config["use_sudo"] ) if run_fn(remote_root+"/utils/auth.sh").failed: logger.error("An error occured with modifying the right for the pipeline") exit(3) if run(remote_root+"/utils/install.sh").failed: logger.error("An error occured with the install script") exit(4) logger.info("Pipeline successfully installed")
def setup(setting): print "in python setup: %s" % setting assert_available(setting) if not fab_exists("/opt/%s" % ("mongodb-3.4.3")): run("tar xf %s" % ("mongodb-linux-x86_64-rhel62-3.4.3.tgz")) run("/bin/mv -f %s %s" % ("mongodb-linux-x86_64-rhel62-3.4.3", "mongodb-3.4.3")) with cd("mongodb-3.4.3"): run("mkdir %s %s %s %s %s %s" % ("data", "log", "scripts", "backup", "conf", "keys")) run("openssl rand -base64 741 >%s" % ("keys/replkey")) run("chmod 400 %s" % ("keys/replkey")) run("/bin/cp -f %s %s" % ("mongodb.conf", "mongodb-3.4.3/conf/")) run("groupadd mongodb") run("useradd -r -g mongodb -s /bin/false mongodb") run("chown -R mongodb.mongodb %s" % ("mongodb-3.4.3")) run("echo \"never\" > /sys/kernel/mm/transparent_hugepage/enabled") run("echo \"never\" > /sys/kernel/mm/transparent_hugepage/defrag") run("sysctl vm.swappiness=1") run("/bin/mv -f %s /opt/%s" % ("mongodb-3.4.3", "mongodb-3.4.3")) run("/bin/cp -f mongodb /etc/init.d/") run("chmod +x /etc/init.d/mongodb") run("chkconfig mongodb --add") run("chkconfig mongodb on") run("service mongodb start") print ''' ############ 配置服务并且启动 ## > bin/mongo use admin db.createUser({user:"******", pwd:"g/fHthsi83d3*d+9dg", roles:[{role:"root", db:"admin"}]}) db.auth("sysdba", "g/fHthsi83d3*d+9dg") show dbs ############ 配置身份验证并且重启mongodb ## ..mongodb.conf: authorization: enabled ## > service mongodb stop && service mongodb start ''' else: print "%s had been built" % "mongodb-3.4.3"
def run(self): if fab_exists(self.cert_path): reg = self.regenerate if self.regenerate is None: reg = confirm('regenerate ssl files?', default=False) if not reg: return tmp_dir = '/tmp/{}'.format(uuid.uuid4().hex) run('mkdir {}'.format(tmp_dir)) with cd(tmp_dir): if self.certificates is None: onetime_pass = uuid.uuid4().hex run('openssl genrsa -des3 -out server.key ' '-passout pass:{} 2048'.format(onetime_pass)) run('openssl req -passin pass:{} -new -key server.key ' '-out server.csr'.format(onetime_pass)) run('cp server.key server.key.org') run('openssl rsa -passin pass:{} -in server.key.org ' '-out server.key'.format(onetime_pass)) run('openssl x509 -req -days 365 -in server.csr ' '-signkey server.key -out server.crt') else: for i in self.certificates: put(i, 'crt') run('cat crt >> server.crt') put(self.private_key, 'server.org.key') p = self.private_key_password if self.private_key_password is None: p = prompt('enter private key password') if p: run('openssl rsa -passin pass:{} -in ' 'server.org.key -out server.key'.format(p)) else: run('cp server.org.key server.key') _run = run if self.use_sudo: _run = sudo remote_dir = os.path.dirname(self.remote_path) _run('mkdir -p {}'.format(remote_dir)) _run('cp server.crt {}'.format(self.cert_path)) _run('cp server.key {}'.format(self.key_path)) run('rm -rf {}'.format(tmp_dir))
def exists(func, path): if func == run: return fab_exists(path) else: return os.path.exists(path)
def exists_local(path, use_sudo=False, verbose=False): if is_local(): return os.path.exists(path) else: return fab_exists(path, use_sudo=use_sudo, verbose=verbose)