source: projects/specs/trunk/c/cdemu-daemon/cdemu-daemon.init @ 7309

Revision 7309, 3.9 KB checked in by iwaim, 11 years ago (diff)

cdemu-daemon 1.5.0-1 files

  • Property svn:executable set to *
Line 
1#!/bin/sh
2#
3# cdemu-daemon: CDEmu userspace daemon
4#
5# chkconfig:    345 98 02
6# description:  This is CDEmu userspace daemon that controls CDEmu block devices \
7#               and services device requests that are passed from kernel space
8#
9# processname:  cdemud
10# pidfile:      /var/run/cdemud.pid
11# config:       /etc/sysconfig/cdemu-daemon
12#
13
14# so we can rearrange this easily
15processname=/usr/bin/cdemud
16servicename=cdemu-daemon
17
18# Sanity checks.
19if [ ! -x $processname ]; then
20    echo "Daemon binary $processname not found!"
21    exit 1
22fi
23
24# Source function library.
25. /etc/init.d/functions
26
27# Source config
28if [ -f /etc/sysconfig/cdemu-daemon ] ; then
29    . /etc/sysconfig/cdemu-daemon
30fi
31
32RETVAL=0
33
34start() {
35    # Load module
36    if [ -n "$MODULE" ]; then
37        echo -n $"    Inserting kernel module ($MODULE): "
38        /sbin/modprobe $MODULE >/dev/null 2>&1
39        RETVAL=$?
40        if [ $RETVAL = 0 ]; then
41            success $"$base startup"
42            echo
43        else
44            failure $"$base startup"
45            echo
46            return $RETVAL
47        fi
48    fi
49   
50    # Wait until control device is created...
51    if [ -n "$CTL_DEVICE" ]; then
52        echo -n $"    Waiting for $CTL_DEVICE to be created: "
53        until [ -c "$CTL_DEVICE" ]; do
54            echo -n ""
55        done
56    fi
57   
58    RETVAL=0
59    if [ $RETVAL -eq 0 ]; then
60        success $"$base startup"
61        echo
62    else
63        failure $"$base startup"
64        echo
65        return $RETVAL
66    fi
67   
68    # Daemon arguments
69    DAEMON_ARGS="--daemonize"
70   
71    if [ -n "$DEVICES" ]; then
72        DAEMON_ARGS="$DAEMON_ARGS --num-devices=$DEVICES"
73    fi
74    if [ -n "$CTL_DEVICE" ]; then
75        DAEMON_ARGS="$DAEMON_ARGS --ctl-device=$CTL_DEVICE"
76    fi
77    if [ -n "$AUDIO_BACKEND" ]; then
78        DAEMON_ARGS="$DAEMON_ARGS --audio-driver=$AUDIO_BACKEND"
79    fi
80   
81    # Start daemon
82    echo -n $"    Starting daemon: "
83    daemon --check $servicename $processname $DAEMON_ARGS >/dev/null 2>&1
84    RETVAL=$?
85    if [ $RETVAL -eq 0 ]; then
86        success $"$base startup" 
87        touch /var/lock/subsys/$servicename
88        echo
89    else
90        failure $"$base startup"
91        echo
92        return $RETVAL
93    fi
94   
95    return $RETVAL
96}
97
98stop() {       
99    # Kill daemon with 'cdemud -k'
100    echo -n $"    Killing daemon: "
101    $processname -k >/dev/null 2>&1
102    RETVAL=$?
103    if [ $RETVAL -eq 0 ]; then
104        success $"$base shutdown"
105        echo
106    else
107        failure $"$base shutdown"
108        echo
109        return $RETVAL
110    fi
111   
112    # Unload module
113    if [ -n "$MODULE" ]; then
114        echo -n $"    Removing kernel module ($MODULE): "
115        /sbin/rmmod $MODULE >/dev/null 2>&1
116        RETVAL=$?
117        if [ $RETVAL -eq 0 ]; then
118            success $"$base shutdown"
119            echo
120        else
121            failure $"$base shutdown"
122            echo
123            return $RETVAL
124        fi
125    fi
126   
127    if [ $RETVAL -eq 0 ]; then
128        rm -f /var/lock/subsys/$servicename
129    fi
130   
131    return $RETVAL
132}
133
134# See how we were called.
135case "$1" in
136    start)
137        echo $"Starting CDEmu daemon: "
138        start
139        RETVAL=$?
140        ;;
141    stop)
142        echo $"Stopping CDEmu daemon: "
143        stop
144        RETVAL=$?
145        ;;
146    status)
147        status $processname
148        RETVAL=$?
149        ;;
150    restart)
151        echo $"Stopping CDEmu daemon: "
152        stop
153        RETVAL=$?
154        if [ $RETVAL -eq 0 ]; then
155            sleep 3
156            echo $"Starting CDEmu daemon: "
157            start
158            RETVAL=$?
159        fi
160        ;;
161    condrestart)
162        if [ -f /var/lock/subsys/$servicename ]; then
163            echo $"Stopping CDEmu daemon: "
164            stop
165            RETVAL=$?
166            if [ $RETVAL -eq 0]; then
167                sleep 3
168                echo $"Starting CDEmu daemon: "
169                start
170            fi
171        fi
172        ;;
173    *)
174        echo $"Usage: $0 {start|stop|status|restart|condrestart}"
175        ;;
176esac
177exit $RETVAL
Note: See TracBrowser for help on using the repository browser.