Skip to content
Snippets Groups Projects
Commit abb0ea64 authored by Florian Pose's avatar Florian Pose
Browse files

Better RC script.

parent 8eae53c5
No related branches found
Tags 1.0.15
No related merge requests found
...@@ -25,74 +25,110 @@ ...@@ -25,74 +25,110 @@
# #
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
CONFIGFILE=/etc/sysconfig/ethercat ### BEGIN INIT INFO
# Provides: EtherCAT
# Required-Start:
# Should-Start:
# Required-Stop:
# Should-Stop:
# Default-Start: 3 5
# Default-Stop: 0 1 2 6
# Short-Description: EtherCAT master driver and network device
# Description:
### END INIT INFO
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
print_usage() ETHERCAT_CONFIG=/etc/sysconfig/ethercat
{
echo "Usage: $0 { start | stop | restart }"
}
unload_module() test -r $ETHERCAT_CONFIG || { echo "$ETHERCAT_CONFIG not existing";
{ if [ "$1" = "stop" ]; then exit 0;
if lsmod | grep ^$1 > /dev/null; then else exit 6; fi; }
echo " unloading module \"$1\"..."
rmmod $1 || exit 1 . $ETHERCAT_CONFIG
fi
}
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Get parameters # Shell functions sourced from /etc/rc.status:
if [ $# -eq 0 ]; then # rc_check check and set local and overall rc status
print_usage # rc_status check and set local and overall rc status
exit 1 # rc_status -v be verbose in local rc status and clear it afterwards
fi # rc_status -v -r ditto and clear both the local and overall rc status
# rc_status -s display "skipped" and exit with status 3
ACTION=$1 # rc_status -u display "unused" and exit with status 3
# rc_failed set local and overall rc status to failed
# Load configuration from sysconfig # rc_failed <num> set local and overall rc status to <num>
# rc_reset clear both the local and overall rc status
if [ -f $CONFIGFILE ]; then # rc_exit exit appropriate to overall rc status
. $CONFIGFILE # rc_active checks whether a service is activated by symlinks
else . /etc/rc.status
echo "ERROR: Configuration file \"$CONFIGFILE\" not found!"
exit 1 # Reset status of this service
fi rc_reset
case $ACTION in # Return values acc. to LSB for all commands but status:
start | restart) # 0 - success
echo "Starting EtherCAT master..." # 1 - generic or unspecified error
# 2 - invalid or excess argument(s)
# remove modules # 3 - unimplemented feature (e.g. "reload")
unload_module 8139too # 4 - user had insufficient privileges
unload_module 8139cp # 5 - program is not installed
unload_module ec_8139too # 6 - program is not configured
unload_module ec_master # 7 - program is not running
# 8--199 - reserved (8--99 LSB, 100--149 distrib, 150--199 appl)
echo " loading master modules..." #
if ! modprobe ec_8139too ec_device_index=$DEVICEINDEX; then # Note that starting an already running service, stopping
echo "ERROR: Failed to load module!" # or restarting a not-running service as well as the restart
exit 1 # with force-reload (in case signaling is not supported) are
fi # considered a success.
case "$1" in
start)
echo -n "Starting EtherCAT master... "
# remove incompatible modules
for mod in 8139too 8139cp; do
if lsmod | grep "^$mod " > /dev/null; then
if ! rmmod $mod; then
/bin/false
rc_status -v
rc_exit
fi;
fi;
done
modprobe ec_8139too ec_device_index=$DEVICEINDEX
rc_status -v
;; ;;
stop) stop)
echo "Stopping EtherCAT master..." echo -n "Shutting down EtherCAT master... "
unload_module ec_8139too
unload_module ec_master for mod in ec_8139too ec_master; do
if lsmod | grep "^$mod " > /dev/null; then
if ! rmmod $mod; then
/bin/false
rc_status -v
rc_exit
fi;
fi;
done
if ! modprobe 8139too; then if ! modprobe 8139too; then
echo "Warning: Failed to restore 8139too module." echo "Warning: Failed to restore 8139too module."
fi fi
rc_status -v
;; ;;
*) restart)
print_usage $0 stop
exit 1 $0 start
esac
echo "done." rc_status
exit 0 ;;
esac
rc_exit
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment