PWD = $(shell pwd)
SERVICECONFIG = $(PWD)/../../cfg/services/services.local.$(USER).xml

PIDFILE=$(PWD)/wiki-tasks-ng.pid
STARTAS=$(PWD)/bin/wiki-tasks-ng

stop:
	if [ -e $(PIDFILE) ]; then \
		 if [ -f /proc/`head -1 $(PIDFILE)`/status ];then \
			/sbin/start-stop-daemon --stop --pidfile $(PIDFILE) --retry 3 ;\
			rm -f $(PIDFILE); \
		 fi; \
	fi
	rm -f nohup.out

start: stop
	ya make
	ulimit -c unlimited; YCR_MODE=fastcgi:/tmp/yandex-maps-wiki-tasks-ng-$(USER).sock nohup /sbin/start-stop-daemon -m --pidfile $(PIDFILE) --start --startas $(STARTAS) -- --config $(SERVICECONFIG)&
	while ! ( test -S /tmp/yandex-maps-wiki-tasks-ng-$(USER).sock ); do sleep 1; echo -n '.'; done ; echo
	chmod a+rw /tmp/yandex-maps-wiki-tasks-ng-$(USER).sock
