start-sqm 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/bin/sh
  2. # This program is free software; you can redistribute it and/or modify
  3. # it under the terms of the GNU General Public License version 2 as
  4. # published by the Free Software Foundation.
  5. #
  6. # Copyright (C) 2012-4 Michael D. Taht, Toke Høiland-Jørgensen, Sebastian Moeller
  7. [ -n "$IFACE" ] || exit 1
  8. . /etc/sqm/sqm.conf
  9. . ${SQM_LIB_DIR}/functions.sh
  10. . ${SQM_LIB_DIR}/defaults.sh
  11. STATE_FILE="${SQM_STATE_DIR}/${IFACE}.state"
  12. check_state_dir
  13. # log file for the most recent sqm instance start
  14. if [ "$SQM_DEBUG" -eq "1" ] ; then
  15. SQM_DEBUG_LOG="${SQM_START_LOG}"
  16. OUTPUT_TARGET="${SQM_DEBUG_LOG}"
  17. echo "start-sqm: Log for interface ${IFACE}: $(date)" > "${OUTPUT_TARGET}"
  18. fi
  19. if [ -z "${SCRIPT}" ] ; then
  20. sqm_error "SCRIPT value is not defined in /etc/sqm/${IFACE}.iface.conf"
  21. sqm_error "Please check your configuration and try again."
  22. exit 1
  23. fi
  24. if [ -f "${STATE_FILE}" ]; then
  25. sqm_error "SQM already activated on ${IFACE}."
  26. exit 1
  27. fi
  28. # in case of spurious hotplug events, try double check whether the interface is really up
  29. if [ ! -d /sys/class/net/${IFACE} ] ; then
  30. sqm_error "${IFACE} does currently not exist, not even trying to start SQM on nothing."
  31. exit 1
  32. fi
  33. if [ "${ENABLED:-1}" -ne "1" ]; then
  34. sqm_log "SQM config disabled on ${IFACE}."
  35. exit 0
  36. fi
  37. if [ ! -f "${SQM_LIB_DIR}/$SCRIPT" ]; then
  38. sqm_error "SQM script ${SCRIPT} not found!"
  39. exit 1
  40. fi
  41. . "${SQM_LIB_DIR}/$SCRIPT"
  42. sqm_trace; sqm_trace "$(date): Starting." # Add some space and a date stamp to verbose log output and log files to separate runs
  43. sqm_log "Starting SQM script: ${SCRIPT} on ${IFACE}, in: ${DOWNLINK} Kbps, out: ${UPLINK} Kbps"
  44. if fn_exists sqm_start ; then
  45. sqm_debug "Using script specific sqm_start function overriding the generic sqm_start_default."
  46. sqm_start && write_state_file ${STATE_FILE} && sqm_log "${SCRIPT} was started on ${IFACE} successfully"
  47. else
  48. sqm_debug "Using generic sqm_start_default function."
  49. sqm_start_default && write_state_file ${STATE_FILE} && sqm_log "${SCRIPT} was started on ${IFACE} successfully"
  50. fi
  51. exit 0