Skip to content

Instantly share code, notes, and snippets.

;; Pallet 0.3.0-SNAPSHOT
;; nodes.clj
(def service
(compute/compute-service "node-list"
:node-list [(node-list/make-node "virtualbox" "server-all"
"10.0.1.14" :ubuntu)]))
(core/defnode the-server
"One server to run everything (servlet, database, nginx, etc)."
David-Santiagos-Computer:servlet David$ cake pallet lift com.mysite.deploy.nodes/the-server
Oct 17, 2010 7:47:10 PM clojure.contrib.logging$impl_write_BANG_ invoke
INFO: retrieving nodes
Oct 17, 2010 7:47:10 PM clojure.contrib.logging$impl_write_BANG_ invoke
INFO: apply-phase :pre-configure for :the-server with 1 nodes
Oct 17, 2010 7:47:10 PM clojure.contrib.logging$impl_write_BANG_ invoke
INFO: apply-phase :configure for :the-server with 1 nodes
Oct 17, 2010 7:47:10 PM clojure.contrib.logging$impl_write_BANG_ invoke
INFO: Connecting to 10.0.1.14 port 22
Oct 17, 2010 7:47:10 PM clojure.contrib.logging$impl_write_BANG_ invoke
David-Santiagos-Computer:servlet David$ cake pallet lift com.davidsantiago.deploy.nodes/the-server
Oct 18, 2010 10:59:55 PM clojure.contrib.logging$impl_write_BANG_ invoke
INFO: retrieving nodes
Oct 18, 2010 10:59:55 PM clojure.contrib.logging$impl_write_BANG_ invoke
INFO: apply-phase :pre-configure for :the-server with 1 nodes
Oct 18, 2010 10:59:55 PM clojure.contrib.logging$impl_write_BANG_ invoke
INFO: apply-phase :configure for :the-server with 1 nodes
Oct 18, 2010 10:59:55 PM clojure.contrib.logging$impl_write_BANG_ invoke
INFO: Connecting to 10.0.1.14 port 22
Oct 18, 2010 10:59:55 PM clojure.contrib.logging$impl_write_BANG_ invoke
(defn postgresql-script
"Execute a postgresql script.
Options for how this script should be run:
:as-user username - Run this script having sudoed to this (system) user. Default: postgres"
[request sql-script & {:keys [as-user]
:as options
:or {as-user "postgres"}}]
(-> request
(exec-script/exec-checked-script
"PostgreSQL temp command file"
2010-10-29 22:17:05,273 INFO [pallet.core] (Thread-1) apply-phase :after-configure for :the-server with 1 nodes
2010-10-29 22:19:25,130 DEBUG [pallet.main-invoker] (Thread-1) OS Mac OS X 10.6.4
2010-10-29 22:19:25,130 DEBUG [pallet.main-invoker] (Thread-1) Arch i386
2010-10-29 22:19:25,131 DEBUG [pallet.main-invoker] (Thread-1) Admin user david
2010-10-29 22:19:25,131 DEBUG [pallet.main-invoker] (Thread-1) private-key-path /Users/David/.ssh/id_rsa true
2010-10-29 22:19:25,131 DEBUG [pallet.main-invoker] (Thread-1) public-key-path /Users/David/.ssh/id_rsa.pub true
2010-10-29 22:19:25,132 DEBUG [pallet.main-invoker] (Thread-1) Running as null@null
2010-10-29 22:19:25,143 TRACE [pallet.core] (Thread-1) lift* phases []
2010-10-29 22:19:25,143 INFO [pallet.core] (Thread-1) retrieving nodes
(defn ensure-database-exists
[request db-name & rest]
(-> request
(resource-when/resource-when
(= 0 @(psql "-t -c"
~(format "\"select count(1) from pg_database where datname='%s'\""
db-name)))
(apply create-database request db-name rest))))
;; Throws a stack trace complaining about too many args (5) to PersistentHashMap.
;; My two attempts. The first is to make create-database ignore the error return
;; with chain-or. I can't get anything to compile here. Have tried with/without
;; stevedore/script, with/without ~(apply...).
;; Second attempt: ensure-database-exists function. Uses a defscript. This will
;; output the if statement desired, but at a seemingly random place earlier in the
;; script unrelated to the conditional. It will also not escape as-user or db-name,
;; although it will escape the (format ...).
(defn create-database
(defn maven-artifact
"Copy a jar to a filesystem location from a maven repo. Artifacts are a sequence
consisting of group, artifact, and version. Doesn't support SNAPSHOTS right now."
[request dir-path maven-repo-url artifacts]
(let [[group artifact version] (first artifacts)]
(if (not (and group artifact version))
;; Ran out of artifacts, return the request.
request
(let [file-name (str artifact "-" version ".jar")
group-path (join "/" (split group #"\."))
;; When the wrap! is as below, the admin functions are properly wrapped, but the
;; site functions will error 500 with an NPE on session.clj:47. If I comment it and
;; uncomment the wrap! at the bottom, then the site URLs will work, but the admin
;; functions will not successfully log in, despite having the form parameters and
;; session in apparently the correct place. In fact, the post request to login is
;; identical in both cases, but it will only work if the code is as below.
;;
;; Ideally, I'd like to be able to break my routes into manageable chunks, compose
;; them, and then just wrap! once. In my reading of the source, I thought routes
;; were just functions that take a request and return a response, so shouldn't
David-Santiagos-Computer:servlet David$ cake pallet nodes -- -P virtualbox
INFO jclouds - extensions (:log4j :ssh)
David-Santiagos-Computer:servlet David$ cake pallet lift com.battletheory.deploy.nodes/server :deploy @dev -- -P virtualbox
INFO jclouds - extensions (:log4j :ssh)
INFO core - retrieving nodes
INFO core - apply-phase :pre-deploy for :server with 0 nodes
INFO core - apply-phase :deploy for :server with 0 nodes
INFO core - apply-phase :after-deploy for :server with 0 nodes