Skip to content

Instantly share code, notes, and snippets.

@hhutch
Created October 25, 2011 15:21
Show Gist options
  • Save hhutch/1313105 to your computer and use it in GitHub Desktop.
Save hhutch/1313105 to your computer and use it in GitHub Desktop.
create a script with stevedore, schedule it with cron
(defn install-backup-scripts
"Creates a script in stevedore and installs it as a shell script in the administrative user's home dir
and installs it as a cron. This will override the crontab."
[request]
(let [administrative-user (:username (pallet.session/admin-user request))
admin-home-dir (str "/home/" administrative-user)
raw-instance-id (-> request :target-node (pallet.compute/id))
instance-id (apply str (interpose "_" (clojure.string/split raw-instance-id #"/")))
instance-group (-> request :target-node (compute/group-name))
s3-dir (str "/mnt/s3logstore/" instance-id "." instance-group)
script-filename "backup_logs_to_s3"
script-contents (str (pallet.script/with-template [:ubuntu]
(pallet.stevedore/script (rsync "-azvv" "/var/log" ~s3-dir))))
; # min hour dom mon dow command
cron-contents (str "* * * * * " admin-home-dir "/bin/" script-filename " > /dev/null")]
(-> request
(pallet.action.directory/directory (str admin-home-dir "/bin") :owner administrative-user :group administrative-user :mode "755")
(pallet.action.remote-file (str admin-home-dir "/bin/" script-filename)
:content script-contents :owner administrative-user :group administrative-user :mode "755")
;; Incanter Joda time would be a better naming scheme <date>-cronfile
(pallet.action.remote-file "/tmp/something-cronfile" :content cron-contents)
(exec-script/exec-script
(crontab "/tmp/something-cronfile")) )))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment