+set -e
+
+if [ -e /etc/redhat-release ]; then
+ WWW_OWNER=nginx:nginx
+else
+ # Assume we're on a Debian-based system for now.
+ WWW_OWNER=www-data:www-data
+fi
+
+NGINX_SERVICE=${NGINX_SERVICE:-$(service --status-all 2>/dev/null \
+ | grep -Eo '\bnginx[^[:space:]]*' || true)}
+if [ -z "$NGINX_SERVICE" ]; then
+ cat >&2 <<EOF
+Error: nginx service not found. Aborting.
+Set NGINX_SERVICE to the name of the service hosting the Rails server.
+EOF
+ exit 1
+elif [ "$NGINX_SERVICE" != "$(echo "$NGINX_SERVICE" | head -n 1)" ]; then
+ cat >&2 <<EOF
+Error: multiple nginx services found. Aborting.
+Set NGINX_SERVICE to the name of the service hosting the Rails server.
+EOF
+ exit 1
+fi
+