Ticket #704: gsmd.2

File gsmd.2, 2.4 KB (added by schrock.brian@…, 6 years ago)

Bugfix on the gsm init.d script.

Line 
1#!/bin/sh
2#
3# gsmd  This shell script starts and stops gsmd.
4#
5# chkconfig: 345 90 40
6# description: Gsmd manages access to a serial- or USB-connected GSM
7# processname: gsmd
8
9# If you must specify special options, uncomment and modify the next line
10GSMD_OPTS="-s 115200 -F"
11# If your GSM device needs to be powered up, uncommend and modify the next line
12GSM_POW="/sys/bus/platform/devices/gta01-pm-gsm.0/power_on"
13GSM_DEV="/dev/ttySAC0"
14GSMD_BIN="/usr/sbin/gsmd"
15
16# Source function library.
17#. /etc/rc.d/init.d/functions
18
19RETVAL=0
20prog="gsmd"
21
22start() {
23        # Power on GSM device
24        if [ -e "${GSM_POW}" ]
25        then
26                POW_STATE=`cat ${GSM_POW}`
27                if [ ${POW_STATE} -eq 1 ]
28                        then
29                                echo "GSM device already on..."
30                        else   
31                                echo -n "Powering up GSM device..."
32                                echo "1" > ${GSM_POW}
33                                echo "done"
34                fi
35        else
36                echo "GSM device not found. Aborting startup"
37                return false
38        fi
39        # Start daemons.
40        echo -n "Starting $prog: "
41        if [ -e "${GSM_DEV}" ]
42        then
43                chown uucp.uucp ${GSM_DEV}
44                mkdir -p /usr/spool/uucp
45                chown uucp.uucp /usr/spool/uucp
46                stty -F /dev/ttySAC0 crtscts
47                gsmd -p ${GSM_DEV} ${GSMD_OPTS} >/tmp/gsm.log 2>&1 &
48                $GSMD_PID=`pidof ${GSM_BIN}`
49                if [ ${GSM_PID} -gt 0 ]
50                        then
51                                echo "success"
52                        else
53                                echo "Failure"
54                                return false
55                fi
56        else
57            # User needs to symlink ${GSM_DEV} to the right thing
58            echo "No ${GSM_DEV} device, aborting gsmd startup."
59        fi
60        RETVAL=$?
61        echo
62        [ $RETVAL -eq 0 ] && cat ${GSM_PID} > /var/lock/subsys/gsmd
63        return $RETVAL
64}
65
66stop() {
67        # Stop daemons.
68        echo -n "Shutting down $prog: "
69        if [ -e /var/lock/subsys/gsmd ]
70                then
71                        GSMD_PID=`cat /var/lock/subsys/gsmd`
72                        if [ ${GSMD_PID} -gt 0 ]       
73                                then
74                                        kill ${GSMD_PID}
75                        fi     
76                else
77                        echo "No Lock file present..."
78                        $GSMD_PID=`pidof ${GSM_BIN}`
79                        kill ${GSMD_PID}
80        fi
81        RETVAL=$?
82        echo
83        if [ $RETVAL -eq 0 ]
84        then
85                if [ -e /var/lock/subsys/gsmd ]
86                        then
87                                rm -f /var/lock/subsys/gsmd
88                fi
89       
90                if [ -e "${GSM_POW}" ]
91                        then
92                                echo -n "Powering down GSM device..."
93                                echo "0" > ${GSM_POW}
94                                sleep 1
95                                echo "done"
96                fi
97        fi
98        return $RETVAL
99}
100
101# See how we were called.
102case "$1" in
103  start)
104        start
105        ;;
106  stop)
107        stop
108        ;;
109  restart|reload)
110        stop
111        start
112        RETVAL=$?
113        ;;
114  condrestart)
115        if [ -f /var/lock/subsys/gsmd ]; then
116            stop
117            start
118            RETVAL=$?
119        fi
120        ;;
121  status)
122#       status gsmd
123#       RETVAL=$?
124        ;;
125  *)
126        echo "Usage: $0 {start|stop|restart|condrestart|status}"
127        exit 1
128esac
129
130exit $RETVAL