summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dotfiles/.dmd.d/init.scm65
1 files changed, 64 insertions, 1 deletions
diff --git a/dotfiles/.dmd.d/init.scm b/dotfiles/.dmd.d/init.scm
index 45d950c..1ecb844 100644
--- a/dotfiles/.dmd.d/init.scm
+++ b/dotfiles/.dmd.d/init.scm
@@ -31,7 +31,70 @@
(define %home (getenv "HOME"))
+(define (rbenv-bin version)
+ "Return the binary path for the VERSION of Ruby managed by rbenv."
+ (string-append %home "/.rbenv/versions/" version "/bin"))
+
+(define (ruby-environment version gemset)
+ "Return the environment variables needed to run Ruby applications
+that use a specific VERSION of Ruby, whose dependencies are stored in
+GEMSET."
+ (let ((gem-home (string-append %home "/.gems/" gemset)))
+ (list (string-append "GEM_PATH=" gem-home)
+ (string-append "GEM_HOME=" gem-home)
+ (string-append "PATH=" gem-home "/bin:"
+ (rbenv-bin version) ":"
+ (getenv "PATH")))))
+
+(define* (rails-service name port ruby-version #:optional (requires '()))
+ "Create a service that runs the Rails application NAME located in
+DIR. The application runs with RUBY, the file name of the necessary
+Ruby version, and listens on PORT."
+ (define gem-home
+ (string-append %home "/.gems/" name))
+
+ (make <service>
+ #:provides (list (string->symbol name))
+ #:requires requires
+ #:start (make-forkexec-constructor
+ `("passenger" "start"
+ "--address" "127.0.0.1"
+ "--port" ,port
+ "--ruby" ,(string-append (rbenv-bin ruby-version) "/ruby"))
+ #:directory (string-append %home "/Code/" name)
+ #:environment-variables (ruby-environment ruby-version name))
+ #:stop (make-kill-destructor)))
+
(register-services
+ ;; VHL applications.
+ (rails-service "api" "3002" "1.9.3-p551")
+ (rails-service "ua" "3000" "2.1.5" '(api))
+ (rails-service "m3" "3001" "1.9.3-p551" '(api ua punjab sidekiq))
+ ;; Punjab BOSH server.
+ (let* ((punjab-home (string-append %home "/Code/vhl-bosh"))
+ (punjab-config (string-append punjab-home "/conf/development.tac")))
+ (make <service>
+ #:provides '(punjab)
+ #:requires '()
+ #:start (make-forkexec-constructor (list "twistd" "--nodaemon" "-y" punjab-config)
+ #:directory punjab-home)
+ #:stop (make-kill-destructor)))
+ ;; TODO: Openfire XMPP server.
+ ;; Redis
+ (make <service>
+ #:provides '(redis)
+ #:requires '()
+ #:start (make-forkexec-constructor '("redis-server"))
+ #:stop (make-kill-destructor))
+ ;; Sidekiq
+ (make <service>
+ #:provides '(sidekiq)
+ #:requires '(redis)
+ #:start (make-forkexec-constructor '("sidekiq")
+ #:directory (string-append %home "/Code/m3")
+ #:environment-variables
+ (ruby-environment "1.9.3-p551" "m3"))
+ #:stop (make-kill-destructor))
;; Emacs
(make <service>
#:provides '(emacs)
@@ -92,4 +155,4 @@
(action 'dmd 'daemonize)
;; Services to start when dmd starts:
-(for-each start '(emacs xmodmap gpg-agent offlineimap sshfs mpd))
+(for-each start '(xmodmap gpg-agent offlineimap))