Skip to content

Instantly share code, notes, and snippets.

@gebv
Last active January 19, 2016 14:50
Show Gist options
  • Save gebv/e8a243925bf6382c89f6 to your computer and use it in GitHub Desktop.
Save gebv/e8a243925bf6382c89f6 to your computer and use it in GitHub Desktop.
Makefile запуск и остановка приложения по PID
.PHONY: deploy setup start stop
LASTBUILD := `cd ../builds && ls -1t | head -1`
STAMP := `date +%s`
BUILD := `date -u '+%Y_%m_%d-%I_%M_%S'`
PIDFILE := ./bin/app.pid
ifneq ("$(wildcard $(PIDFILE))","")
PID=$(shell cat $(PIDFILE))
endif
default: deploy
start:
ifndef PID
@echo Starting...
@$(shell nohup ./bin/app.bin -config=config.json -stderrthreshold=INFO -v=2 > ../logs/current.log 2>&1 & echo $$! > $(PIDFILE))
@echo PID=$(shell cat $(PIDFILE))
else
@echo PID='$(PID)'
endif
stop:
ifdef PID
@echo PID=$(PID) Stopping...
@rm $(PIDFILE)
@echo "================END================" >> ../logs/current.log
@echo $(BUILD) >> ../logs/current.log
@cp ../logs/current.log ../logs/$(BUILD).log
@echo > ../logs/current.log
else
@echo It is stopped
endif
deploy:
unzip ../builds/$(LASTBUILD) -d ../.tmp/$(STAMP)
rsync --progress --partial --force -avz --exclude '.pid' --exclude 'downloads' --exclude 'config' ../.tmp/$(STAMP)/ ../current
setup:
mkdir -p ../.tmp
mkdir -p ../logs
mkdir -p ../builds
mkdir -p ../shared
mkdir -p ../current/bin
mkdir -p ../shared/config
mkdir -p ../shared/downloads
ln -s ../shared/config/ config
ln -s ../shared/downloads/ downloads
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment