#!/bin/sh -e

YASM_ROOT="/Berkanavt/yasm"
SVC="yandex-yasm-gateway"

case "$1" in
    remove|purge)
        if [ -x /bin/systemctl -a -f /etc/systemd/system/${SVC}.service ] ; then
            if ! /bin/systemctl stop ${SVC} ; then
                echo "Cannot stop ${SVC} service!"
            fi
        elif [ -x /usr/bin/service -a -f /etc/init/${SVC}.conf ] ; then
            if ! /usr/bin/service ${SVC} stop ; then
                echo "Cannot stop ${SVC} service!"
            fi
        fi

        /bin/rm -fr ${YASM_ROOT}/gateway ${YASM_ROOT}/web

        /bin/rm -f /etc/nginx/sites-enabled/yasm-front.conf
        /usr/sbin/nginx -s reload -c /etc/nginx/nginx-solomon.conf
        ;;
esac
