   (c/su
     (cu/install-tarball! node url base-dir force?)
     (c/exec :mkdir (str base-dir "/log"))
-    (c/exec :mkdir :-p (str voltroot "/log"))
     (cu/ensure-user! username)
     (c/exec :chown :-R (str username ":" username) base-dir)
 

  [test]
  (remove nil? (pmap up? (:nodes test))))

(defn await-start
    "Blocks until the logfile reports 'Server completed initialization'."
  [node]
  (info "Waiting for" node "to start at voltroot:" voltroot )
  (def done false)

       (loop [x 50]
       (try
           (c/sudo username
                   (c/cd voltroot

                         (Thread/sleep 5000)
                         (info node (c/exec :tail :-n 5 "log/volt.log"))
                         (c/exec :tail :-n 5 "log/volt.log"
                                 | :grep :-m 1 :-E "completed initialization|Node rejoin completed"
                                 )))

                   (info node "started")
                   (def done true )
	       (catch Exception e (info node "waiting for startup " x " retries left" ) )
       )

       (when (and (not done) (> x 0))
            (recur (dec x)))
       )
       (when (not done)
            (throw (RuntimeException.
                    (str node " failed to start in time; STDOUT:\n\n"
                        (meh (c/exec :tail :-n 10
                                      (str base-dir "/log/stdout.log")))
                         "\n\nLOG:\n\n"
                         (meh (c/exec :tail :-n 10
                                      (str voltroot "/log/volt.log")))
                         "\n\n")))
        )
   "done"
)

(defn await-rejoin
  "Blocks until the logfile reports 'Node rejoin completed'"
  [node]
  (info "Waiting for" node "to rejoin")
  (def done 0)
  (timeout 240000
           (throw (RuntimeException.
                    (str node " failed to rejoin in time; STDOUT:\n\n"
                        (meh (c/exec :tail :-n 10
                                      (str base-dir "/log/stdout.log")))
                         "\n\nLOG:\n\n"
                         (meh (c/exec :tail :-n 10
                                      (str voltroot "/log/volt.log")))
                         "\n\n")))


  (loop [x 100]
  (info node " NOT rejoined, " x "attempts left")
  (try
  (c/sudo username
          (c/cd voltroot
                ; hack hack hack
                (Thread/sleep 2000)
                (c/exec :tail :-n 1 :-f "log/volt.log"
                        | :grep :-m 1 "Node rejoin completed"
                        | :xargs (c/lit "echo \"\" >> log/volt.log \\;")))
          (info node "rejoined"))
          ( def done 1 )

   (catch RuntimeException e (info node "waiting for rejoin" ) )
   )

   (when (and (> x 0 ) (= done 0))
   	(recur (dec x)))
   )
   )
)



(defn start-daemon!
  "Starts the daemon with the given command."

                                   :pidfile (str base-dir "/pidfile")
                                   :chdir   base-dir}
                                  (str base-dir "/bin/voltdb")
                                  cmd
                                  :--deployment (str base-dir "/deployment.xml")
                                  :--host host))))

(defn start!
  "Starts voltdb, creating a fresh DB"
  [test node]
  (start-daemon! test :create (jepsen/primary test))
  (await-initialization node))

(defn recover!
  "Recovers an entire cluster, or with a node, a single node."
