|
1 #!/bin/sh |
|
2 |
|
3 #------------------------------------------------------------------------------ |
|
4 # |
|
5 # MSR Init Script |
|
6 # |
|
7 # $Id$ |
|
8 # |
|
9 #------------------------------------------------------------------------------ |
|
10 |
|
11 ### BEGIN INIT INFO |
|
12 # Provides: msr |
|
13 # Required-Start: $local_fs $syslog $network |
|
14 # Should-Start: $time ntp ethercat |
|
15 # Required-Stop: $local_fs $syslog $network |
|
16 # Should-Stop: $time ntp ethercat |
|
17 # Default-Start: 3 5 |
|
18 # Default-Stop: 0 1 2 6 |
|
19 # Short-Description: MSR module |
|
20 # Description: |
|
21 ### END INIT INFO |
|
22 |
|
23 #------------------------------------------------------------------------------ |
|
24 |
|
25 # <Customizing> |
|
26 |
|
27 NAME="MSR EtherCAT sample" |
|
28 BASE=/opt/etherlab |
|
29 MSR_SERVER=$BASE/bin/msrserv.pl |
|
30 MODULE=ec_msr_sample |
|
31 RTAI_PATH=/usr/realtime |
|
32 RTAI_MODULES="hal up" # sem math |
|
33 DEVICE=msr |
|
34 DEVMASK=664 |
|
35 GROUP=users |
|
36 |
|
37 # </Customizing> |
|
38 |
|
39 #------------------------------------------------------------------------------ |
|
40 |
|
41 . /etc/rc.status |
|
42 rc_reset |
|
43 |
|
44 #------------------------------------------------------------------------------ |
|
45 |
|
46 case "$1" in |
|
47 start) |
|
48 echo -n Starting $NAME" " |
|
49 |
|
50 # Insert RTAI modules |
|
51 for mod in $RTAI_MODULES; do |
|
52 if ! lsmod | grep -q "^rtai_$mod"; then |
|
53 if ! insmod $RTAI_PATH/modules/rtai_$mod.ko; then |
|
54 /bin/false |
|
55 rc_status -v |
|
56 rc_exit |
|
57 fi |
|
58 fi |
|
59 done |
|
60 |
|
61 # Insert realtime module |
|
62 if ! modprobe $MODULE; then |
|
63 /bin/false |
|
64 rc_status -v |
|
65 rc_exit |
|
66 fi |
|
67 |
|
68 #sleep 2 |
|
69 |
|
70 # Create MSR device |
|
71 MAJOR=`cat /proc/devices | awk "\\$2==\"$DEVICE\" {print \\$1}"` |
|
72 rm -f /dev/${DEVICE} |
|
73 mknod /dev/${DEVICE} c $MAJOR 0 |
|
74 chgrp $GROUP /dev/${DEVICE} |
|
75 chmod $DEVMASK /dev/${DEVICE} |
|
76 |
|
77 #sleep 1 |
|
78 |
|
79 # Start MSR-Server |
|
80 startproc $MSR_SERVER 1>/dev/null 2>/dev/null |
|
81 rc_status -v |
|
82 ;; |
|
83 |
|
84 stop) |
|
85 echo -n Shutting down $NAME" " |
|
86 |
|
87 if ! killproc $MSR_SERVER; then |
|
88 /bin/false |
|
89 rc_status -v |
|
90 rc_exit |
|
91 fi |
|
92 |
|
93 if ! /sbin/rmmod $MODULE; then |
|
94 /bin/false |
|
95 rc_status -v |
|
96 rc_exit |
|
97 fi |
|
98 |
|
99 # Remove stale nodes |
|
100 rm -f /dev/${DEVICE} /dev/${DEVICE}0 |
|
101 |
|
102 rc_status -v |
|
103 ;; |
|
104 |
|
105 restart) |
|
106 $0 stop || exit 1 |
|
107 sleep 1 |
|
108 $0 start |
|
109 |
|
110 rc_status |
|
111 ;; |
|
112 |
|
113 status) |
|
114 echo -n "Checking for MSR module: " |
|
115 /sbin/lsmod | grep -q "^$MODULE" |
|
116 rc_status -v |
|
117 |
|
118 echo -n "Checking for MSR server: " |
|
119 checkproc $MSR_SERVER |
|
120 rc_status -v |
|
121 ;; |
|
122 |
|
123 *) |
|
124 echo "Usage: $0 {start|stop|status|restart}" |
|
125 exit 1 |
|
126 ;; |
|
127 esac |
|
128 |
|
129 rc_exit |