mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-30 11:32:03 +00:00
81 lines
3.1 KiB
Bash
81 lines
3.1 KiB
Bash
#!/bin/sh
|
|
set -e
|
|
|
|
CLICKHOUSE_USER=clickhouse
|
|
CLICKHOUSE_GROUP=${CLICKHOUSE_USER}
|
|
CLICKHOUSE_DATADIR=/var/lib/clickhouse
|
|
CLICKHOUSE_LOGDIR=/var/log/clickhouse-server
|
|
|
|
|
|
if [ "$1" = configure ]; then
|
|
if [ -x "/bin/systemctl" ] && [ -f /etc/systemd/system/clickhouse-server.service ] && [ -d /run/systemd/system ]; then
|
|
# if old rc.d service present - remove it
|
|
if [ -x "/etc/init.d/clickhouse-server" ]; then
|
|
update-rc.d clickhouse-server remove
|
|
echo "ClickHouse init script has migrated to systemd. Please manually stop old server and restart the service: sudo killall clickhouse-server && sleep 5 && sudo service clickhouse-server restart"
|
|
fi
|
|
|
|
/bin/systemctl daemon-reload
|
|
/bin/systemctl enable clickhouse-server
|
|
else
|
|
# If you downgrading to version older than 1.1.54336 run: systemctl disable clickhouse-server
|
|
if [ -x "/etc/init.d/clickhouse-server" ]; then
|
|
update-rc.d clickhouse-server defaults 19 19 >/dev/null || exit $?
|
|
fi
|
|
fi
|
|
|
|
# Make sure the administrative user exists
|
|
if ! getent passwd ${CLICKHOUSE_USER} > /dev/null; then
|
|
adduser --system --disabled-login --no-create-home --home /nonexistent \
|
|
--shell /bin/false --group --gecos "Clickhouse server" clickhouse > /dev/null
|
|
fi
|
|
|
|
# if the user was created manually, make sure the group is there as well
|
|
if ! getent group ${CLICKHOUSE_GROUP} > /dev/null; then
|
|
addgroup --system ${CLICKHOUSE_GROUP} > /dev/null
|
|
fi
|
|
|
|
# make sure user is in the correct group
|
|
if ! id -Gn ${CLICKHOUSE_USER} | grep -qw ${CLICKHOUSE_USER}; then
|
|
adduser ${CLICKHOUSE_USER} ${CLICKHOUSE_GROUP} > /dev/null
|
|
fi
|
|
|
|
# check validity of user and group
|
|
if [ "`id -u ${CLICKHOUSE_USER}`" -eq 0 ]; then
|
|
echo "The ${CLICKHOUSE_USER} system user must not have uid 0 (root).
|
|
Please fix this and reinstall this package." >&2
|
|
exit 1
|
|
fi
|
|
|
|
if [ "`id -g ${CLICKHOUSE_GROUP}`" -eq 0 ]; then
|
|
echo "The ${CLICKHOUSE_USER} system user must not have root as primary group.
|
|
Please fix this and reinstall this package." >&2
|
|
exit 1
|
|
fi
|
|
|
|
if [ ! -d ${CLICKHOUSE_DATADIR} ]; then
|
|
mkdir -p ${CLICKHOUSE_DATADIR}
|
|
chown ${CLICKHOUSE_USER}:${CLICKHOUSE_GROUP} ${CLICKHOUSE_DATADIR}
|
|
chmod 700 ${CLICKHOUSE_DATADIR}
|
|
fi
|
|
|
|
if [ ! -d ${CLICKHOUSE_LOGDIR} ]; then
|
|
mkdir -p ${CLICKHOUSE_LOGDIR}
|
|
chown root:${CLICKHOUSE_GROUP} ${CLICKHOUSE_LOGDIR}
|
|
# Allow everyone to read logs, root and clickhouse to read-write
|
|
chmod 775 ${CLICKHOUSE_LOGDIR}
|
|
fi
|
|
|
|
|
|
if [ -d ${CLICKHOUSE_LOGDIR} ]; then
|
|
# only for compatibility for old metrika user, remove string after 2017-06-01
|
|
su -s /bin/sh ${CLICKHOUSE_USER} -c "test -w ${CLICKHOUSE_LOGDIR}" || chown -R root:${CLICKHOUSE_GROUP} ${CLICKHOUSE_LOGDIR}; chmod -R ug+rw ${CLICKHOUSE_LOGDIR}
|
|
fi
|
|
|
|
# Clean old dynamic compilation results
|
|
if [ -d "${CLICKHOUSE_DATADIR}/build" ]; then
|
|
rm -f ${CLICKHOUSE_DATADIR}/build/*.cpp ${CLICKHOUSE_DATADIR}/build/*.so ||:
|
|
fi
|
|
|
|
fi
|