summaryrefslogtreecommitdiff
path: root/community/mythtv/mythbackend.rc
blob: 488b4cb8ed33295e514970d63ba1d26ec5a60487 (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
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/bash

. /etc/rc.conf
. /etc/rc.d/functions
. /etc/profile

###############################################################################
# Default values to use if none are supplied in the config file.
#
# User who should start the mythbackend process
MBE_USER='mythtv'

# Startup options for mythbackend
MBE_OPTS=''

# Directory holding the mythbackend log file
LOG_PATH='/var/log/mythtv'

# Logging options for mythbackend
LOG_OPTS=''
###############################################################################

CONFIG_FILE=/etc/conf.d/mythbackend
PIDFILE=/var/run/mythbackend.pid

if [[ -r "$CONFIG_FILE" ]]; then
  . "$CONFIG_FILE"
fi

PID="$(cat "$PIDFILE" 2> /dev/null || pidof mythbackend)"
export HOME="$(getent passwd "$MBE_USER" | cut -d : -f 6)"

case "$1" in
  start)
    stat_busy "Starting MythTV Backend"

    if [[ "$PID" -gt 0 ]] && kill -0 "$PID"; then
      stat_fail
      exit 0
    fi

    touch "$PIDFILE"
    chown "$MBE_USER" "$PIDFILE" "$LOG_PATH"

    MBE_CMD="/usr/bin/mythbackend --daemon \
                                  --logpath "$LOG_PATH" $LOG_OPTS \
                                  --pidfile "$PIDFILE" $MBE_OPTS"
    if su "$MBE_USER" -c "$MBE_CMD"; then
      add_daemon mythbackend
      stat_done
    else
      stat_fail
    fi
    ;;
  stop)
    stat_busy "Stopping MythTV Backend"
    if [[ "$PID" -gt 0 ]] && kill "$PID" &> /dev/null; then
      rm_daemon mythbackend
      stat_done
      rm -f "$PIDFILE"
    else
      stat_fail
    fi
    ;;
  restart)
    "$0" stop
    "$0" start
    ;;
  *)
    echo "usage: $0 (start|stop|restart)"
    ;;
esac
exit 0