src/Pure/Tools/phabricator.scala
changeset 71053 ba14aa0b5a5d
parent 71052 6bf53035baf0
child 71054 b64fc38327ae
equal deleted inserted replaced
71052:6bf53035baf0 71053:ba14aa0b5a5d
   220     config.execute("config set storage.mysql-engine.max-size 8388608")
   220     config.execute("config set storage.mysql-engine.max-size 8388608")
   221 
   221 
   222     config.execute("storage upgrade --force")
   222     config.execute("storage upgrade --force")
   223 
   223 
   224 
   224 
       
   225     /* SSH hosting */
       
   226 
       
   227     progress.echo("SSH hosting setup...")
       
   228 
       
   229     val ssh_port = ssh_alternative2
       
   230 
       
   231     config.execute("config set diffusion.ssh-user " + Bash.string(name))
       
   232     config.execute("config set diffusion.ssh-port " + ssh_port)
       
   233 
       
   234     val sudoers_file = Path.explode("/etc/sudoers.d") + Path.basic(isabelle_phabricator_name())
       
   235     File.write(sudoers_file,
       
   236       www_user + " ALL=(" + daemon_user + ") SETENV: NOPASSWD: /usr/bin/git, /usr/bin/hg, /usr/bin/ssh, /usr/bin/id\n" +
       
   237       name + " ALL=(" + daemon_user + ") SETENV: NOPASSWD: /usr/bin/git, /usr/bin/git-upload-pack, /usr/bin/git-receive-pack, /usr/bin/hg, /usr/bin/svnserve, /usr/bin/ssh, /usr/bin/id\n")
       
   238 
       
   239     Isabelle_System.bash("chmod 0440 " + File.bash_path(sudoers_file)).check
       
   240 
       
   241 
       
   242     /* PHP setup */
       
   243 
       
   244     val php_version =
       
   245       Isabelle_System.bash("""php --run 'echo PHP_MAJOR_VERSION . "." . PHP_MINOR_VERSION;'""")
       
   246         .check.out
       
   247 
       
   248     val php_conf =
       
   249       Path.explode("/etc/php") + Path.basic(php_version) +  // educated guess
       
   250         Path.explode("apache2/conf.d") +
       
   251         Path.basic(isabelle_phabricator_name(ext = "ini"))
       
   252 
       
   253     File.write(php_conf,
       
   254       "post_max_size = 32M\n" +
       
   255       "opcache.validate_timestamps = 0\n" +
       
   256       "memory_limit = 512M\n")
       
   257 
       
   258 
       
   259     /* Apache setup */
       
   260 
       
   261     progress.echo("Apache setup...")
       
   262 
       
   263     val apache_root = Path.explode(options.string("phabricator_apache_root"))
       
   264     val apache_sites = apache_root + Path.explode("sites-available")
       
   265 
       
   266     if (!apache_sites.is_dir) error("Bad Apache sites directory " + apache_sites)
       
   267 
       
   268     val server_name = phabricator_name(ext = "lvh.me")  // alias for "localhost" for testing
       
   269     val server_url = "http://" + server_name
       
   270 
       
   271     File.write(apache_sites + Path.basic(isabelle_phabricator_name(ext = "conf")),
       
   272 """<VirtualHost *:80>
       
   273     ServerName """ + server_name + """
       
   274     ServerAdmin webmaster@localhost
       
   275     DocumentRoot """ + config.home.implode + """/webroot
       
   276 
       
   277     ErrorLog ${APACHE_LOG_DIR}/error.log
       
   278     RewriteEngine on
       
   279     RewriteRule ^(.*)$  /index.php?__path__=$1  [B,L,QSA]
       
   280 </VirtualHost>
       
   281 
       
   282 # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
       
   283 """)
       
   284 
       
   285     Isabelle_System.bash( """
       
   286       set -e
       
   287       a2enmod rewrite
       
   288       a2ensite """ + Bash.string(isabelle_phabricator_name())).check
       
   289 
       
   290     Linux.service_restart("apache2")
       
   291 
       
   292 
   225     /* PHP daemon */
   293     /* PHP daemon */
   226 
   294 
   227     progress.echo("PHP daemon setup...")
   295     progress.echo("PHP daemon setup...")
   228 
   296 
   229     config.execute("config set phd.user " + Bash.string(daemon_user))
   297     config.execute("config set phd.user " + Bash.string(daemon_user))
   245 [Install]
   313 [Install]
   246 WantedBy=multi-user.target
   314 WantedBy=multi-user.target
   247 """)
   315 """)
   248 
   316 
   249 
   317 
   250     /* SSH hosting */
       
   251 
       
   252     progress.echo("SSH hosting setup...")
       
   253 
       
   254     val ssh_port = ssh_alternative2
       
   255 
       
   256     config.execute("config set diffusion.ssh-user " + Bash.string(name))
       
   257     config.execute("config set diffusion.ssh-port " + ssh_port)
       
   258 
       
   259     val sudoers_file = Path.explode("/etc/sudoers.d") + Path.basic(isabelle_phabricator_name())
       
   260     File.write(sudoers_file,
       
   261       www_user + " ALL=(" + daemon_user + ") SETENV: NOPASSWD: /usr/bin/git, /usr/bin/hg, /usr/bin/ssh, /usr/bin/id\n" +
       
   262       name + " ALL=(" + daemon_user + ") SETENV: NOPASSWD: /usr/bin/git, /usr/bin/git-upload-pack, /usr/bin/git-receive-pack, /usr/bin/hg, /usr/bin/svnserve, /usr/bin/ssh, /usr/bin/id\n")
       
   263 
       
   264     Isabelle_System.bash("chmod 0440 " + File.bash_path(sudoers_file)).check
       
   265 
       
   266 
       
   267     /* PHP setup */
       
   268 
       
   269     val php_version =
       
   270       Isabelle_System.bash("""php --run 'echo PHP_MAJOR_VERSION . "." . PHP_MINOR_VERSION;'""")
       
   271         .check.out
       
   272 
       
   273     val php_conf =
       
   274       Path.explode("/etc/php") + Path.basic(php_version) +  // educated guess
       
   275         Path.explode("apache2/conf.d") +
       
   276         Path.basic(isabelle_phabricator_name(ext = "ini"))
       
   277 
       
   278     File.write(php_conf,
       
   279       "post_max_size = 32M\n" +
       
   280       "opcache.validate_timestamps = 0\n" +
       
   281       "memory_limit = 512M\n")
       
   282 
       
   283 
       
   284     /* Apache setup */
       
   285 
       
   286     progress.echo("Apache setup...")
       
   287 
       
   288     val apache_root = Path.explode(options.string("phabricator_apache_root"))
       
   289     val apache_sites = apache_root + Path.explode("sites-available")
       
   290 
       
   291     if (!apache_sites.is_dir) error("Bad Apache sites directory " + apache_sites)
       
   292 
       
   293     val server_name = phabricator_name(ext = "lvh.me")  // alias for "localhost" for testing
       
   294     val server_url = "http://" + server_name
       
   295 
       
   296     File.write(apache_sites + Path.basic(isabelle_phabricator_name(ext = "conf")),
       
   297 """<VirtualHost *:80>
       
   298     ServerName """ + server_name + """
       
   299     ServerAdmin webmaster@localhost
       
   300     DocumentRoot """ + config.home.implode + """/webroot
       
   301 
       
   302     ErrorLog ${APACHE_LOG_DIR}/error.log
       
   303     RewriteEngine on
       
   304     RewriteRule ^(.*)$  /index.php?__path__=$1  [B,L,QSA]
       
   305 </VirtualHost>
       
   306 
       
   307 # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
       
   308 """)
       
   309 
       
   310     Isabelle_System.bash( """
       
   311       set -e
       
   312       a2enmod rewrite
       
   313       a2ensite """ + Bash.string(isabelle_phabricator_name())).check
       
   314 
       
   315     Linux.service_restart("apache2")
       
   316 
       
   317     progress.echo("\nDONE\nWeb configuration via " + server_url)
   318     progress.echo("\nDONE\nWeb configuration via " + server_url)
   318   }
   319   }
   319 
   320 
   320 
   321 
   321   /* Isabelle tool wrapper */
   322   /* Isabelle tool wrapper */