Демон Sentinel из init.d в Linux не останавливается - PullRequest
0 голосов
/ 11 мая 2018

Я установил новый Alpine linux и настроил Redis с помощью команды

apk add redis

Теперь установщик не дал нам /etc/sentinel.conf, поэтому я создал его вручную, скопировав /etc/redis.conf.

port 26379
dir /var/lib/redis
bind 192.168.56.122
sentinel announce-ip 192.168.56.122
sentinel announce-port 26379
sentinel monitor mymaster 192.168.56.121 6379 2
sentinel auth-pass mymaster mypassword
sentinel down-after-milliseconds mymaster 5000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 10000
daemonize yes
logfile /var/log/redis/sentinel.log
pidfile /var/run/redis/sentinel.pid

Теперь, чтобы запустить sentinel в качестве демона, я создаю следующий скрипт /etc/init.d/sentinel, скопировав /etc/init.d/redis.

Если я запускаю команду

/etc/init.d/sentinel start

тогда он запускается. Но когда я пытаюсь остановить это, используя

/etc/init.d/sentinel stop

система сообщает, что служба остановлена, но если я вижу процесс, я все равно вижу, что он работает. Есть ли что-то, что я делаю не так?

#!/sbin/openrc-run

SENTINEL_CONF=${SENTINEL_CONF:-/etc/sentinel.conf}
SENTINEL_USER=${SENTINEL_USER:-root}
SENTINEL_GROUP=${SENTINEL_GROUP:-root}

name="Sentinel server"
command=/usr/bin/redis-sentinel
command_args=${SENTINEL_CONF}

depend() {
    use net localmount logger
    after keepalived firewall
}

# get global pidfile, logfile, and dir from config file
get_config() {
    if [ ! -f "${SENTINEL_CONF}" ] ; then
        eerror "You need a ${SENTINEL_CONF} file to run redis"
        return 1;
    fi

    pidfile=$(awk '$1 == "pidfile" { print $2 }' "$SENTINEL_CONF")
    logfile=$(awk '$1 == "logfile" { print $2 }' "$SENTINEL_CONF")
    dir=$(awk '$1 == "dir" { print $2 }' "$SENTINEL_CONF")
    : ${pidfile:=/var/run/redis/sentinel.pid}
    : ${logfile:=/var/log/redis/sentinel.log}
    : ${dir:=/var/lib/redis}
}

start() {
    get_config || return 1
    checkpath -d -o ${SENTINEL_USER}:${SENTINEL_GROUP} ${pidfile%/*} \
        ${logfile%/*} ${dir}

    ebegin "Starting $name"
    start-stop-daemon --start \
        --chdir "${dir}" \
        --user ${SENTINEL_USER}:${SENTINEL_GROUP} \
        --pidfile "${pidfile}" \
        --exec "${command}" \
        -- ${command_args}
    eend $? 
}

stop() {
    get_config
    ebegin "Stopping $name"
    start-stop-daemon --stop --retry 30 --pidfile "${pidfile}"
    eend $?
}

Обновление


Я также скопировал /etc/conf.d/redis и создал копию с именем /etc/conf.d/sentinel

# Redis user.
SENTINEL_USER="root"

# Redis group.
SENTINEL_GROUP="root"

# Redis configuration file.
SENTINEL_CONF="/etc/sentinel.conf"
...