#!/bin/sh
# atlasd postinstall — reload the init system and restart an already-running
# control plane so an upgrade takes effect. Init-system-agnostic (systemd or
# OpenRC). A fresh install stays stopped until the operator fills in
# /etc/atlas/atlasd.env and enables the unit. Wired as apk postupgrade too (see
# .goreleaser.yaml) so an `apk upgrade` restarts as well.
set -e

mkdir -p /var/lib/atlas

if command -v systemctl >/dev/null 2>&1; then
	systemctl daemon-reload || true
	if systemctl is-enabled atlasd.service >/dev/null 2>&1; then
		systemctl try-restart atlasd.service || true
	fi
elif command -v rc-service >/dev/null 2>&1; then
	if rc-service atlasd status >/dev/null 2>&1; then
		rc-service atlasd restart || true
	fi
fi

exit 0
