mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-14 03:25:15 +00:00
931e307835
init.d скрипт поправлен [#CONV-4914]
199 lines
3.2 KiB
Bash
Executable File
199 lines
3.2 KiB
Bash
Executable File
#! /bin/sh
|
|
### BEGIN INIT INFO
|
|
# Provides: @DAEMON@
|
|
# Default-Start: 2
|
|
# Default-Stop: 1
|
|
# Short-Description: Yandex daemon
|
|
### END INIT INFO
|
|
|
|
USER=metrika
|
|
GROUP=metrika
|
|
SHELL=/bin/sh
|
|
PROGRAM=@DAEMON@
|
|
SYSCONFDIR=/etc/$PROGRAM
|
|
PIDDIR=/var/run/$PROGRAM
|
|
LOGDIR=/var/log/$PROGRAM
|
|
LOCALSTATEDIR=/var/lock
|
|
BINDIR=/usr/bin
|
|
CRONFILE=/etc/cron.d/@CRONFILE@
|
|
|
|
CNFFILE=$SYSCONFDIR/config.xml
|
|
CONFFILE=$SYSCONFDIR/config.conf
|
|
CONFMERGEDFILE=$SYSCONFDIR/config-merged.conf
|
|
PIDFILE=$PIDDIR/$PROGRAM.pid
|
|
LOCKFILE=$LOCALSTATEDIR/$PROGRAM
|
|
RETVAL=0
|
|
|
|
isrun()
|
|
{
|
|
[ -r "$PIDFILE" ] && pgrep -s `cat "$PIDFILE"` >/dev/null 2>&1
|
|
}
|
|
|
|
wait4done()
|
|
{
|
|
while isrun; do
|
|
sleep 1
|
|
done
|
|
}
|
|
|
|
start()
|
|
{
|
|
[ -x $BINDIR/$PROGRAM ] || exit 0
|
|
local EXIT_STATUS
|
|
EXIT_STATUS=0
|
|
|
|
echo -n "Start $PROGRAM service: "
|
|
|
|
[ -f "$LOCKFILE" ] && sleep 1
|
|
if isrun; then
|
|
echo -n "already running "
|
|
EXIT_STATUS=1
|
|
else
|
|
# Clean stale lock files
|
|
rm -f "$PIDFILE" "$LOCKFILE"
|
|
|
|
mkdir -p $LOGDIR
|
|
mkdir -p $PIDDIR
|
|
chown -R $USER:$GROUP $LOGDIR
|
|
chown -R $USER:$GROUP $PIDDIR
|
|
|
|
if [ -f "$CONFFILE" ]; then
|
|
if [ -x /usr/local/bin/conf-merge.sh ]; then
|
|
/usr/local/bin/conf-merge.sh $CONFFILE $SYSCONFDIR/conf.d $CONFMERGEDFILE
|
|
else
|
|
echo "Warning: there is no /usr/local/bin/conf-merge.sh file" >&2
|
|
cp $CONFFILE $CONFMERGEDFILE
|
|
fi
|
|
/usr/local/bin/short2old.sh $CONFMERGEDFILE > $CNFFILE
|
|
[ $? -ne 0 ] && echo FAILED && exit 1
|
|
else
|
|
echo "Warinig: there is no $CONFFILE file; using $CNFFILE file." >&2
|
|
fi
|
|
su -l $USER -s $SHELL -c "\"$BINDIR/$PROGRAM\" --daemon --pid-file=\"$PIDFILE\" --config-file=\"$CNFFILE\""
|
|
EXIT_STATUS=$?
|
|
fi
|
|
|
|
if [ $EXIT_STATUS -eq 0 ]; then
|
|
touch "$LOCKFILE"
|
|
echo "DONE"
|
|
else
|
|
echo "FAILED"
|
|
fi
|
|
|
|
return $EXIT_STATUS
|
|
}
|
|
|
|
stop()
|
|
{
|
|
local EXIT_STATUS
|
|
EXIT_STATUS=0
|
|
|
|
echo -n "Stop $PROGRAM service: "
|
|
|
|
if isrun; then
|
|
if [ -f "$LOCKFILE" ]; then
|
|
kill -TERM `cat "$PIDFILE"`
|
|
wait4done
|
|
rm -f "$LOCKFILE"
|
|
else
|
|
echo "has been stopping already"
|
|
return 1
|
|
fi
|
|
else
|
|
rm -f "$LOCKFILE"
|
|
fi
|
|
|
|
echo "DONE"
|
|
return $EXIT_STATUS
|
|
}
|
|
|
|
restart()
|
|
{
|
|
stop
|
|
start
|
|
}
|
|
|
|
forcestop()
|
|
{
|
|
local EXIT_STATUS
|
|
EXIT_STATUS=0
|
|
|
|
echo -n "Stop $PROGRAM service: "
|
|
|
|
if isrun; then
|
|
if [ -f "$LOCKFILE" ]; then
|
|
rm -f "$LOCKFILE"
|
|
kill -9 `cat "$PIDFILE"`
|
|
wait4done
|
|
else
|
|
echo "has been stopping already"
|
|
return 1
|
|
fi
|
|
fi
|
|
|
|
echo "DONE"
|
|
return $EXIT_STATUS
|
|
}
|
|
|
|
forcerestart()
|
|
{
|
|
forcestop
|
|
start
|
|
}
|
|
|
|
enable_cron()
|
|
{
|
|
sed -i 's/^#*//' "$CRONFILE"
|
|
}
|
|
|
|
disable_cron()
|
|
{
|
|
sed -i 's/^#*/#/' "$CRONFILE"
|
|
}
|
|
|
|
# See how we were called.
|
|
EXIT_STATUS=0
|
|
case "$1" in
|
|
start)
|
|
start && enable_cron
|
|
;;
|
|
stop)
|
|
disable_cron && stop
|
|
;;
|
|
status)
|
|
isrun && echo "$PROGRAM service is running" || echo "$PROGRAM service is stopped"
|
|
;;
|
|
restart)
|
|
restart && enable_cron
|
|
;;
|
|
forcestop)
|
|
disable_cron && forcestop
|
|
;;
|
|
forcerestart)
|
|
forcerestart && enable_cron
|
|
;;
|
|
reload)
|
|
restart
|
|
;;
|
|
condstart)
|
|
isrun || start
|
|
;;
|
|
condstop)
|
|
isrun && stop
|
|
;;
|
|
condrestart)
|
|
isrun && restart
|
|
;;
|
|
condreload)
|
|
isrun && restart
|
|
;;
|
|
fallenstart)
|
|
[ -r "$PIDFILE" ] && start
|
|
;;
|
|
*)
|
|
echo "Usage: ${0##*/} {start|stop|status|restart|reload|condstart|condstop|condrestart|condreload|fallenstart}"
|
|
EXIT_STATUS=2
|
|
esac
|
|
|
|
exit $EXIT_STATUS
|