Last active
May 19, 2016 16:44
-
-
Save vdel26/11284281 to your computer and use it in GitHub Desktop.
Makefile for working with a remote Nginx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#### SETTINGS | |
NGINXDIR = /usr/local/openresty/nginx/ | |
NGXCONF = nginx_dummycustomer.conf | |
USER = ubuntu | |
REMOTE = ec2-54-224-138-186.compute-1.amazonaws.com | |
REMOTEDIR = /home/$(USER)/dummycustomer/ | |
PRIVATEKEY = /Users/victordg/.ssh/aws/vdg-3scale.pem | |
#### | |
ngx_files = $(shell find . -name '*.lua' -o -name '*.conf') | |
ngx_bin = $(NGINXDIR)sbin/nginx | |
ngx_conf_dir = $(NGINXDIR)conf/ | |
tmp_dir = /home/$(USER)/ngx-$(shell date +%s) | |
ifdef PRIVATEKEY | |
sshflags = -i $(PRIVATEKEY) | |
endif | |
rsyncflags = -e "ssh $(sshflags) $(PRIVATEKEY)" --checksum -rlvzu --exclude ".*" --exclude "*.tgz*" --exclude "Makefile" | |
all: | |
@echo "use any of the targets: start, stop, pull, push, sync, deploy, watch" | |
start: | |
@echo "starting Nginx" | |
ssh -i $(PRIVATEKEY) $(USER)@$(REMOTE) 'sudo $(ngx_bin) -c $(REMOTEDIR)$(NGXCONF)' | |
stop: | |
@echo "stopping Nginx" | |
ssh -i $(PRIVATEKEY) $(USER)@$(REMOTE) 'sudo $(ngx_bin) -c $(REMOTEDIR)$(NGXCONF) -s stop' | |
pull: | |
rsync --update $(rsyncflags) $(USER)@$(REMOTE):$(REMOTEDIR)/ . | |
push: | |
rsync $(rsyncflags) . $(USER)@$(REMOTE):$(REMOTEDIR)/ | |
# synchronize with remote | |
sync: pull push | |
# push changes to remote and start Nginx with the config file specified by NGXCONF | |
deploy: push | |
ssh $(sshflags) $(PRIVATEKEY) $(USER)@$(REMOTE) 'sudo $(ngx_bin) -c $(REMOTEDIR)$(NGXCONF)' | |
# like deploy but when the remote Nginx is already running | |
redeploy: push | |
ssh $(sshflags) $(PRIVATEKEY) $(USER)@$(REMOTE) 'sudo $(ngx_bin) -c $(REMOTEDIR)$(NGXCONF) -s reload' | |
# watch local directory and push changes | |
# requires watchman -- https://github.com/facebook/watchman | |
watch: | |
@echo "Watching for changes in *.conf and *.lua files" | |
watchman watch $(shell pwd) -f --persistent --server-encoding=json | |
watchman -- trigger $(shell pwd) remake '*.conf' '*.lua' -- make push | |
.PHONY: watch deploy redeploy start stop push pull sync |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment