test/dummy/bin/corre in msip-2.2.0.alfa3 vs test/dummy/bin/corre in msip-2.2.0.beta1
- old
+ new
@@ -1,6 +1,8 @@
#!/usr/bin/env ruby
+# frozen_string_literal: true
+
# Ejecuta aplicación usando Procfile de ser posible
# Si hay un archivo .env toma variables de configuración de ese
# Las variables usadas son:
# RAILS_ENV: Modo de ejecución development, production (o test que no se usa)
# RC: Script de arranque en modo producción en /etc/rc.d/
@@ -8,111 +10,109 @@
# IPDES: En modo desarrollo IP por usar
# R: Si tiene un valor ejecuta rápido (no instala dependencias ni elimina caches ni regenera recursos)
# Aunque si el valor es r recompila (sin eliminar dependencias)
# Y si el valor es f o si no hay Procfile no intenta correr con foreman
-require 'fileutils'
-#require 'byebug'
+require "fileutils"
+# require 'byebug'
# ENV.each {|l,v| puts "#{l}=#{v}" } # Depuración
# Ruta a directorio raíz de aplicación
-RAIZ_AP = File.expand_path('..', __dir__)
+RAIZ_AP = File.expand_path("..", __dir__)
def system!(*args)
system(*args) || abort("\n== Falló la orden #{args} ==")
end
-FileUtils.chdir RAIZ_AP do
-
- if File.exists?('./.env')
- require 'dotenv'
+FileUtils.chdir(RAIZ_AP) do
+ if File.exist?("./.env")
+ require "dotenv"
Dotenv.load
end
- if !ENV['RC'] || ENV['RC'] == ''
- nap=`git remote -v | grep "(fetch)" | sed -e "s/.*\\/\\(.*\\) (fetch)/\\1/g"`
- if !nap || nap == ''
- nap = 'apconmsip'
+ if !ENV["RC"] || ENV["RC"] == ""
+ nap = %x(git remote -v | grep "(fetch)" | sed -e "s/.*\\/\\(.*\\) (fetch)/\\1/g")
+ if !nap || nap == ""
+ nap = "apconmsip"
end
- ENV['RC'] = nap.strip
+ ENV["RC"] = nap.strip
end
- puts "\n== Ejecutando aplicacion #{ENV['RC']} =="
+ puts "\n== Ejecutando aplicacion #{ENV["RC"]} =="
- if !File.exists?('/tmp/node')
+ unless File.exist?("/tmp/node")
puts "\n== Enlace a /usr/local/bin/node desde /tmp =="
- system! 'doas ln -s /usr/local/bin/node /tmp'
+ system! "doas ln -s /usr/local/bin/node /tmp"
end
- if !ENV['RAILS_ENV'] || ENV['RAILS_ENV'] == ''
- ENV['RAILS_ENV'] = 'development'
+ if !ENV["RAILS_ENV"] || ENV["RAILS_ENV"] == ""
+ ENV["RAILS_ENV"] = "development"
end
- if !ENV['PUERTODES']
- ENV['PUERTODES'] = '2300'
+ unless ENV["PUERTODES"]
+ ENV["PUERTODES"] = "2300"
end
- if !ENV['IPDES'] || ENV['IPDES'] == ''
- ENV['IPDES'] = '127.0.0.1'
+ if !ENV["IPDES"] || ENV["IPDES"] == ""
+ ENV["IPDES"] = "127.0.0.1"
end
- if !ENV['R'] || ENV['R'] == ''
+ if !ENV["R"] || ENV["R"] == ""
puts "\n== Instalando dependencias =="
- system! 'gem install bundler --conservative'
- system('bundle check') || system!('bundle install')
+ system! "gem install bundler --conservative"
+ system("bundle check") || system!("bundle install")
# Instala dependencias Javascript
- system! 'CXX=c++ bin/yarn'
+ system! "CXX=c++ bin/yarn"
puts "\n== Preparando base de datos =="
- system! "RAILS_ENV=#{ENV['RAILS_ENV']} bin/rails db:prepare"
+ system! "RAILS_ENV=#{ENV["RAILS_ENV"]} bin/rails db:prepare"
puts "\n== Actualizando índices =="
- system!("RAILS_ENV=#{ENV['RAILS_ENV']} bin/rails msip:indices")
+ system!("RAILS_ENV=#{ENV["RAILS_ENV"]} bin/rails msip:indices")
puts "\n== Eliminando bitácoras y archivos temporales =="
- system! 'bin/rails log:clear tmp:clear'
+ system! "bin/rails log:clear tmp:clear"
end
- if !ENV['R'] || ENV['R'] == '' || ENV['R'] == 'r'
- puts "\n== Eliminando recursos public/packs* y public/#{ENV['RUTA_RELATIVA']}/assets/* =="
- system! 'rm -rf public/packs*'
- system! "rm -rf public/#{ENV['RUTA_RELATIVA']}/assets/*"
+ if !ENV["R"] || ENV["R"] == "" || ENV["R"] == "r"
+ puts "\n== Eliminando recursos public/packs* y public/#{ENV["RUTA_RELATIVA"]}/assets/* =="
+ system! "rm -rf public/packs*"
+ system! "rm -rf public/#{ENV["RUTA_RELATIVA"]}/assets/*"
system! "rm -rf app/assets/builds/*"
puts "\n== Enlaza controladores stimulus de motores =="
- system! 'bin/rails msip:stimulus_motores'
+ system! "bin/rails msip:stimulus_motores"
puts "\n== Crea recursos CSS y Javascript =="
- system! "RAILS_ENV=#{ENV['RAILS_ENV']} bin/rails assets:precompile --trace"
+ system! "RAILS_ENV=#{ENV["RAILS_ENV"]} bin/rails assets:precompile --trace"
end
- if ENV['RAILS_ENV'] == "development"
+ if ENV["RAILS_ENV"] == "development"
puts "\n== Ejecutando en modo desarrollo =="
- if File.exist?('Procfile') && ENV['R'] != 'f'
- ord="foreman start -f Procfile"
+ if File.exist?("Procfile") && ENV["R"] != "f"
+ ord = "foreman start -f Procfile"
else
ord = ""
- if ENV['CONFIG_HOSTS'] && ENV['CONFIG_HOSTS'] != ''
- ord += "CONFIG_HOSTS=\"#{ENV['CONFIG_HOSTS'].downcase}\" "
+ if ENV["CONFIG_HOSTS"] && ENV["CONFIG_HOSTS"] != ""
+ ord += "CONFIG_HOSTS=\"#{ENV["CONFIG_HOSTS"].downcase}\" "
end
ord += "RAILS_RELATIVE_URL_ROOT='' "
ord += "bin/rails s "
- if ENV['PUERTODES'] != ''
- ord += "-p #{ENV['PUERTODES']} "
+ if ENV["PUERTODES"] != ""
+ ord += "-p #{ENV["PUERTODES"]} "
end
- ord += "-b '#{ENV['IPDES']}' "
+ ord += "-b '#{ENV["IPDES"]}' "
end
- puts "#{ord}"
- elsif ENV['RAILS_ENV'] == 'production'
- if File.exists?('bin/corre-local')
- system!('bin/corre-local')
+ puts ord.to_s
+ elsif ENV["RAILS_ENV"] == "production"
+ if File.exist?("bin/corre-local")
+ system!("bin/corre-local")
end
- if !File.exists?("/etc/rc.d/#{ENV['RC']}")
- puts "\nFalta script /etc/rc.d/#{ENV['RC']}"
+ unless File.exist?("/etc/rc.d/#{ENV["RC"]}")
+ puts "\nFalta script /etc/rc.d/#{ENV["RC"]}"
exit 1
end
puts "\n== Ejecutando en modo producción =="
- ord = "doas sh /etc/rc.d/#{ENV['RC']} -d start"
+ ord = "doas sh /etc/rc.d/#{ENV["RC"]} -d start"
end
system!(ord)
-
end