23 # along with the IgH EtherCAT Master; if not, write to the Free Software |
23 # along with the IgH EtherCAT Master; if not, write to the Free Software |
24 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
24 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
25 # |
25 # |
26 #------------------------------------------------------------------------------ |
26 #------------------------------------------------------------------------------ |
27 |
27 |
28 CONFIGFILE=/etc/sysconfig/ethercat |
28 ### BEGIN INIT INFO |
|
29 # Provides: EtherCAT |
|
30 # Required-Start: |
|
31 # Should-Start: |
|
32 # Required-Stop: |
|
33 # Should-Stop: |
|
34 # Default-Start: 3 5 |
|
35 # Default-Stop: 0 1 2 6 |
|
36 # Short-Description: EtherCAT master driver and network device |
|
37 # Description: |
|
38 ### END INIT INFO |
29 |
39 |
30 #------------------------------------------------------------------------------ |
40 #------------------------------------------------------------------------------ |
31 |
41 |
32 print_usage() |
42 ETHERCAT_CONFIG=/etc/sysconfig/ethercat |
33 { |
|
34 echo "Usage: $0 { start | stop | restart }" |
|
35 } |
|
36 |
43 |
37 unload_module() |
44 test -r $ETHERCAT_CONFIG || { echo "$ETHERCAT_CONFIG not existing"; |
38 { |
45 if [ "$1" = "stop" ]; then exit 0; |
39 if lsmod | grep ^$1 > /dev/null; then |
46 else exit 6; fi; } |
40 echo " unloading module \"$1\"..." |
47 |
41 rmmod $1 || exit 1 |
48 . $ETHERCAT_CONFIG |
42 fi |
|
43 } |
|
44 |
49 |
45 #------------------------------------------------------------------------------ |
50 #------------------------------------------------------------------------------ |
46 |
51 |
47 # Get parameters |
52 # Shell functions sourced from /etc/rc.status: |
48 if [ $# -eq 0 ]; then |
53 # rc_check check and set local and overall rc status |
49 print_usage |
54 # rc_status check and set local and overall rc status |
50 exit 1 |
55 # rc_status -v be verbose in local rc status and clear it afterwards |
51 fi |
56 # rc_status -v -r ditto and clear both the local and overall rc status |
|
57 # rc_status -s display "skipped" and exit with status 3 |
|
58 # rc_status -u display "unused" and exit with status 3 |
|
59 # rc_failed set local and overall rc status to failed |
|
60 # rc_failed <num> set local and overall rc status to <num> |
|
61 # rc_reset clear both the local and overall rc status |
|
62 # rc_exit exit appropriate to overall rc status |
|
63 # rc_active checks whether a service is activated by symlinks |
|
64 . /etc/rc.status |
52 |
65 |
53 ACTION=$1 |
66 # Reset status of this service |
|
67 rc_reset |
54 |
68 |
55 # Load configuration from sysconfig |
69 # Return values acc. to LSB for all commands but status: |
|
70 # 0 - success |
|
71 # 1 - generic or unspecified error |
|
72 # 2 - invalid or excess argument(s) |
|
73 # 3 - unimplemented feature (e.g. "reload") |
|
74 # 4 - user had insufficient privileges |
|
75 # 5 - program is not installed |
|
76 # 6 - program is not configured |
|
77 # 7 - program is not running |
|
78 # 8--199 - reserved (8--99 LSB, 100--149 distrib, 150--199 appl) |
|
79 # |
|
80 # Note that starting an already running service, stopping |
|
81 # or restarting a not-running service as well as the restart |
|
82 # with force-reload (in case signaling is not supported) are |
|
83 # considered a success. |
56 |
84 |
57 if [ -f $CONFIGFILE ]; then |
85 case "$1" in |
58 . $CONFIGFILE |
86 start) |
59 else |
87 echo -n "Starting EtherCAT master... " |
60 echo "ERROR: Configuration file \"$CONFIGFILE\" not found!" |
|
61 exit 1 |
|
62 fi |
|
63 |
88 |
64 case $ACTION in |
89 # remove incompatible modules |
65 start | restart) |
90 for mod in 8139too 8139cp; do |
66 echo "Starting EtherCAT master..." |
91 if lsmod | grep "^$mod " > /dev/null; then |
|
92 if ! rmmod $mod; then |
|
93 /bin/false |
|
94 rc_status -v |
|
95 rc_exit |
|
96 fi; |
|
97 fi; |
|
98 done |
67 |
99 |
68 # remove modules |
100 modprobe ec_8139too ec_device_index=$DEVICEINDEX |
69 unload_module 8139too |
|
70 unload_module 8139cp |
|
71 unload_module ec_8139too |
|
72 unload_module ec_master |
|
73 |
101 |
74 echo " loading master modules..." |
102 rc_status -v |
75 if ! modprobe ec_8139too ec_device_index=$DEVICEINDEX; then |
|
76 echo "ERROR: Failed to load module!" |
|
77 exit 1 |
|
78 fi |
|
79 ;; |
103 ;; |
80 |
104 |
81 stop) |
105 stop) |
82 echo "Stopping EtherCAT master..." |
106 echo -n "Shutting down EtherCAT master... " |
83 unload_module ec_8139too |
107 |
84 unload_module ec_master |
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 |
85 if ! modprobe 8139too; then |
118 if ! modprobe 8139too; then |
86 echo "Warning: Failed to restore 8139too module." |
119 echo "Warning: Failed to restore 8139too module." |
87 fi |
120 fi |
|
121 |
|
122 rc_status -v |
88 ;; |
123 ;; |
89 |
124 |
90 *) |
125 restart) |
91 print_usage |
126 $0 stop |
92 exit 1 |
127 $0 start |
|
128 |
|
129 rc_status |
|
130 ;; |
93 esac |
131 esac |
94 |
132 rc_exit |
95 echo "done." |
|
96 exit 0 |
|
97 |
133 |
98 #------------------------------------------------------------------------------ |
134 #------------------------------------------------------------------------------ |