MODULE = wiki-social-backoffice
PWD = $(shell pwd)
LOCAL_CONFIG = $(PWD)/../../../../cfg/services/services.local.$(USER).xml
PIDFILE = $(PWD)/$(MODULE).pid
STARTAS = $(PWD)/$(MODULE)
SOCKETFILE = /tmp/yandex-maps-$(MODULE)-$(USER).sock

$(MODULE):
	ya make

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
	@# Reason to delete existing socket file:
	@# When wiki-social-backoffice stops, its socket is left undeleted.
	@# If socket from previous run exists at this point,
	@#  while-loop waiting for it will exit before the new socket is created,
	@#  chmod will change permissions of the old socket file
	@#  and newly created socket file permissions will not be set correctrly.
	if [ -S $(SOCKETFILE) ] ; then rm -v $(SOCKETFILE); fi;
	rm -f nohup.out

start: stop
	ya make
	ulimit -c unlimited;
	YCR_MODE=fastcgi:$(SOCKETFILE) nohup /sbin/start-stop-daemon -m --pidfile $(PIDFILE) --start --startas $(STARTAS) $(LOCAL_CONFIG) &
	while ! ( test -S $(SOCKETFILE) ); do sleep 1; echo -n '.'; done ; echo
	chmod a+rw $(SOCKETFILE)

get-rating:
	curl -H "Host: social.$(USER).spica.maps.dev.yandex.net" "http://localhost/rating/day?after=0"
