| 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 |
|---|
| 10 | GSMD_OPTS="-s 115200 -F" |
|---|
| 11 | # If your GSM device needs to be powered up, uncommend and modify the next line |
|---|
| 12 | GSM_POW="/sys/bus/platform/devices/gta01-pm-gsm.0/power_on" |
|---|
| 13 | GSM_DEV="/dev/ttySAC0" |
|---|
| 14 | GSMD_BIN="/usr/sbin/gsmd" |
|---|
| 15 | LOCK_FILE="/var/lock/subsys/gsmd" |
|---|
| 16 | |
|---|
| 17 | # Source function library. |
|---|
| 18 | #. /etc/rc.d/init.d/functions |
|---|
| 19 | |
|---|
| 20 | RETVAL=0 |
|---|
| 21 | prog="gsmd" |
|---|
| 22 | |
|---|
| 23 | start() { |
|---|
| 24 | # Power on GSM device |
|---|
| 25 | if [ -e "${GSM_POW}" ] |
|---|
| 26 | then |
|---|
| 27 | if [ `cat ${GSM_POW}` -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 1 |
|---|
| 38 | fi |
|---|
| 39 | |
|---|
| 40 | # Start daemons. |
|---|
| 41 | |
|---|
| 42 | GSMD_PID=`pidof ${GSMD_BIN}` |
|---|
| 43 | if [ $GSMD_PID ] && [ $GSMD_PID -gt 0 ] |
|---|
| 44 | then |
|---|
| 45 | echo "Aborting $prog is already running..." |
|---|
| 46 | if [ -e ${LOCK_FILE} ] |
|---|
| 47 | then |
|---|
| 48 | TMP_GSMD_PID=`cat ${LOCK_FILE}` |
|---|
| 49 | if [ ${TMP_GSMD_PID} -eq ${GSMD_PID} ] |
|---|
| 50 | then |
|---|
| 51 | echo "Previously running gsmd was correctly started..." |
|---|
| 52 | else |
|---|
| 53 | echo "Previously running gsmd was incorrectly started, fixing..." |
|---|
| 54 | echo ${GSMD_PID} > ${LOCK_FILE} |
|---|
| 55 | fi |
|---|
| 56 | else |
|---|
| 57 | echo "Previously running gsmd was incorrectly started, fixing..." |
|---|
| 58 | echo ${GSMD_PID} > ${LOCK_FILE} |
|---|
| 59 | fi |
|---|
| 60 | return |
|---|
| 61 | else |
|---|
| 62 | if [ -e ${LOCK_FILE} ] |
|---|
| 63 | then |
|---|
| 64 | echo "Last gsmd left lock file lying around..." |
|---|
| 65 | rm -f ${LOCK_FILE} |
|---|
| 66 | fi |
|---|
| 67 | fi |
|---|
| 68 | |
|---|
| 69 | echo -n "Starting $prog: " |
|---|
| 70 | |
|---|
| 71 | if [ -e "${GSM_DEV}" ] |
|---|
| 72 | then |
|---|
| 73 | chown uucp.uucp ${GSM_DEV} |
|---|
| 74 | mkdir -p /usr/spool/uucp |
|---|
| 75 | chown uucp.uucp /usr/spool/uucp |
|---|
| 76 | stty -F /dev/ttySAC0 crtscts |
|---|
| 77 | ${GSMD_BIN} -p ${GSM_DEV} ${GSMD_OPTS} >/tmp/gsm.log 2>&1 & |
|---|
| 78 | RETVAL=$? |
|---|
| 79 | GSMD_PID=`pidof ${GSMD_BIN}` |
|---|
| 80 | if [ $GSMD_PID ] && [ ${GSMD_PID} -gt 0 ] |
|---|
| 81 | then |
|---|
| 82 | echo "Success" |
|---|
| 83 | else |
|---|
| 84 | echo "Failure" |
|---|
| 85 | return |
|---|
| 86 | fi |
|---|
| 87 | else |
|---|
| 88 | # User needs to symlink ${GSM_DEV} to the right thing |
|---|
| 89 | echo "No ${GSM_DEV} device, aborting gsmd startup." |
|---|
| 90 | echo "Failure no gsmd device..." >> /var/log/gsmd-boot |
|---|
| 91 | fi |
|---|
| 92 | [ $RETVAL -eq 0 ] && echo ${GSMD_PID} > ${LOCK_FILE} |
|---|
| 93 | return $RETVAL |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | stop() { |
|---|
| 97 | # Stop daemons. |
|---|
| 98 | echo -n "Shutting down $prog: " |
|---|
| 99 | RUNNING_GSMD_PID=`pidof ${GSMD_BIN}` |
|---|
| 100 | if [ ${RUNNING_GSMD_PID} ] && [ ${RUNNING_GSMD_PID} -gt 0 ] |
|---|
| 101 | then |
|---|
| 102 | kill ${RUNNING_GSMD_PID} |
|---|
| 103 | GSMD_PID=`pidof ${GSMD_BIN}` |
|---|
| 104 | if [ ${GSMD_PID} ] && [ ${GSMD_PID} -gt 0 ] |
|---|
| 105 | then |
|---|
| 106 | echo "Failed" |
|---|
| 107 | else |
|---|
| 108 | echo "Killed ${RUNNING_GSMD_PID}" |
|---|
| 109 | fi |
|---|
| 110 | else |
|---|
| 111 | echo "FAIL, $prog is not running..." |
|---|
| 112 | fi |
|---|
| 113 | if [ -e ${LOCK_FILE} ] |
|---|
| 114 | then |
|---|
| 115 | echo -n "Removing Lock file..." |
|---|
| 116 | rm -f ${LOCK_FILE} |
|---|
| 117 | echo "done" |
|---|
| 118 | fi |
|---|
| 119 | |
|---|
| 120 | if [ -e "${GSM_POW}" ] |
|---|
| 121 | then |
|---|
| 122 | echo -n "Powering down GSM device..." |
|---|
| 123 | echo "0" > ${GSM_POW} |
|---|
| 124 | sleep 1 |
|---|
| 125 | echo "done" |
|---|
| 126 | fi |
|---|
| 127 | return $RETVAL |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | # See how we were called. |
|---|
| 131 | case "$1" in |
|---|
| 132 | start) |
|---|
| 133 | start |
|---|
| 134 | ;; |
|---|
| 135 | stop) |
|---|
| 136 | stop |
|---|
| 137 | ;; |
|---|
| 138 | restart|reload) |
|---|
| 139 | stop |
|---|
| 140 | start |
|---|
| 141 | RETVAL=$? |
|---|
| 142 | ;; |
|---|
| 143 | condrestart) |
|---|
| 144 | if [ -f ${LOCK_FILE} ]; then |
|---|
| 145 | stop |
|---|
| 146 | start |
|---|
| 147 | RETVAL=$? |
|---|
| 148 | fi |
|---|
| 149 | ;; |
|---|
| 150 | status) |
|---|
| 151 | # status gsmd |
|---|
| 152 | # RETVAL=$? |
|---|
| 153 | ;; |
|---|
| 154 | *) |
|---|
| 155 | echo "Usage: $0 {start|stop|restart|condrestart|status}" |
|---|
| 156 | exit 1 |
|---|
| 157 | esac |
|---|
| 158 | |
|---|
| 159 | exit $RETVAL |
|---|