support for system services;
authorwenzelm
Tue, 05 Nov 2019 16:47:59 +0100
changeset 71048 5f02ecbb19d6
parent 71047 87c132cf5860
child 71049 f4b9dd5ab0cc
support for system services;
src/Pure/System/linux.scala
--- a/src/Pure/System/linux.scala	Tue Nov 05 14:28:00 2019 +0100
+++ b/src/Pure/System/linux.scala	Tue Nov 05 16:47:59 2019 +0100
@@ -104,4 +104,25 @@
       """).check
     }
   }
+
+
+  /* system services */
+
+  def service_start(name: String): Unit =
+    Isabelle_System.bash("systemctl start " + Bash.string(name)).check
+
+  def service_stop(name: String): Unit =
+    Isabelle_System.bash("systemctl stop " + Bash.string(name)).check
+
+  def service_install(name: String, spec: String)
+  {
+    val service_file = Path.explode("/lib/systemd/system") + Path.basic(name).ext("service")
+    File.write(service_file, spec)
+
+    Isabelle_System.bash("""
+      set -e
+      chmod 0644 """ + File.bash_path(service_file) + """
+      systemctl enable """ + Bash.string(name) + """
+      systemctl start """ + Bash.string(name)).check
+  }
 }