aboutsummaryrefslogtreecommitdiff
path: root/system/valkey/rc.valkey.new
blob: aca97e59a77da8d1853529d4196e71cca18c95d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/sh
#
# Valkey startup script for Slackware Linux

PORT=6379
SERV=/usr/bin/valkey-server
CLI=/usr/bin/valkey-cli
PIDFILE=/var/run/valkey_${PORT}.pid
CONF=/etc/valkey/valkey.conf

valkey_start() {
  if [ ! -r $CONF ]; then
    echo "$CONF does not appear to exist.  Abort."
    exit 1
  fi

  if [ -s $PIDFILE ]; then
    echo "Valkey appears to be already running?"
    exit 1
  fi

  echo "Starting Valkey server..."
  $SERV $CONF
}

valkey_stop() {
  if [ ! -s $PIDFILE ]; then
    echo "$PIDFILE does not exist or is empty."
    exit 1
  fi

  PID=$(cat $PIDFILE)
  echo -n "Stopping Valkey server..."
  $CLI -p $PORT shutdown
  while [ -d /proc/$PID ]; do
    sleep 1
    echo -n "."
  done
  echo " done"
}

valkey_restart() {
  valkey_stop
  sleep 3
  valkey_start
}

case "$1" in
  start)
    valkey_start
    ;;
  stop)
    valkey_stop
    ;;
  restart)
    valkey_restart
    ;;
  *)
    echo "Usage: $0 {start|stop|restart}"
    exit 1
esac