#/bin/bash
#
#
case "$1" in
    start)
        echo -n "Starting Gitlab ... "

        sudo systemctl start postgresql
        sudo systemctl start redis@redis
        sudo systemctl start gitlab-runner
        sudo systemctl start gitlab

        sudo systemctl start nginx

        echo "Done"

        ;;
    stop)
        echo -n "Shutting down Gitlab ... "

        sudo systemctl stop nginx

        sudo systemctl stop gitlab
        sudo systemctl stop gitlab-runner
        sudo systemctl stop redis@redis
        sudo systemctl stop postgresql

        echo "Done"

        ;;
    restart)
        ## Stop the service and regardless of whether it was
        ## running or not, start it again.
        $0 stop
        $0 start

        # Remember status and be quiet
        rc_status
        ;;
    status)
        systemctl status postgresql
        systemctl status redis@redis
        systemctl status gitlab-runner
        systemctl status gitlab

        systemctl status nginx

        ;;
    enable)
        systemctl enable postgresql
        systemctl enable redis@redis
        systemctl enable gitlab-runner
        systemctl enable gitlab

        systemctl enable nginx

        ;;
    disable)
        systemctl disable postgresql
        systemctl disable redis@redis
        systemctl disable gitlab-runner
        systemctl disable gitlab

        systemctl disable nginx

        ;;
    backup)
        pushd /srv/www/vhosts/gitlab-ce> /dev/null 2>&1
        sudo rake.RUBY_SUFFIX gitlab:backup:create RAILS_ENV=production
        popd> /dev/null 2>&1
        ;;
    *)
        echo "Usage: $0 {start|stop|restart|enable|disable|backup}"
        exit 1
        ;;
esac
exit 0
