Skip to content

Instantly share code, notes, and snippets.

Created Jun 23, 2012
What would you like to do?
pallet redis crate
(ns pallet.crate.redis
"Simple redis crate for pallet,
with a DSL for configuration"
(:require [pallet.parameter :as parameter]
[pallet.action.package :as pkg]
[pallet.action.user :as user]
[ :as dir]
[pallet.action.remote-file :as file]
[pallet.action.service :as service]))
(def default-config
{:daemonize "yes"
:pidfile "/var/run/"
:port 6379
:bind ""
:timeout 3000
:loglevel "verbose"
:logfile "/var/log/redis/redis-server.log"
:databases 16
:dir "/var/lib/redis"
:dbfilename "dump.rdb"
:rdbcompression "yes"
:save ["900 1" "300 10" "60 10000"]
:appendfsync "everysec"
:vm-enabled "no"
:glueoutputbuf "yes"
:hash-max-zipmap-entries 64
:hash-max-zipmap-value 512
:activerehashing "yes"})
(defn- generate-line
[[directive args]]
(format "%-8s %s\n"
(name directive)
(str args)))
(defn- explode-lines
[[directive args]]
(if (sequential? args)
(for [arg args] [directive arg])
[[directive args]]))
(defn- generate-config
(->> config
(map explode-lines)
(reduce concat [])
(map generate-line)
(reduce str)))
(defn- apply-defaults
[config data-dir]
(-> default-config
(assoc :dir data-dir)
(merge config)))
(defn install-package
(-> session
(pkg/package-source "dotdeb" :aptitude
{:url ""
:scopes ["all"]
:key-url ""
:release "stable"})
(pkg/package-manager :update)
(pkg/package "redis-server")))
(defn settings
[session & {:keys [config data-dir user group]
:or {data-dir "/var/lib/redis"}}]
session :redis :main
{:config (generate-config (apply-defaults config data-dir))}))
(defn configure
(let [{:keys [config user group data-dir]}
(parameter/get-target-settings session :redis :main)]
(-> session
(user/group group :system true)
(user/user user :system true :group group)
(dir/directory data-dir :owner user :group group :mode "0755")
(file/remote-file "/etc/redis/redis.conf"
:content config
:literal true))))
(defn restart
(-> session
(service/service "redis" :action :restart)))
(defn start
(-> session
(service/service "redis" :action :start)))
(defn stop
(-> session
(service/service "redis" :action :stop)))
(pallet.core/defnode redis
:bootstrap (pallet.phase/phase-fn
:configure (pallet.phase/phase-fn
(pallet.crate.redis/configure :config {:maxmemory 1073741824}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment