sqm-bin 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/bin/sh
  2. . /etc/sqm/sqm.conf
  3. ACTION="$1"
  4. RUN_IFACE="$2"
  5. if [ "$(id -u)" -ne "0" ]; then
  6. echo "This script must be run as root." >&2
  7. exit 1
  8. fi
  9. if [ "$ACTION" != "start" -a "$ACTION" != "stop" -a "$ACTION" != "reload" ]; then
  10. echo "Usage: $0 <start|stop|reload> [iface]." >&2
  11. exit 1
  12. fi
  13. # Stopping all active interfaces
  14. if [ "$ACTION" = "stop" -a -z "$RUN_IFACE" ]; then
  15. echo "Stopping SQM on all active interfaces." >&2
  16. for f in ${SQM_STATE_DIR}/*.state; do
  17. # Source the state file prior to stopping; we need the $IFACE and
  18. # $SCRIPT variables saved in there.
  19. [ -f "$f" ] && ( . $f; IFACE=$IFACE SCRIPT=$SCRIPT SQM_DEBUG=$SQM_DEBUG SQM_DEBUG_LOG=$SQM_DEBUG_LOG OUTPUT_TARGET=$OUTPUT_TARGET ${SQM_LIB_DIR}/stop-sqm )
  20. done
  21. exit 0
  22. fi
  23. if [ -n "$RUN_IFACE" ]; then
  24. if [ ! -f /etc/sqm/${RUN_IFACE}.iface.conf ]; then
  25. echo "No config file found for iface $RUN_IFACE." >&2
  26. exit 1
  27. fi
  28. IFACE=$RUN_IFACE
  29. . /etc/sqm/${RUN_IFACE}.iface.conf
  30. [ -f ${SQM_STATE_DIR}/$IFACE.state ] && ( . ${SQM_LIB_DIR}/stop-sqm )
  31. [ "$ACTION" = "stop" ] || ( . ${SQM_LIB_DIR}/start-sqm )
  32. else
  33. echo "Starting SQM on all configured interfaces." >&2
  34. for f in /etc/sqm/*.iface.conf; do
  35. if [ -f "$f" ]; then
  36. IFACE=$(basename $f .iface.conf)
  37. . $f
  38. [ -f ${SQM_STATE_DIR}/$IFACE.state ] && ( . ${SQM_LIB_DIR}/stop-sqm )
  39. [ "$ACTION" = "stop" ] || ( . ${SQM_LIB_DIR}/start-sqm )
  40. else
  41. echo >&2
  42. echo "Error: No valid interface configuration found." >&2
  43. echo "A interface must be defined in /etc/sqm/<interface name>.iface.conf" >&2
  44. echo "Please define a interface configuration in /etc/sqm." >&2
  45. echo "For more information, see the template file in" >&2
  46. echo "/etc/sqm/eth0.iface.conf.example" >&2
  47. exit 1
  48. fi
  49. done
  50. fi