Files
datastore/packages/datastore-server.init
zooqueen 2c6671844d datastore: rename hanzo-datastore → datastore (one canonical name)
The white-label name is just `datastore`, not `hanzo-datastore` — one name, DRY.

- binary / packages / paths / user / config: hanzo-datastore → datastore
  (binary `datastore`, packages `datastore-{client,server,common-static,keeper}`,
  `/var/lib/datastore`, `/etc/datastore-server`, `/var/log/datastore-server`, user `datastore`)
- env vars: HANZO_* → DATASTORE_* across the white-label scripts (entrypoint, init,
  service, postinstall, docs) and compose — the docker image env is now consistently
  `DATASTORE_*` and compose matches what the entrypoint reads.
- renamed 13 spec/config files: `packages/hanzo-datastore-*` → `packages/datastore-*`,
  `docker/server/hanzo-paths.xml` → `docker/server/datastore-paths.xml`.

Left intentionally: GitHub Actions secrets `ROBOT_HANZO_{SSH_KEY,COMMIT_TOKEN}` (renaming
needs rotating org secrets). The C++ source still reads `CLICKHOUSE_*` env and expects a
`<clickhouse>` config root — that's the deeper clickhouse→datastore source debrand, tracked
separately. The Hanzo brand stays in human prose (maintainer, homepage `hanzo.ai`, image
org `hanzoai/datastore`).
2026-06-21 19:06:04 -07:00

210 lines
4.5 KiB
Bash

#!/bin/sh
### BEGIN INIT INFO
# Provides: datastore-server
# Required-Start: $network
# Required-Stop: $network
# Should-Start: $time
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: datastore-server daemon
### END INIT INFO
DATASTORE_USER=datastore
DATASTORE_GROUP=${DATASTORE_USER}
SHELL=/bin/bash
PROGRAM=datastore-server
DATASTORE_GENERIC_PROGRAM=datastore
DATASTORE_PROGRAM_ENV=""
EXTRACT_FROM_CONFIG=${DATASTORE_GENERIC_PROGRAM}-extract-from-config
DATASTORE_CONFDIR=/etc/datastore-server
DATASTORE_LOGDIR=/var/log/datastore-server
DATASTORE_LOGDIR_USER=root
DATASTORE_DATADIR=/var/lib/datastore
if [ -d "/var/lock" ]; then
LOCALSTATEDIR=/var/lock
else
LOCALSTATEDIR=/run/lock
fi
if [ ! -d "$LOCALSTATEDIR" ]; then
mkdir -p "$LOCALSTATEDIR"
fi
DATASTORE_BINDIR=/usr/bin
DATASTORE_CRONFILE=/etc/cron.d/datastore-server
DATASTORE_CONFIG=$DATASTORE_CONFDIR/config.xml
LOCKFILE=$LOCALSTATEDIR/$PROGRAM
DATASTORE_PIDDIR=/var/run/$PROGRAM
DATASTORE_PIDFILE="$DATASTORE_PIDDIR/$PROGRAM.pid"
command -v flock >/dev/null && FLOCK=flock
set -a
test -f /etc/default/datastore-server && . /etc/default/datastore-server
set +a
die()
{
echo $1 >&2
exit 1
}
check_config()
{
if [ -x "$DATASTORE_BINDIR/$EXTRACT_FROM_CONFIG" ]; then
su -s $SHELL ${DATASTORE_USER} -c "$DATASTORE_BINDIR/$EXTRACT_FROM_CONFIG --config-file=\"$DATASTORE_CONFIG\" --key=path" >/dev/null || die "Configuration file ${DATASTORE_CONFIG} doesn't parse successfully. Won't restart server. You may use forcerestart if you are sure.";
fi
}
initdb()
{
${DATASTORE_GENERIC_PROGRAM} install --user "${DATASTORE_USER}" --pid-path "${DATASTORE_PIDDIR}" --config-path "${DATASTORE_CONFDIR}" --binary-path "${DATASTORE_BINDIR}"
}
start()
{
${DATASTORE_GENERIC_PROGRAM} start --user "${DATASTORE_USER}" --pid-path "${DATASTORE_PIDDIR}" --config-path "${DATASTORE_CONFDIR}" --binary-path "${DATASTORE_BINDIR}"
}
stop()
{
${DATASTORE_GENERIC_PROGRAM} stop --pid-path "${DATASTORE_PIDDIR}"
}
restart()
{
${DATASTORE_GENERIC_PROGRAM} restart --user "${DATASTORE_USER}" --pid-path "${DATASTORE_PIDDIR}" --config-path "${DATASTORE_CONFDIR}" --binary-path "${DATASTORE_BINDIR}"
}
forcestop()
{
${DATASTORE_GENERIC_PROGRAM} stop --force --pid-path "${DATASTORE_PIDDIR}"
}
service_or_func()
{
if [ -n "${SYSTEMCTL_SKIP_REDIRECT+x}" ]; then
$1
return
fi
if [ -x "/bin/systemctl" ] && [ -d /run/systemd/system ]; then
if [ -f /etc/systemd/system/datastore-server.service ] || [ -f /lib/systemd/system/datastore-server.service ]; then
systemctl $1 $PROGRAM
return
fi
fi
$1
}
forcerestart()
{
forcestop
service_or_func start
}
use_cron()
{
if [ -x "/bin/systemctl" ] && [ -f /etc/systemd/system/datastore-server.service ] && [ -d /run/systemd/system ]; then
return 1
fi
if [ ! -f "$DATASTORE_CRONFILE" ]; then
return 1
fi
if [ -z "$DATASTORE_CRONFILE" ]; then
return 2
fi
return 0
}
enable_cron()
{
use_cron && sed -i 's/^#*//' "$DATASTORE_CRONFILE"
}
disable_cron()
{
use_cron && sed -i 's/^#*/#/' "$DATASTORE_CRONFILE"
}
is_cron_disabled()
{
use_cron || return 0
grep -q -E '^#' "$DATASTORE_CRONFILE";
}
main()
{
EXIT_STATUS=0
case "$1" in
start)
service_or_func start && enable_cron
;;
stop)
disable_cron
service_or_func stop
;;
restart)
service_or_func restart && enable_cron
;;
forcestop)
disable_cron
forcestop
;;
forcerestart)
forcerestart && enable_cron
;;
reload)
service_or_func restart
;;
condstart)
service_or_func start
;;
condstop)
service_or_func stop
;;
condrestart)
service_or_func restart
;;
condreload)
service_or_func restart
;;
initdb)
initdb
;;
enable_cron)
enable_cron
;;
disable_cron)
disable_cron
;;
*)
echo "Usage: $0 {start|stop|status|restart|forcestop|forcerestart|reload|condstart|condstop|condrestart|condreload|initdb}"
exit 2
;;
esac
exit $EXIT_STATUS
}
status()
{
${DATASTORE_GENERIC_PROGRAM} status --pid-path "${DATASTORE_PIDDIR}"
}
case "$1" in
status)
status
exit 0
;;
esac
(
if $FLOCK -n 9; then
main "$@"
else
echo "Init script is already running" && exit 1
fi
) 9> $LOCKFILE