From 4c29d0ae396d87caf292c8f4dd477d07288bfa9c Mon Sep 17 00:00:00 2001 From: Ilya Korolev Date: Mon, 8 Dec 2008 06:42:56 +0000 Subject: [PATCH] =?UTF-8?q?Metrica=20=09-=20=D0=B4=D0=B0=D0=BB=D1=8C=D0=BD?= =?UTF-8?q?=D0=B5=D0=B9=D1=88=D0=B8=D0=B5=20=D0=BF=D1=80=D0=B0=D0=B2=D0=BA?= =?UTF-8?q?=D0=B8=20=D0=B4=D0=BB=D1=8F=20=D1=81=D0=B1=D0=BE=D1=80=D0=BA?= =?UTF-8?q?=D0=B8=20deb-=D0=BF=D0=B0=D0=BA=D0=B5=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/init.d/CMakeLists.init | 13 ++++ tools/init.d/template | 132 +++++++++++++++++++++++++++++++++++ 2 files changed, 145 insertions(+) create mode 100644 tools/init.d/CMakeLists.init create mode 100755 tools/init.d/template diff --git a/tools/init.d/CMakeLists.init b/tools/init.d/CMakeLists.init new file mode 100644 index 00000000000..98c14f80cc5 --- /dev/null +++ b/tools/init.d/CMakeLists.init @@ -0,0 +1,13 @@ +# В этом файле описаны действия для добавления init.d скрипта. Пока в разработке. + +# Данный файл нужно включать в CMakeLists.txt в каталоге каждого конкретного демона. +# Пример использования: +# set(SRCS) +# INCLUDE( ${PROJECT_SOURCE_DIR}/CMakeLists.ssqls ) + +macro (CREATE_INIT_SCRIPT initname daemonname) +add_custom_command(OUTPUT ${initname} ${daemonname} + COMMAND sed -e 's,[@]DAEMON[@],${daemonname},g' < ${PROJECT_SOURCE_DIR}/tools/init.d/template > ${initname} + COMMENT "Building ${initname}" +) +endmacro (CREATE_INIT_SCRIPT) diff --git a/tools/init.d/template b/tools/init.d/template new file mode 100755 index 00000000000..dd966d60de5 --- /dev/null +++ b/tools/init.d/template @@ -0,0 +1,132 @@ +#! /bin/sh +### BEGIN INIT INFO +# Provides: @DAEMON@ +# Default-Start: 2 3 4 5 +# Default-Stop: 1 +# Short-Description: Yandex daemon +### END INIT INFO + +USER=metrica +GROUP=metrica +SHELL=/bin/sh +PROGRAM=@DAEMON@ +SYSCONFDIR=/etc/$PROGRAM +PIDDIR=/var/run/$PROGRAM +LOGDIR=/var/log/$PROGRAM +LOCALSTATEDIR=/var/lock +BINDIR=/usr/bin + +[ -x $BINDIR/$PROGRAM ] || exit 0 + +CNFFILE=$SYSCONFDIR/config.xml +PIDFILE=$PIDDIR/$PROGRAM.pid +LOCKFILE=$LOCALSTATEDIR/$PROGRAM +RETVAL=0 + +isrun() +{ + [ -r "$PIDFILE" ] && ps ax|grep `cat "$PIDFILE"`|grep -v grep >/dev/null 2>&1 && return 0 || return 1 +} + +wait4done() +{ + while isrun; do + sleep 1 + done +} + +start() +{ + local EXIT_STATUS + EXIT_STATUS=0 + + echo -n "Start $PROGRAM service: " + + 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 + + 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 + EXITS_STATUS=0 + + echo -n "Stop $PROGRAM service: " + + if isrun; then + kill -9 `cat "$PIDFILE"` + wait4done + rm -f "$LOCKFILE" + fi + + echo "DONE" + return $EXIT_STATUS +} + +restart() +{ + stop + start +} + +# See how we were called. +EXIT_STATUS=0 +case "$1" in + start) + start + ;; + stop) + stop + ;; + status) + isrun && echo "$PROGRAM service is running" || echo "$PROGRAM service is stopped" + ;; + restart) + restart + ;; + 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