   (let [working-dir (working-dir params)
         wrapper-file (doto (clj-fs/file (wrapper-file-path params))
                        clj-fs/create
-                       .deleteOnExit
                        (spit (wrapper-body params))
                        (.setExecutable true false))]
     (logging/debug {:WRAPPER-FILE (.getAbsolutePath wrapper-file)})

  (try (merge-params script-atom
                     {:started_at (time/now)
                      :state "executing"
                      :watchdog (create-watchdog)})
       ; do it again because the env vars must be already in place when calling
       ; create-script-file and create-wrapper-file
       (merge-params script-atom
                     {:script-file (create-script-file @script-atom)
                      :wrapper-file (create-wrapper-file @script-atom)})
       (let [exec-future (exec-sh script-atom)]
         (merge-params script-atom {:exec-future exec-future})
         (wait-for-or-terminate script-atom)
         (merge-params script-atom (get-final-parameters @exec-future)))
       script-atom
       (catch Exception e
         (set-script-atom-for-execption script-atom e)

(defn- create-script-file [params]
  (let [script (:body params)
        script-file (clj-fs/file (script-file-path params))]
    (doto script-file
      clj-fs/create (spit script) (.setExecutable true false))
    (.getAbsolutePath script-file)))


