mirror of
https://github.com/vale981/stream
synced 2025-03-05 10:01:39 -05:00
implement writing a unit file
This commit is contained in:
parent
3ff5347d5b
commit
57ed429c6e
6 changed files with 69 additions and 4 deletions
|
@ -6,6 +6,7 @@
|
|||
:dependencies [[org.clojure/clojure "1.10.1"]
|
||||
[com.github.thjomnx/java-systemd "1.1.0"]
|
||||
[com.taoensso/timbre "4.10.0"]
|
||||
[cljstache/cljstache "2.0.6"]
|
||||
[org.clojure/core.async "1.2.603"]]
|
||||
:main ^:skip-aot stream.core
|
||||
:target-path "target/%s"
|
||||
|
|
8
resources/commander/templates/unit.mustache
Normal file
8
resources/commander/templates/unit.mustache
Normal file
|
@ -0,0 +1,8 @@
|
|||
[Unit]
|
||||
Description={{ description }}
|
||||
|
||||
[Service]
|
||||
ExecStart={{ command }}
|
||||
|
||||
[Install]
|
||||
WantedBy={{ target }}
|
11
src/stream/commander/api.clj
Normal file
11
src/stream/commander/api.clj
Normal file
|
@ -0,0 +1,11 @@
|
|||
(ns stream.commander.api)
|
||||
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
; Globals, Structures and State ;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
;; TODO: specs
|
||||
(defrecord process
|
||||
[unit-name monitor-channel ffmpeg-config problems])
|
||||
(def processes (ref {}))
|
33
src/stream/commander/impl.clj
Normal file
33
src/stream/commander/impl.clj
Normal file
|
@ -0,0 +1,33 @@
|
|||
(ns stream.commander.impl
|
||||
(:require [cljstache.core :as template]
|
||||
[clojure.java.io :as io]
|
||||
[taoensso.timbre :as timbre
|
||||
:refer [log trace debug info warn error fatal report
|
||||
logf tracef debugf infof warnf errorf fatalf reportf
|
||||
spy get-env]]))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
; Unit file Management ;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(defn- render-unit-file
|
||||
"Renders the unit file from a template.
|
||||
The template can be found at:
|
||||
resources/commander/templates/unit.mustache"
|
||||
[command description target]
|
||||
(template/render-resource "commander/templates/unit.mustache"
|
||||
{:description description
|
||||
:command command
|
||||
:target target}))
|
||||
|
||||
(defn create-unit-file!
|
||||
"Creates or overwrites a service unit file in the appropriate
|
||||
directory and returns the file path."
|
||||
[name command description target]
|
||||
(let [unit-contents (render-unit-file command description target)
|
||||
path (str (System/getProperty "user.home") "/.config/systemd/user/" name ".service")
|
||||
file (io/as-file path)]
|
||||
(.mkdirs (.getParentFile file))
|
||||
(spit path unit-contents)
|
||||
(debug "Wrote a unit file to:" path)
|
||||
path))
|
16
test/stream/commander_test.clj
Normal file
16
test/stream/commander_test.clj
Normal file
|
@ -0,0 +1,16 @@
|
|||
(ns stream.commander-test
|
||||
(:require [stream.commander.impl :as impl]
|
||||
[stream.commander.api :as api]
|
||||
[clojure.test :refer :all]
|
||||
[clojure.java.io :as io]))
|
||||
|
||||
(deftest unit-files
|
||||
(testing "The rendering."
|
||||
(is (#'impl/render-unit-file "test" "test" "test")))
|
||||
(let [name (str (java.util.UUID/randomUUID))]
|
||||
(testing "Writing a unit file."
|
||||
(let [file (io/as-file
|
||||
(impl/create-unit-file! name
|
||||
"test" "test" "test"))]
|
||||
(is (.exists file))
|
||||
(.delete file)))))
|
|
@ -1,7 +1,3 @@
|
|||
(ns stream.core-test
|
||||
(:require [clojure.test :refer :all]
|
||||
[stream.core :refer :all]))
|
||||
|
||||
(deftest a-test
|
||||
(testing "FIXME, I fail."
|
||||
(is (= 0 1))))
|
||||
|
|
Loading…
Add table
Reference in a new issue