0

I've installed a fresh Alpine linux and setup Redis by using the command

apk add redis

Now the installer doesn't have give us a /etc/sentinel.conf so I manually created one by copying the /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

Now to run sentinel as a daemon I create the following /etc/init.d/sentinel script by copying the /etc/init.d/redis.

If I run the command

/etc/init.d/sentinel start

then it starts up. But when I try to stop it using

/etc/init.d/sentinel stop

the system reports that the service has stop but if I see the process I still see it running. Is there something that I'm doing wrong?

#!/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 $?
}

Update


I've also copied the /etc/conf.d/redis and created a copy called /etc/conf.d/sentinel

# Redis user.
SENTINEL_USER="root"

# Redis group.
SENTINEL_GROUP="root"

# Redis configuration file.
SENTINEL_CONF="/etc/sentinel.conf"
Soham Dasgupta
  • 5,061
  • 24
  • 79
  • 125
  • 1
    Hi, I'm not a mod (It should probably be a moderator saying this), but this is not the right place for this. You should ask someone to move it to superuser.stackexchange(.com) or unix.stackexchange(.com) – Aster May 12 '18 at 21:07
  • 1
    Like I didn't try. Have a look at this [question](https://unix.stackexchange.com/questions/440342/error-while-trying-to-run-docker-redis-image-on-alpine-linux-3-7-0), which got down-voted for reasons known only to Gandalf. Honestly SO and all other network sites are becoming increasingly unwelcoming, hostile and noninclusive environment. Anyway I will move this to the Unix site. – Soham Dasgupta May 13 '18 at 04:55

0 Answers0