|
1 #!/bin/sh |
|
2 |
|
3 #------------------------------------------------------------------------------ |
|
4 # |
|
5 # Init script for EtherCAT |
|
6 # |
|
7 # $Id$ |
|
8 # |
|
9 # Copyright (C) 2006 Florian Pose, Ingenieurgemeinschaft IgH |
|
10 # |
|
11 # This file is part of the IgH EtherCAT Master. |
|
12 # |
|
13 # The IgH EtherCAT Master is free software; you can redistribute it |
|
14 # and/or modify it under the terms of the GNU General Public License |
|
15 # as published by the Free Software Foundation; either version 2 of the |
|
16 # License, or (at your option) any later version. |
|
17 # |
|
18 # The IgH EtherCAT Master is distributed in the hope that it will be |
|
19 # useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
21 # GNU General Public License for more details. |
|
22 # |
|
23 # You should have received a copy of the GNU General Public License |
|
24 # along with the IgH EtherCAT Master; if not, write to the Free Software |
|
25 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|
26 # |
|
27 # The right to use EtherCAT Technology is granted and comes free of |
|
28 # charge under condition of compatibility of product made by |
|
29 # Licensee. People intending to distribute/sell products based on the |
|
30 # code, have to sign an agreement to guarantee that products using |
|
31 # software based on IgH EtherCAT master stay compatible with the actual |
|
32 # EtherCAT specification (which are released themselves as an open |
|
33 # standard) as the (only) precondition to have the right to use EtherCAT |
|
34 # Technology, IP and trade marks. |
|
35 # |
|
36 #------------------------------------------------------------------------------ |
|
37 |
|
38 ### BEGIN INIT INFO |
|
39 # Provides: ethercat |
|
40 # Required-Start: $local_fs $syslog $network |
|
41 # Should-Start: $time |
|
42 # Required-Stop: $local_fs $syslog $network |
|
43 # Should-Stop: $time |
|
44 # Default-Start: 3 5 |
|
45 # Default-Stop: 0 1 2 6 |
|
46 # Short-Description: IgH EtherCAT master modules |
|
47 # Description: |
|
48 ### END INIT INFO |
|
49 |
|
50 #------------------------------------------------------------------------------ |
|
51 |
|
52 ETHERCAT_CONFIG=/etc/sysconfig/ethercat |
|
53 |
|
54 test -r $ETHERCAT_CONFIG || { echo "$ETHERCAT_CONFIG not existing"; |
|
55 if [ "$1" = "stop" ]; then exit 0; |
|
56 else exit 6; fi; } |
|
57 |
|
58 . $ETHERCAT_CONFIG |
|
59 |
|
60 #------------------------------------------------------------------------------ |
|
61 |
|
62 . /etc/rc.status |
|
63 rc_reset |
|
64 |
|
65 case "$1" in |
|
66 start) |
|
67 echo -n "Starting EtherCAT master " |
|
68 |
|
69 if [ ! $DEVICE_INDEX ]; then |
|
70 echo "ERROR: DEVICE_INDEX not set!" |
|
71 /bin/false |
|
72 rc_status -v |
|
73 rc_exit |
|
74 fi |
|
75 |
|
76 if [ ! $EOE_DEVICES ]; then |
|
77 EOE_DEVICES=0 |
|
78 fi |
|
79 |
|
80 for mod in 8139too 8139cp; do |
|
81 if lsmod | grep "^$mod " > /dev/null; then |
|
82 if ! rmmod $mod; then |
|
83 /bin/false |
|
84 rc_status -v |
|
85 rc_exit |
|
86 fi |
|
87 fi |
|
88 done |
|
89 |
|
90 if ! modprobe ec_master ec_eoe_devices=$EOE_DEVICES; then |
|
91 /bin/false |
|
92 rc_status -v |
|
93 rc_exit |
|
94 fi |
|
95 |
|
96 if ! modprobe ec_8139too ec_device_index=$DEVICE_INDEX; then |
|
97 /bin/false |
|
98 rc_status -v |
|
99 rc_exit |
|
100 fi |
|
101 |
|
102 rc_status -v |
|
103 ;; |
|
104 |
|
105 stop) |
|
106 echo -n "Shutting down EtherCAT master " |
|
107 |
|
108 for mod in ec_8139too ec_master; do |
|
109 if lsmod | grep "^$mod " > /dev/null; then |
|
110 if ! rmmod $mod; then |
|
111 /bin/false |
|
112 rc_status -v |
|
113 rc_exit |
|
114 fi; |
|
115 fi; |
|
116 done |
|
117 |
|
118 if ! modprobe 8139too; then |
|
119 echo "Warning: Failed to restore 8139too module." |
|
120 fi |
|
121 |
|
122 rc_status -v |
|
123 ;; |
|
124 |
|
125 restart) |
|
126 $0 stop |
|
127 $0 start |
|
128 |
|
129 rc_status |
|
130 ;; |
|
131 |
|
132 status) |
|
133 echo -n "Checking for EtherCAT " |
|
134 |
|
135 lsmod | grep "^ec_master " > /dev/null |
|
136 master_running=$? |
|
137 lsmod | grep "^ec_8139too " > /dev/null |
|
138 device_running=$? |
|
139 test $master_running -eq 0 -a $device_running -eq 0 |
|
140 |
|
141 rc_status -v |
|
142 ;; |
|
143 esac |
|
144 rc_exit |
|
145 |
|
146 #------------------------------------------------------------------------------ |