aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2013-04-26 04:34:45 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2013-04-26 04:35:14 +0200
commit9c655eeace1648695287cb47e5dfc63915e283c3 (patch)
treeda5aa51b3f2eaa0084ff56fe50f2232c1d8b69f0
parentIn fact, we do want jquery 1.9.1 for older devices. (diff)
downloadzmusic-ng-9c655eeace1648695287cb47e5dfc63915e283c3.tar.xz
zmusic-ng-9c655eeace1648695287cb47e5dfc63915e283c3.zip
Deployment is now more streamlined.
-rw-r--r--Makefile55
-rw-r--r--README.md17
-rw-r--r--backend/nginx.conf2
-rw-r--r--backend/zmusic/__init__.py9
-rw-r--r--server.cfg14
5 files changed, 63 insertions, 34 deletions
diff --git a/Makefile b/Makefile
index 8f5e318..9d43b36 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
include server.cfg
-.PHONY: all clean upload deploy update-collection
+.PHONY: all clean deploy update-collection
all:
@$(MAKE) -C frontend
@@ -9,24 +9,41 @@ clean:
@$(MAKE) -C frontend clean
@$(MAKE) -C backend clean
-upload: all
- @echo " RSYNC $(SERVER):$(SERVER_UPLOAD_PATH)"
- @rsync -aizm --delete-excluded --exclude=*.cfg --exclude=*.conf --filter="P app.cfg" --exclude=*.swp --exclude=.git* --exclude=frontend/bin/ \
- --exclude=Makefile --exclude=*.pyc --include=scripts.min.js --include=styles.min.css --exclude=*.js --exclude=*.css \
- . "$(SERVER):$(SERVER_UPLOAD_PATH)"
+SSH_OPTS := -o ControlMaster=auto -o ControlPath=.ssh-deployment.sock
-deploy: upload
- @echo " DEPLOY $(SERVER):$(SERVER_DEPLOY_PATH)"
- @ssh -t "$(SERVER)" "set -ex; \
- umask 027; \
- sudo rsync -rim --delete --filter='P zmusic.db' '$(SERVER_UPLOAD_PATH)/' '$(SERVER_DEPLOY_PATH)'; \
- sudo chown -R uwsgi:nginx '$(SERVER_DEPLOY_PATH)'; \
- sudo find '$(SERVER_DEPLOY_PATH)' -type f -exec chmod 640 {} \;; \
- sudo find '$(SERVER_DEPLOY_PATH)' -type d -exec chmod 750 {} \;; \
- sudo /etc/init.d/uwsgi.zmusic restart"
+deploy: all
+ @echo " SSH $(WEB_SERVER)"
+ @ssh $(SSH_OPTS) -Nf $(WEB_SERVER)
+
+ @echo " RSYNC frontend/ $(WEB_SERVER):$(SERVER_STATIC_PATH)"
+ @ssh -t $(SSH_OPTS) $(WEB_SERVER) "sudo -u $(SERVER_STATIC_USER) -v"
+ @rsync -aizm --delete-excluded --exclude=Makefile --exclude=*.swp --exclude=bin/ --exclude=Makefile \
+ --include=scripts.min.js --include=styles.min.css --exclude=*.js --exclude=*.css --rsh="ssh $(SSH_OPTS)" \
+ --rsync-path="sudo -n -u $(SERVER_STATIC_USER) rsync" frontend/ "$(WEB_SERVER):$(SERVER_STATIC_PATH)"
+
+ @echo " CHOWN $(SERVER_STATIC_USER):$(SERVER_APP_USER) $(WEB_SERVER):$(SERVER_STATIC_PATH)"
+ @ssh -t $(SSH_OPTS) $(WEB_SERVER) "sudo chown -v -R $(SERVER_STATIC_USER):$(SERVER_APP_USER) '$(SERVER_STATIC_PATH)'"
+
+ @echo " RSYNC backend/zmusic $(WEB_SERVER):$(SERVER_APP_PATH)"
+ @ssh -t $(SSH_OPTS) $(WEB_SERVER) "sudo -u $(SERVER_APP_USER) -v"
+ @rsync -aizm --delete-excluded --filter="P zmusic.db" --filter="P app.cfg" --exclude=*.swp --exclude=*.pyc \
+ --rsh="ssh $(SSH_OPTS)" --rsync-path="sudo -n -u $(SERVER_APP_USER) rsync" backend/zmusic/ "$(WEB_SERVER):$(SERVER_APP_PATH)"
+
+ @echo " CHOWN $(SERVER_APP_USER):$(SERVER_APP_USER) $(WEB_SERVER):$(SERVER_APP_PATH)"
+ @ssh -t $(SSH_OPTS) $(WEB_SERVER) "sudo chown -v -R $(SERVER_APP_USER):$(SERVER_APP_USER) '$(SERVER_APP_PATH)'"
+
+ @echo " CHMOD 750/640 $(WEB_SERVER):$(SERVER_APP_PATH) $(WEB_SERVER):$(SERVER_STATIC_PATH)"
+ @ssh -t $(SSH_OPTS) $(WEB_SERVER) "sudo find '$(SERVER_APP_PATH)' '$(SERVER_STATIC_PATH)' -type f -exec chmod -v 640 {} \;; \
+ sudo find '$(SERVER_APP_PATH)' '$(SERVER_STATIC_PATH)' -type d -exec chmod -v 750 {} \;;"
+
+ @echo " UWSGI restart $(WEB_SERVER)"
+ @ssh -t $(SSH_OPTS) $(WEB_SERVER) "sudo /etc/init.d/uwsgi restart"
+
+ @echo " SSH $(WEB_SERVER)"
+ @ssh -O exit $(SSH_OPTS) $(WEB_SERVER)
update-collection:
- @echo " RSYNC $(SERVER):$(SERVER_COLLECTION_PATH)"
- @rsync -avzPi --delete-excluded --delete-after --fuzzy --exclude=.directory '$(LOCAL_COLLECTION_PATH)/' '$(SERVER):$(SERVER_COLLECTION_PATH)'
- @echo " SCAN $(SERVER)"
- @curl 'http://$(SERVER)/scan?username=$(ADMIN_USERNAME)&password=$(ADMIN_PASSWORD)'
+ @echo " RSYNC $(LOCAL_COLLECTION_PATH) $(UPLOAD_SERVER):$(UPLOAD_SERVER_PATH)"
+ @rsync -avzPi --delete-excluded --delete-after --fuzzy --exclude=.directory '$(LOCAL_COLLECTION_PATH)/' '$(UPLOAD_SERVER):$(UPLOAD_SERVER_PATH)'
+ @echo " SCAN $(WEB_SERVER)"
+ @curl 'http://$(WEB_SERVER)/scan?username=$(ADMIN_USERNAME)&password=$(ADMIN_PASSWORD)'
diff --git a/README.md b/README.md
index 94b9b44..6917579 100644
--- a/README.md
+++ b/README.md
@@ -178,9 +178,10 @@ There is an additional makefile target called `update-collection` for uploading
The `server.cfg` configuration file controls the revelent paths for this command:
-* `SERVER`: The hostname of the remote server.
* `LOCAL_COLLECTION_PATH`: The path of the music folder on the local system.
-* `SERVER_COLLECTION_PATH`: The destination path of the music folder on the remote system.
+* `UPLOAD_SERVER`: The hostname of the remote upload server, probably the same as `WEB_SERVER`.
+* `UPLOAD_SERVER_PATH`: The destination path of the music folder on the remote system.
+* `WEB_SERVER`: The hostname of the web server, probably the same as `UPLOAD_SERVER`.
* `ADMIN_USERNAME` and `ADMIN_PASSWORD` should be the same as those set in `backend/app.cfg`.
### nginx / uwsgi
@@ -191,13 +192,11 @@ uwsgi should be run with the `-w zmusic:app` switch, possibly using `--chdir` to
For easy deployment, the makefile has some deployment targets, which are configured by the `server.cfg` configuration file. These keys should be set:
-* `SERVER`: The hostname of the deployed server.
-* `SERVER_UPLOAD_PATH`: A remote path where the default ssh user can write.
-* `SERVER_DEPLOY_PATH`: A remote path where the default ssh user cannot write, but where root can.
-
-The `upload` target uploads relevent portions of the project to `SERVER_UPLOAD_PATH`. The `deploy` target first executes the `upload` target, then copies files from `SERVER_UPLOAD_PATH` to `SERVER_DEPLOY_PATH` with the proper permissions, and then finally restarts the uwsgi processes.
-
- zmusig-ng $ make deploy
+* `WEB_SERVER`: The hostname of the deployed server.
+* `SERVER_STATIC_PATH`: The path of the static frontend files.
+* `SERVER_STATIC_USER`: The primary user for static file permissions.
+* `SERVER_APP_PATH`: The path of the python backend files.
+* `SERVER_STATIC_USER`: The primary user of the python backup files.
These makefile targets should be used with care, and the makefile itself should be inspected to ensure all commands are correct for custom configurations.
diff --git a/backend/nginx.conf b/backend/nginx.conf
index 611943f..6b57cce 100644
--- a/backend/nginx.conf
+++ b/backend/nginx.conf
@@ -63,7 +63,7 @@ http {
}
location /static/ {
internal;
- alias /var/www/uwsgi/zmusic/frontend/;
+ alias /var/www/htdocs/zmusic-frontend/;
}
location /music/ {
internal;
diff --git a/backend/zmusic/__init__.py b/backend/zmusic/__init__.py
index 0855b62..c63f012 100644
--- a/backend/zmusic/__init__.py
+++ b/backend/zmusic/__init__.py
@@ -8,7 +8,14 @@ import sys
import pkgutil
app = Flask(__name__)
-app.config.from_pyfile(os.path.join(os.path.dirname(os.path.abspath(__file__)), '../app.cfg'))
+
+base_dir = os.path.dirname(os.path.abspath(__file__))
+if os.path.exists(os.path.join(base_dir, 'app.cfg')):
+ app.config.from_pyfile(os.path.join(base_dir, 'app.cfg'))
+elif os.path.exists(os.path.join(base_dir, '../app.cfg')):
+ app.config.from_pyfile(os.path.join(base_dir, '../app.cfg'))
+else:
+ raise IOError("Could not find app.cfg.")
db = SQLAlchemy(app)
diff --git a/server.cfg b/server.cfg
index 8d2572d..52038ef 100644
--- a/server.cfg
+++ b/server.cfg
@@ -1,7 +1,13 @@
-SERVER = music.zx2c4.com
-SERVER_UPLOAD_PATH = zmusic-ng
-SERVER_DEPLOY_PATH = /var/www/uwsgi/zmusic
-SERVER_COLLECTION_PATH = /mnt/music
LOCAL_COLLECTION_PATH = /home/zx2c4/Music
+UPLOAD_SERVER = music.zx2c4.com
+UPLOAD_SERVER_PATH = /mnt/storage/music
+
+WEB_SERVER = music.zx2c4.com
+SERVER_STATIC_PATH = /var/www/htdocs/music.zx2c4.com
+SERVER_APP_PATH = /var/www/uwsgi/zmusic
+SERVER_MUSIC_PATH = /mnt/storage/music
+SERVER_APP_USER = zmusic
+SERVER_STATIC_USER = nginx
+
ADMIN_USERNAME = msadmin
ADMIN_PASSWORD = 2manyservers