| 9 | | (defvar *frontend-pid-file* #P"bknr-web-frontend.pid") |
|---|
| | 9 | (defvar *varnish-directory*) |
|---|
| | 10 | |
|---|
| | 11 | (defparameter *frontend-verbose* nil) |
|---|
| | 12 | (defparameter *frontend-debug* nil) |
|---|
| | 13 | |
|---|
| | 14 | (defun execute-shell (fmt &rest args) |
|---|
| | 15 | (let ((command (apply #'format nil fmt args))) |
|---|
| | 16 | (when *frontend-debug* |
|---|
| | 17 | (format t "; $ ~A~%" command)) |
|---|
| | 18 | (asdf:run-shell-command command))) |
|---|
| | 19 | |
|---|
| | 20 | (defun frontend-pid-file () |
|---|
| | 21 | (merge-pathnames #P"bknr-web-frontend.pid" *varnish-directory*)) |
|---|
| 16 | | (and (probe-file *frontend-pid-file*) |
|---|
| 17 | | (zerop (asdf:run-shell-command "sudo kill -0 ~D" (read-pid-file))))) |
|---|
| 18 | | |
|---|
| 19 | | (defun start-frontend (&key |
|---|
| 20 | | host |
|---|
| 21 | | backend-port |
|---|
| 22 | | (varnish-directory (namestring (format nil "/tmp/varnish-~A/" backend-port))) |
|---|
| 23 | | (port 80)) |
|---|
| 24 | | (when (frontend-running-p) |
|---|
| 25 | | (cerror "Tear it down!" 'frontend-already-running) |
|---|
| 26 | | (stop-frontend :verbose t) |
|---|
| 27 | | (assert (not (frontend-running-p)) nil |
|---|
| 28 | | "Failed to stop frontend. This is a bug.")) |
|---|
| 29 | | (let* ((cmd (format nil "sudo varnishd -a ~@[~A~]:~D ~ |
|---|
| 30 | | -b localhost:~D ~ |
|---|
| 31 | | -n '~A' ~ |
|---|
| 32 | | -P '~A'" |
|---|
| 33 | | host port |
|---|
| 34 | | backend-port |
|---|
| 35 | | varnish-directory |
|---|
| 36 | | *frontend-pid-file*)) |
|---|
| 37 | | (exit-code (progn (format t "; $ ~A" cmd) |
|---|
| 38 | | (asdf:run-shell-command cmd)))) |
|---|
| 39 | | (unless (zerop exit-code) |
|---|
| 40 | | (error "Attempt to launch varnishd returned error ~D." exit-code))) |
|---|
| 41 | | (values)) |
|---|
| | 29 | (and (probe-file (frontend-pid-file)) |
|---|
| | 30 | (zerop (execute-shell "sudo kill -0 ~D" (read-pid-file))))) |
|---|
| | 46 | (defun start-frontend (&key |
|---|
| | 47 | host |
|---|
| | 48 | backend-port |
|---|
| | 49 | (verbose t) |
|---|
| | 50 | (varnish-directory (pathname (format nil "/tmp/varnish-~A/" backend-port))) |
|---|
| | 51 | (port 80)) |
|---|
| | 52 | (let ((*varnish-directory* varnish-directory) |
|---|
| | 53 | (*frontend-verbose* verbose)) |
|---|
| | 54 | (when (frontend-running-p) |
|---|
| | 55 | #+(or) (cerror "Stop the running frontend process" 'frontend-already-running) |
|---|
| | 56 | (stop-frontend :verbose verbose) |
|---|
| | 57 | (assert (not (frontend-running-p)) nil |
|---|
| | 58 | "Failed to stop frontend. This is a bug.")) |
|---|
| | 59 | (when verbose |
|---|
| | 60 | (format t "; Starting varnishd frontend process on ~@[~A~]:~A~%" host port)) |
|---|
| | 61 | (let ((exit-code (execute-shell "sudo varnishd -a ~@[~A~]:~D ~ |
|---|
| | 62 | -b localhost:~D ~ |
|---|
| | 63 | -n '~A' ~ |
|---|
| | 64 | -P '~A'" |
|---|
| | 65 | host port |
|---|
| | 66 | backend-port |
|---|
| | 67 | (namestring varnish-directory) |
|---|
| | 68 | (namestring (frontend-pid-file))))) |
|---|
| | 69 | (unless (zerop exit-code) |
|---|
| | 70 | (error "Attempt to launch varnishd exit code ~D." exit-code))) |
|---|
| | 71 | (values))) |
|---|
| | 72 | |
|---|