lxc-auto.init 983 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/bin/sh /etc/rc.common
  2. . /lib/functions.sh
  3. START=99
  4. STOP=00
  5. run_command() {
  6. local command="$1"
  7. $command
  8. }
  9. start_container() {
  10. local cfg="$1"
  11. local name
  12. config_get name "$cfg" name
  13. config_list_foreach "$cfg" command run_command
  14. if [ -n "$name" ]; then
  15. /usr/bin/lxc-start -n "$name"
  16. fi
  17. }
  18. max_timeout=0
  19. stop_container() {
  20. local cfg="$1"
  21. local name timeout
  22. config_get name "$cfg" name
  23. config_get timeout "$cfg" timeout 300
  24. if [ "$max_timeout" -lt "$timeout" ]; then
  25. max_timeout=$timeout
  26. fi
  27. if [ -n "$name" ]; then
  28. if [ "$timeout" = "0" ]; then
  29. /usr/bin/lxc-stop -n "$name" &
  30. else
  31. /usr/bin/lxc-stop -n "$name" -t $timeout &
  32. fi
  33. fi
  34. }
  35. start() {
  36. config_load lxc-auto
  37. config_foreach start_container container
  38. }
  39. stop() {
  40. config_load lxc-auto
  41. config_foreach stop_container container
  42. # ensure e.g. shutdown doesn't occur before maximum timeout on
  43. # containers that are shutting down
  44. if [ $max_timeout -gt 0 ]; then
  45. sleep $max_timeout
  46. fi
  47. }