You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.2 KiB

  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2013 Julius Schulz-Zander <julius@net.t-labs.tu-berlin.de>
  3. # Copyright (C) 2014-2017 OpenWrt.org
  4. # Copyright (C) 2018 Yousong Zhou <yszhou4tech@gmail.com>
  5. START=15
  6. ovs_script_dir=/usr/share/openvswitch/scripts
  7. ovs_ctl="$ovs_script_dir/ovs-ctl"; [ -x "$ovs_ctl" ] || ovs_ctl=:
  8. ovn_ctl="$ovs_script_dir/ovn-ctl"; [ -x "$ovn_ctl" ] || ovn_ctl=:
  9. EXTRA_COMMANDS=status
  10. start() {
  11. ovs_action start "$@"
  12. }
  13. stop() {
  14. ovs_action stop "$@"
  15. }
  16. restart() {
  17. ovs_action restart "$@"
  18. }
  19. status() {
  20. ovs_action status "$@"
  21. }
  22. ovs_action_cfgs=
  23. ovs_action() {
  24. local action="$1"; shift
  25. local cfgtype
  26. ovs_action_cfgs="$*"
  27. config_load openvswitch
  28. for cfgtype in ovs ovn_northd ovn_controller; do
  29. config_foreach "ovs_xx" "$cfgtype" "$action" "$cfgtype"
  30. done
  31. }
  32. ovs_xx() {
  33. local cfg="$1"
  34. local action="$2"
  35. local cfgtype="$3"
  36. local disabled
  37. if [ -n "$ovs_action_cfgs" ] && ! list_contains "ovs_action_cfgs" "$cfg"; then
  38. return
  39. fi
  40. case "$action" in
  41. status|stop) ;;
  42. *)
  43. config_get_bool disabled "$cfg" disabled 0
  44. [ "$disabled" -le 0 ] || return
  45. ;;
  46. esac
  47. case "$cfgtype" in
  48. ovs)
  49. "$ovs_ctl" "$action" \
  50. --system-id=random
  51. ;;
  52. ovn_*)
  53. "$ovn_ctl" "${action}_${cfgtype#ovn_}"
  54. ;;
  55. esac
  56. }