src/Pure/System/linux.scala
changeset 73340 0ffcad1f6130
parent 73120 c3589f2dff31
child 73534 e7fb17bca374
equal deleted inserted replaced
73339:9efdebe24c65 73340:0ffcad1f6130
    93   def user_home(name: String): String = user_entry(name, 6)
    93   def user_home(name: String): String = user_entry(name, 6)
    94 
    94 
    95   def user_add(name: String,
    95   def user_add(name: String,
    96     description: String = "",
    96     description: String = "",
    97     system: Boolean = false,
    97     system: Boolean = false,
    98     ssh_setup: Boolean = false)
    98     ssh_setup: Boolean = false): Unit =
    99   {
    99   {
   100     require(!description.contains(','), "malformed description")
   100     require(!description.contains(','), "malformed description")
   101 
   101 
   102     if (user_exists(name)) error("User already exists: " + quote(name))
   102     if (user_exists(name)) error("User already exists: " + quote(name))
   103 
   103 
   122   /* system services */
   122   /* system services */
   123 
   123 
   124   def service_operation(op: String, name: String): Unit =
   124   def service_operation(op: String, name: String): Unit =
   125     Isabelle_System.bash("systemctl " + Bash.string(op) + " " + Bash.string(name)).check
   125     Isabelle_System.bash("systemctl " + Bash.string(op) + " " + Bash.string(name)).check
   126 
   126 
   127   def service_enable(name: String) { service_operation("enable", name) }
   127   def service_enable(name: String): Unit = service_operation("enable", name)
   128   def service_disable(name: String) { service_operation("disable", name) }
   128   def service_disable(name: String): Unit = service_operation("disable", name)
   129   def service_start(name: String) { service_operation("start", name) }
   129   def service_start(name: String): Unit = service_operation("start", name)
   130   def service_stop(name: String) { service_operation("stop", name) }
   130   def service_stop(name: String): Unit = service_operation("stop", name)
   131   def service_restart(name: String) { service_operation("restart", name) }
   131   def service_restart(name: String): Unit = service_operation("restart", name)
   132 
   132 
   133   def service_shutdown(name: String)
   133   def service_shutdown(name: String): Unit =
   134   {
       
   135     try { service_stop(name) }
   134     try { service_stop(name) }
   136     catch { case ERROR(_) => }
   135     catch { case ERROR(_) => }
   137   }
       
   138 
   136 
   139   def service_install(name: String, spec: String)
   137   def service_install(name: String, spec: String): Unit =
   140   {
   138   {
   141     service_shutdown(name)
   139     service_shutdown(name)
   142 
   140 
   143     val service_file = Path.explode("/lib/systemd/system") + Path.basic(name).ext("service")
   141     val service_file = Path.explode("/lib/systemd/system") + Path.basic(name).ext("service")
   144     File.write(service_file, spec)
   142     File.write(service_file, spec)