Advertisement
yacel100

fabfile.py

Sep 7th, 2017
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.27 KB | None | 0 0
  1. from fabric.api import env
  2. import sys
  3. from ilogue.fexpect import expect, expecting, run , sudo
  4.  
  5. def instalar_pxp():
  6.  
  7.     question = raw_input("Nombre del sistema : ")
  8.     nombre_sistema = question
  9.     proxy = "" 
  10.     version = run("grep -o release.. /etc/redhat-release")
  11.  
  12.  
  13. # cambio de los archivos pg_hba y postgres.config#
  14.    
  15.     archi=open("/var/lib/pgsql/9.5/data/pg_hba.conf",'w')
  16.        
  17.     archi.write("# TYPE  DATABASE        USER            ADDRESS                 METHOD\n\n")
  18.     archi.write("# 'local' is for Unix domain socket connections only\n")
  19.     archi.write("local   all        postgres,dbkerp_conexion,db" + nombre_sistema + "_conexion                  trust\n")
  20.     archi.write("local   all             all                                     md5\n")
  21.     archi.write("# IPv4 local connections:\n")
  22.     archi.write("host    all             all             127.0.0.1/32            md5\n")
  23.     archi.write("host    all             all             192.168.0.0/16          md5\n")
  24.     archi.write("# IPv6 local connections:\n")
  25.     archi.write("host    all             all             ::1/128                 md5\n")
  26.     archi.close()
  27.  
  28.    
  29.    
  30.    
  31.     ## de aca empezamos a editar para crear un nuevo sistema
  32.     db_pass = "postgres"
  33.     sudo('psql -c "CREATE DATABASE db'+ nombre_sistema +' WITH ENCODING=\'UTF-8\';"', user='postgres')
  34.     sudo('psql -c "CREATE USER db'+ nombre_sistema +'_conexion WITH PASSWORD \'db'+ nombre_sistema +'_conexion\';"', user='postgres')
  35.     sudo('psql -c "ALTER ROLE db'+ nombre_sistema +'_conexion SUPERUSER;"', user='postgres')
  36.     sudo('psql -c "CREATE USER db'+ nombre_sistema +'_admin WITH PASSWORD \'a1a69c4e834c5aa6cce8c6eceee84295\';"', user='postgres')
  37.     sudo('psql -c "ALTER ROLE db'+ nombre_sistema +'_admin SUPERUSER;"', user='postgres')
  38.    
  39.     if(version == 'release 7'):
  40.         run('systemctl restart postgresql-9.5')
  41.     else:
  42.         run('service postgresql-9.5 restart')
  43.  
  44. # instalacion de git para poder bajar el repositoriio pxp y moviendo a la carpeta /var/www/html/kerp/#
  45.    
  46.     run("mkdir /var/www/html/"+ nombre_sistema)
  47.     run("mkdir /var/www/html/"+ nombre_sistema +"/pxp")
  48.        
  49.     #Si existe proxy se configura github para el proxy
  50.     run("git clone https://github.com/kplian/pxp.git /var/www/html/"+nombre_sistema+"/pxp")
  51.     run("chown -R apache.apache /var/www/html/"+nombre_sistema+"/")
  52.     run("chmod 700 -R /var/www/html/"+nombre_sistema+"/")
  53.  
  54. # haciendo una copia de datosgenerales.samples.php y modificando archivo#
  55.     f = open("/var/www/html/"+nombre_sistema+"/pxp/lib/DatosGenerales.sample.php")
  56.     g = open("/var/www/html/"+nombre_sistema+"/pxp/lib/DatosGenerales.php","w")
  57.     linea = f.readline()
  58.     while linea != "":
  59.         g.write(linea)
  60.         linea = f.readline()
  61.  
  62.     g.close()
  63.     f.close()
  64.     #TODO    VOLVER VARIABLE LA CARPETA PRINCIPAL KERP
  65.     f = open("/var/www/html/"+nombre_sistema+"/pxp/lib/DatosGenerales.php",'r')
  66.     chain = f.read()
  67.     chain = chain.replace("/web/lib/lib_control/","/"+nombre_sistema+"/pxp/lib/lib_control/")
  68.     chain = chain.replace("/kerp-boa/","/"+nombre_sistema+"/")
  69.     chain = chain.replace("dbkerp_conexion","db"+nombre_sistema+"_conexion")
  70.     chain = chain.replace("dbkerp","db"+nombre_sistema)
  71.  
  72.    
  73.    
  74.     chain = chain.replace("/var/lib/pgsql/9.1/data/pg_log/","/var/lib/pgsql/9.5/data/pg_log/")
  75.    
  76.  
  77.     f.close()
  78.     otro = open("/var/www/html/"+nombre_sistema+"/pxp/lib/DatosGenerales.php",'w')
  79.     otro.write(chain)
  80.     otro.close()
  81.  
  82.  
  83.     run("ln -s /var/www/html/"+nombre_sistema+"/pxp/lib /var/www/html/"+nombre_sistema+"/lib")
  84.     run("ln -s /var/www/html/"+nombre_sistema+"/pxp/index.php /var/www/html/"+nombre_sistema+"/index.php")
  85.     run("ln -s /var/www/html/"+nombre_sistema+"/pxp/sis_generador /var/www/html/"+nombre_sistema+"/sis_generador")
  86.     run("ln -s /var/www/html/"+nombre_sistema+"/pxp/sis_organigrama /var/www/html/"+nombre_sistema+"/sis_organigrama")
  87.     run("ln -s /var/www/html/"+nombre_sistema+"/pxp/sis_parametros /var/www/html/"+nombre_sistema+"/sis_parametros")
  88.     run("ln -s /var/www/html/"+nombre_sistema+"/pxp/sis_seguridad /var/www/html/"+nombre_sistema+"/sis_seguridad")
  89.     run("ln -s /var/www/html/"+nombre_sistema+"/pxp/sis_workflow /var/www/html/"+nombre_sistema+"/sis_workflow")
  90.    
  91.  
  92.    
  93.     archi=open('/var/www/html/'+nombre_sistema+'/sistemas.txt','w')
  94.     archi.close()
  95.    
  96.    
  97.     run("mkdir /var/www/html/"+nombre_sistema+"/reportes_generados")
  98.    
  99.     run("sudo setfacl -R -m u:apache:wrx /var/www/html/"+nombre_sistema+"/reportes_generados")
  100.    
  101. #   sudo("yum -y install rpm-build")
  102.    
  103.     run("sudo setfacl -R -m u:postgres:wrx /var/www/html")
  104.    
  105.     run("sudo chcon -Rv --type=httpd_sys_rw_content_t /var/www/html/"+nombre_sistema+"/")
  106.     run("sudo setsebool -P httpd_can_network_connect_db=1")
  107.    
  108.     run("sudo setsebool -P httpd_can_network_connect 1")
  109.  
  110.    
  111.     run("php /var/www/html/"+nombre_sistema+"/lib/ratchet/pxp-Server.php > /dev/null 2>&1 &")
  112.    
  113.     prompts = []
  114.     prompts += expect('Ingrese una opcion.*','1')
  115.     prompts += expect('Ingrese el nombre de la BD.*','db'+nombre_sistema)  
  116.     prompts += expect('Desea obtener un backup de la BD.*','NO')
  117.     prompts += expect('los datos de prueba.*','n') 
  118.    
  119.     with expecting(prompts):
  120.         sudo("/var/www/html/"+nombre_sistema+"/pxp/utilidades/restaurar_bd/./restaurar_todo.py" , user="postgres")
  121.        
  122. def prueba_local():
  123.     prompts = []
  124.     prompts += expect('is your.*','Jaime')
  125.     prompts += expect('you at stack.*','si')           
  126.    
  127.     with expecting(prompts):
  128.         run("python /root/prueba_local.py")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement