]> git.pld-linux.org Git - packages/tvheadend.git/blob - tvheadend.init
e7dd72eb4a1388ba663758de7a1f69708b394e61
[packages/tvheadend.git] / tvheadend.init
1 #!/bin/sh
2 #
3 # tvheadend     tvheadend tv streaming service
4 #
5 # chkconfig:    345 40 60
6 #
7 # description:  tvheadend tv streaming service
8 #
9 # processname:  tvheadend
10 #
11
12 # Source function library
13 . /etc/rc.d/init.d/functions
14
15 # Get network config
16 . /etc/sysconfig/network
17
18 # Check that networking is up.
19 if is_yes "${NETWORKING}"; then
20         if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
21                 msg_network_down "tvheadend"
22                 exit 1
23         fi
24 else
25         exit 0
26 fi
27
28 # Set defaults
29 TVHEADEND_ARGS=""
30
31 # Get service config - may override defaults
32 [ -f /etc/sysconfig/tvheadend ] && . /etc/sysconfig/tvheadend
33
34 # configtest itself
35 # must return non-zero if check failed
36 # output is discarded if checkconfig is ran without details
37 configtest() {
38         /usr/sbin/tvheadend -t
39         return $?
40 }
41
42 # wrapper for configtest
43 checkconfig() {
44         local details=${1:-0}
45
46         if [ $details = 1 ]; then
47                 # run config test and display report (status action)
48                 show "Checking %s configuration" "tvheadend"; busy
49                 local out
50                 out=$(configtest 2>&1)
51                 RETVAL=$?
52                 if [ $RETVAL = 0 ]; then
53                         ok
54                 else
55                         fail
56                 fi
57                 [ "$out" ] && echo >&2 "$out"
58         else
59                 # run config test and abort with nice message if failed
60                 # (for actions checking status before action).
61                 configtest >/dev/null 2>&1
62                 RETVAL=$?
63                 if [ $RETVAL != 0 ]; then
64                         show "Checking %s configuration" "tvheadend"; fail
65                         nls 'Configuration test failed. See details with %s "checkconfig"' $0
66                         exit $RETVAL
67                 fi
68         fi
69 }
70
71 start() {
72         # Check if the service is already running?
73         if [ -f /var/lock/subsys/tvheadend ]; then
74                 msg_already_running "tvheadend"
75                 return
76         fi
77
78         checkconfig
79         msg_starting "tvheadend"
80         daemon --group video /usr/sbin/tvheadend $TVHEADEND_ARGS
81         RETVAL=$?
82         [ $RETVAL -eq 0 ] && touch /var/lock/subsys/tvheadend
83 }
84
85 stop() {
86         if [ ! -f /var/lock/subsys/tvheadend ]; then
87                 msg_not_running "tvheadend"
88                 return
89         fi
90
91         # Stop daemons.
92         msg_stopping "tvheadend"
93         killproc tvheadend
94         rm -f /var/lock/subsys/tvheadend
95 }
96
97 reload() {
98         if [ ! -f /var/lock/subsys/tvheadend ]; then
99                 msg_not_running "tvheadend"
100                 RETVAL=7
101                 return
102         fi
103
104         checkconfig
105         msg_reloading "tvheadend"
106         killproc tvheadend -HUP
107         RETVAL=$?
108 }
109
110 condrestart() {
111         if [ ! -f /var/lock/subsys/tvheadend ]; then
112                 msg_not_running "tvheadend"
113                 RETVAL=$1
114                 return
115         fi
116
117         checkconfig
118         stop
119         start
120 }
121
122 RETVAL=0
123 # See how we were called.
124 case "$1" in
125   start)
126         start
127         ;;
128   stop)
129         stop
130         ;;
131   restart)
132         checkconfig
133         stop
134         start
135         ;;
136   try-restart)
137         condrestart 0
138         ;;
139 # include force-reload here if program allows reloading without restart
140 # otherwise remove reload action and support force-reload as restart if running
141   reload|force-reload)
142         reload
143         ;;
144 # use this one if program doesn't support reloading without restart
145   force-reload)
146         condrestart 7
147         ;;
148   checkconfig|configtest)
149         checkconfig 1
150         ;;
151   status)
152         status tvheadend
153         RETVAL=$?
154         ;;
155   *)
156         msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|checkconfig|status}"
157         exit 3
158 esac
159
160 exit $RETVAL
This page took 0.032305 seconds and 2 git commands to generate.