src/Pure/Tools/phabricator.scala
changeset 79513 292605271dcf
parent 79512 bf91c1aec34b
child 79515 fa581264522e
equal deleted inserted replaced
79512:bf91c1aec34b 79513:292605271dcf
    15 import scala.util.matching.Regex
    15 import scala.util.matching.Regex
    16 
    16 
    17 
    17 
    18 object Phabricator {
    18 object Phabricator {
    19   /** defaults **/
    19   /** defaults **/
       
    20 
       
    21   /* PHP */
       
    22 
       
    23   def php_version(): String =
       
    24     Isabelle_System.bash("""php --run 'echo PHP_MAJOR_VERSION . "." . PHP_MINOR_VERSION;'""")
       
    25       .check.out
       
    26 
       
    27   def php_conf_dir(name: String): Path =
       
    28     Path.explode("/etc/php") + Path.basic(php_version()) +  // educated guess
       
    29     Path.basic(name) + Path.explode("conf.d")
       
    30 
    20 
    31 
    21   /* webservers */
    32   /* webservers */
    22 
    33 
    23   sealed abstract class Webserver {
    34   sealed abstract class Webserver {
    24     override def toString: String = title
    35     override def toString: String = title
    25     def title: String
    36     def title: String
    26     def short_name: String
    37     def short_name: String
    27     def system_name: String = short_name
    38     def system_name: String = short_name
       
    39     def php_name: String = short_name
    28 
    40 
    29     def packages(): List[String]
    41     def packages(): List[String]
    30 
    42 
    31     def system_path: Path = Path.basic(system_name)
    43     def system_path: Path = Path.basic(system_name)
    32     def root_dir: Path = Path.explode("/etc") + system_path
    44     def root_dir: Path = Path.explode("/etc") + system_path
    34 
    46 
    35     def restart(): Unit = Linux.service_restart(system_name)
    47     def restart(): Unit = Linux.service_restart(system_name)
    36 
    48 
    37     def systemctl(cmd: String): String = "systemctl " + cmd + " " + system_name
    49     def systemctl(cmd: String): String = "systemctl " + cmd + " " + system_name
    38 
    50 
    39     def php_version(): String =
    51     def php_init(): Unit =
    40       Isabelle_System.bash("""php --run 'echo PHP_MAJOR_VERSION . "." . PHP_MINOR_VERSION;'""")
    52       File.write(php_conf_dir(php_name) + Path.basic(isabelle_phabricator_name(ext = "ini")),
    41         .check.out
    53         "post_max_size = 32M\n" +
    42 
    54         "opcache.validate_timestamps = 0\n" +
    43     def php_config: String =
    55         "memory_limit = 512M\n" +
    44       "post_max_size = 32M\n" +
    56         "max_execution_time = 120\n")
    45       "opcache.validate_timestamps = 0\n" +
       
    46       "memory_limit = 512M\n" +
       
    47       "max_execution_time = 120\n"
       
    48 
       
    49     def php_init(): Unit = ()
       
    50 
    57 
    51     def site_name(name: String): String = isabelle_phabricator_name(name = name)
    58     def site_name(name: String): String = isabelle_phabricator_name(name = name)
    52 
    59 
    53     def site_conf(name: String): Path =
    60     def site_conf(name: String): Path =
    54       sites_dir + Path.basic(isabelle_phabricator_name(name = name, ext = "conf"))
    61       sites_dir + Path.basic(isabelle_phabricator_name(name = name, ext = "conf"))
    59   object Apache extends Webserver {
    66   object Apache extends Webserver {
    60     override val title = "Apache"
    67     override val title = "Apache"
    61     override val short_name = "apache"
    68     override val short_name = "apache"
    62     override def system_name = "apache2"
    69     override def system_name = "apache2"
    63     override def packages(): List[String] = List("apache2", "libapache2-mod-php")
    70     override def packages(): List[String] = List("apache2", "libapache2-mod-php")
    64 
       
    65     override def php_init(): Unit = {
       
    66       val php_conf =
       
    67         Path.explode("/etc/php") + Path.basic(php_version()) +  // educated guess
       
    68         Path.basic(system_name) + Path.explode("conf.d") +
       
    69         Path.basic(isabelle_phabricator_name(ext = "ini"))
       
    70       File.write(php_conf, php_config)
       
    71     }
       
    72 
    71 
    73     override def site_init(name: String, server_name: String, webroot: String): Unit = {
    72     override def site_init(name: String, server_name: String, webroot: String): Unit = {
    74       File.write(site_conf(name),
    73       File.write(site_conf(name),
    75 """<VirtualHost *:80>
    74 """<VirtualHost *:80>
    76     ServerName """ + server_name + """
    75     ServerName """ + server_name + """
    94   }
    93   }
    95 
    94 
    96   object Nginx extends Webserver {
    95   object Nginx extends Webserver {
    97     override val title = "Nginx"
    96     override val title = "Nginx"
    98     override val short_name = "nginx"
    97     override val short_name = "nginx"
       
    98     override val php_name = "fpm"
    99     override def packages(): List[String] = List("nginx", "php-fpm")
    99     override def packages(): List[String] = List("nginx", "php-fpm")
   100 
   100 
   101     override def site_init(name: String, server_name: String, webroot: String): Unit = {
   101     override def site_init(name: String, server_name: String, webroot: String): Unit = {
   102       File.write(site_conf(name),
   102       File.write(site_conf(name),
   103 """
   103 """