-end\r
-\r
-\r
-\r
-class MiseEnProd\r
- @@rep_remote = '/var/www/euphorik'\r
- @@host = 'euphorik.ch'\r
- @@opt_rsync = ''\r
- \r
- def initialize \r
- end \r
-\r
- def creer_remote_rep(rep) \r
- begin\r
- `ssh #{@@host} "mkdir #{@@rep_remote}/#{rep}"`\r
- rescue\r
- end\r
- end\r
- \r
- def compiler_partie_serveuse\r
- Dir.chdir(@@rep_remote + '/modules')\r
- puts `make`\r
- if $?.exitstatus != 0\r
- puts "Echec de compilation de la partie serveuse"\r
- exit 1\r
- end\r
- Dir.chdir('..')\r
- end\r
- \r
- def creer_repertoire_bd \r
- # création du repertoire BD\r
- creer_remote_rep('BD')\r
- creer_remote_rep('BD/backup')\r
- `ssh #{@@host} "chmod g+w #{@@rep_remote}/BD"`\r
- end\r
- \r
- # css, images, html, etc..\r
- def copier_partie_statique \r
- print `rsync #{$opt_rsync} index.yaws #{$host}:#{$rep_remote}`\r
- print `rsync #{$opt_rsync} favicon.ico #{$host}:#{$rep_remote}`\r
- print `rsync #{$opt_rsync} -r css #{$host}:#{$rep_remote}`\r
- print `rsync #{$opt_rsync} -r pages #{$host}:#{$rep_remote}`\r
- print `rsync #{$opt_rsync} -r --exclude 'autres' img #{$host}:#{$rep_remote}` \r
- end\r
- \r
- # minification et package des fichiers js dans euphorik.js\r
- def pack_js\r
- # copie des js avec minification\r
- rep_js = 'js'\r
- creer_remote_rep(rep_js)\r
- Dir.entries(rep_js).each{|fichier|\r
- if fichier[0..0] != '.' and fichier != 'debug.js'\r
- puts "Minimisation et copie de #{fichier}"\r
- print `tools/jsmin.rb < #{rep_js}/#{fichier} | ssh #{@@host} "cat > #{@@rep_remote}/#{rep_js}/#{fichier}"`\r
- end\r
- } \r
- end\r
- \r
- def copie_modules_serveurs \r
- # copie des modules erlang\r
- creer_remote_rep('modules')\r
- `rsync #{@@opt_rsync} -r --exclude 'euphorik_test.beam' modules/ebin #{@@host}:#{@@rep_remote}/modules`\r
- `rsync #{@@opt_rsync} -r modules/include #{@@host}:#{@@rep_remote}/modules`\r
- end\r
- \r
- def set_droits_fichiers\r
- # attribution des droits\r
- `ssh #{$host} "chmod -R g+rx #{$rep_remote}"` \r
- end\r
- \r
- def maj\r
- # execution du script de mise à jour\r
- print `cat tools/mise_en_prod.erl | ssh #{$host} "cat > /tmp/mise_en_prod.erl"`\r
- print `ssh #{$host} "chmod u+x /tmp/mise_en_prod.erl; /tmp/mise_en_prod.erl; rm /tmp/mise_en_prod.erl"`\r
- end\r
-end\r
-\r
-\r
-#verifJS = VerifJS.new("../js")\r
-#verifJS.verifier()
+end
+
+# Permet la mise en production et preproduction
+class MiseEnProd
+ # obsolète !
+ @@rep_remote = '/var/www/euphorik'
+ @@host = 'euphorik.ch'
+
+ def initialize(racine)
+ Dir.chdir(racine)
+ end
+
+ # L'emplacement ou sont copié les fichiers
+ # A définir avant la mise en prod
+ def uri=(uri)
+ plop = uri.split(':')
+ @uri = plop[0]
+ @rep = plop[1]
+ end
+
+ # Effectue la mise en production.
+ def miseEnProd
+ copierFichiers()
+ maj('yaws')
+ end
+
+ # Effectue la mise en préproduction.
+ def miseEnPreProd
+ copierFichiers()
+ lancerYaws()
+ maj('yaws_dev')
+ end
+
+ def copierFichiers
+ compiler_partie_serveuse()
+ creer_repertoire_bd()
+ copier_partie_statique()
+ pack_js()
+ copie_modules_serveurs()
+ set_droits_fichiers()
+ end
+
+ def lancerYaws
+ creer_rep("tools")
+ system("rsync tools/yaws.conf #{@uri}:#{@rep}/tools")
+ system("rsync tools/start_yaws.sh #{@uri}:#{@rep}/tools")
+ system("ssh #{@uri} \"cd #{@rep}/tools; screen -d -m -S yaws_dev ./start_yaws.sh\"")
+ end
+
+ def exec(commande)
+ system("ssh #{@uri} \"cd #{@rep} && #{commande}\"")
+ end
+
+ def creer_rep(rep)
+ begin
+ exec("test -d #{rep} || mkdir #{rep}")
+ rescue
+ end
+ end
+
+ def compiler_partie_serveuse
+ log "compilation des modules serveur"
+ Dir.chdir('modules')
+ system("make")
+ if $?.exitstatus != 0
+ puts "Echec de compilation de la partie serveuse"
+ exit 1
+ end
+ Dir.chdir('..')
+ end
+
+ def creer_repertoire_bd
+ log "création du répertoire de la base de données"
+ # création du repertoire BD
+ creer_rep('BD')
+ creer_rep('BD/backups')
+ exec("chmod -R g+w BD")
+ end
+
+ # css, images, html, etc..
+ def copier_partie_statique
+ log "copie de la partie statique"
+ uri = "#{@uri}:#{@rep}"
+ system("awk '$0 !~ /prod=\"delete\"/' index.yaws | ssh #{@uri} \" cat > #{@rep}/index.yaws\"")
+ system("rsync favicon.ico #{uri}")
+ system("rsync --delete -r styles #{uri}")
+ system("rsync --delete -r pages #{uri}")
+ system("rsync --delete -r --exclude 'autres' img #{uri}")
+ end
+
+ # minification et package des fichiers js dans euphorik.js
+ def pack_js
+ log "minification, assemblage et copie du javascript"
+ rep_js = 'js'
+ creer_rep(rep_js)
+ # jquery.js et euphorik.js doivent se trouve en premier
+ fichiers = ['js/libs/jquery.js', 'js/euphorik.js'].concat(get_fichiers_js(rep_js))
+ commande_cat = "cat "
+ fichiers.each{|f|
+ commande_cat += f + " "
+ }
+ #copie des js concaténés avec minification
+ system("#{commande_cat} | tools/jsmin.rb | ssh #{@uri} \"cd #{@rep} && cat > #{rep_js}/euphorik.js\"")
+ end
+
+ #renvoie une liste des fichiers js
+ def get_fichiers_js(rep)
+ fichiers = []
+ Dir.entries(rep).each{|fichier|
+ if fichier[0..0] != '.' and fichier != 'euphorik.js' and fichier != 'jquery.js'
+ fichier = rep + "/" + fichier
+ if File.directory?(fichier)
+ fichiers.concat(get_fichiers_js(fichier))
+ else
+ fichiers << fichier
+ end
+ end
+ }
+ return fichiers
+ end
+
+ def copie_modules_serveurs
+ log "copie des modules du serveur"
+ # copie des modules erlang
+ creer_rep('modules')
+ system("rsync -r --exclude 'euphorik_test.beam' modules/ebin #{@uri}:#{@rep}/modules")
+ system("rsync -r modules/include #{@uri}:#{@rep}/modules")
+ end
+
+ def set_droits_fichiers
+ log "attribution des droits sur les fichiers"
+ # attribution des droits
+ exec("chmod -R g+rx .")
+ end
+
+ # noeud : le nom du noeud sur lequel le script de mise en prod est exécuté
+ # Execute le script 'mise_en_prod.erl' sur le serveur afin de :
+ # - Recharger les modules
+ # - Mettre à jour la base de données
+ def maj(noeud)
+ log "rechargement des modules serveur et mise à jour de la base de données"
+ # execution du script de mise à jour
+ system("cat tools/mise_en_prod.erl | ssh #{@uri} \"cat > /tmp/mise_en_prod.erl\"")
+ system("ssh #{@uri} \"chmod u+x /tmp/mise_en_prod.erl; /tmp/mise_en_prod.erl #{noeud}; rm /tmp/mise_en_prod.erl\"")
+ end
+
+ def log(message)
+ puts "----- #{message} -----"
+ end
+end
+
+
+# Traite la ligne de commande lorsque tools.rb est utilisé comme tel
+class Commande
+ def initialize
+ Dir.chdir("..")
+ @miseEnProd = MiseEnProd.new(".")
+ @verifJS = VerifJS.new("js")
+ @version = Version.new(".")
+ end
+
+ def traiter
+ if ARGV.size == 0
+ afficherUsage
+ return
+ end
+
+ case ARGV[0]
+ when 'prod'
+ @version.maj()
+ @miseEnProd.uri = "gburri@euphorik.ch:/var/www/euphorik"
+ @miseEnProd.miseEnProd()
+ when 'pre'
+ @version.maj()
+ @miseEnProd.uri = "gburri@euphorik.ch:/var/www/euphorik_preprod"
+ @miseEnProd.miseEnPreProd()
+ when 'js'
+ @verifJS.verifier()
+ when 'version'
+ @version.maj()
+ end
+ end
+
+ def afficherUsage
+ puts "Usage : tools.rb (prod | pre | js | version)\n" +
+ " prod : Mise en production\n" +
+ " pre : Mise en préproduction, copie les données en production\n" +
+ " js : vérification des fichiers JavaScript\n" +
+ " version : met à jour la version à partir du fichier VERSION"
+ end
+end