2016-02-07 20:02:44 +00:00
|
|
|
#!/bin/sh
|
|
|
|
set -e
|
|
|
|
|
2017-01-31 19:53:05 +00:00
|
|
|
CLICKHOUSE_USER=clickhouse
|
|
|
|
CLICKHOUSE_GROUP=${CLICKHOUSE_USER}
|
|
|
|
CLICKHOUSE_DATADIR=/var/lib/clickhouse
|
|
|
|
CLICKHOUSE_DATADIR_OLD=/opt/clickhouse # remove after 2017-06-01
|
2017-01-31 21:36:13 +00:00
|
|
|
CLICKHOUSE_LOGDIR=/var/log/clickhouse-server
|
2017-01-31 19:53:05 +00:00
|
|
|
CLICKHOUSE_SERVER_ETCDIR=/etc/clickhouse-server
|
|
|
|
|
|
|
|
|
2017-01-09 13:42:29 +00:00
|
|
|
if [ "$1" = configure ]; then
|
|
|
|
|
|
|
|
if [ -x "/etc/init.d/clickhouse-server" ]; then
|
|
|
|
update-rc.d clickhouse-server defaults 19 19 >/dev/null || exit $?
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Make sure the administrative user exists
|
2017-01-31 19:53:05 +00:00
|
|
|
if ! getent passwd ${CLICKHOUSE_USER} > /dev/null; then
|
2017-01-09 13:42:29 +00:00
|
|
|
adduser --system --disabled-login --no-create-home --home /nonexistent \
|
2017-01-31 19:53:05 +00:00
|
|
|
--shell /bin/false --group --gecos "Clickhouse server" clickhouse > /dev/null
|
2017-01-09 13:42:29 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# if the user was created manually, make sure the group is there as well
|
2017-01-31 19:53:05 +00:00
|
|
|
if ! getent group ${CLICKHOUSE_GROUP} > /dev/null; then
|
|
|
|
addgroup --system ${CLICKHOUSE_GROUP} > /dev/null
|
2017-01-09 13:42:29 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# make sure user is in the correct group
|
2017-01-31 19:53:05 +00:00
|
|
|
if ! id -Gn ${CLICKHOUSE_USER} | grep -qw ${CLICKHOUSE_USER}; then
|
|
|
|
adduser ${CLICKHOUSE_USER} ${CLICKHOUSE_GROUP} > /dev/null
|
2017-01-09 13:42:29 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# check validity of user and group
|
2017-01-31 19:53:05 +00:00
|
|
|
if [ "`id -u ${CLICKHOUSE_USER}`" -eq 0 ]; then
|
|
|
|
echo "The ${CLICKHOUSE_USER} system user must not have uid 0 (root).
|
2017-01-09 13:42:29 +00:00
|
|
|
Please fix this and reinstall this package." >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-01-31 19:53:05 +00:00
|
|
|
if [ "`id -g ${CLICKHOUSE_GROUP}`" -eq 0 ]; then
|
|
|
|
echo "The ${CLICKHOUSE_USER} system user must not have root as primary group.
|
2017-01-09 13:42:29 +00:00
|
|
|
Please fix this and reinstall this package." >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2016-02-07 20:02:44 +00:00
|
|
|
|
2017-01-31 19:53:05 +00:00
|
|
|
if [ ! -d ${CLICKHOUSE_DATADIR} ]; then
|
|
|
|
# only for compatibility for old /opt/clickhouse, remove after 2017-06-01
|
|
|
|
if [ -d ${CLICKHOUSE_DATADIR_OLD} ]; then
|
|
|
|
ln -s ${CLICKHOUSE_DATADIR_OLD} ${CLICKHOUSE_DATADIR}
|
|
|
|
else
|
|
|
|
# DONT remove after 2017-06-01 :
|
|
|
|
mkdir -p ${CLICKHOUSE_DATADIR}
|
2017-02-13 19:19:21 +00:00
|
|
|
chown ${CLICKHOUSE_USER}:${CLICKHOUSE_GROUP} ${CLICKHOUSE_DATADIR}
|
|
|
|
chmod 700 ${CLICKHOUSE_DATADIR}
|
2017-01-31 19:53:05 +00:00
|
|
|
fi
|
2017-01-09 13:42:29 +00:00
|
|
|
fi
|
2016-02-07 20:02:44 +00:00
|
|
|
|
2017-01-31 19:53:05 +00:00
|
|
|
if [ ! -d ${CLICKHOUSE_LOGDIR} ]; then
|
|
|
|
mkdir -p ${CLICKHOUSE_LOGDIR}
|
|
|
|
chown root:${CLICKHOUSE_GROUP} ${CLICKHOUSE_LOGDIR}
|
2017-02-13 19:46:59 +00:00
|
|
|
# Allow everyone to read logs, root and clickhouse to read-write
|
2017-02-13 19:19:21 +00:00
|
|
|
chmod 775 ${CLICKHOUSE_LOGDIR}
|
2016-02-07 20:02:44 +00:00
|
|
|
fi
|
2017-01-09 13:42:29 +00:00
|
|
|
|
2017-01-31 22:43:32 +00:00
|
|
|
|
2017-02-16 17:57:46 +00:00
|
|
|
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
|
|
|
|
|
2017-01-31 22:43:32 +00:00
|
|
|
|
2017-02-16 17:57:46 +00:00
|
|
|
if [ -d ${CLICKHOUSE_SERVER_ETCDIR} ]; then
|
|
|
|
# -R only for compatibility for old metrika user, remove -R after 2017-06-01
|
|
|
|
su -s /bin/sh ${CLICKHOUSE_USER} -c "test -w ${CLICKHOUSE_SERVER_ETCDIR}" || chown -R ${CLICKHOUSE_USER}:${CLICKHOUSE_GROUP} ${CLICKHOUSE_SERVER_ETCDIR}
|
|
|
|
fi
|
2017-01-31 22:43:32 +00:00
|
|
|
|
2016-02-07 20:02:44 +00:00
|
|
|
|
2017-01-31 19:53:05 +00:00
|
|
|
# Clean old dynamic compilation results
|
|
|
|
if [ -d "${CLICKHOUSE_DATADIR}/build" ]; then
|
|
|
|
rm -f ${CLICKHOUSE_DATADIR}/build/*.cpp ${CLICKHOUSE_DATADIR}/build/*.so ||:
|
|
|
|
fi
|
2017-01-09 13:42:29 +00:00
|
|
|
|
2017-01-31 19:53:05 +00:00
|
|
|
fi
|