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.

71 lines
1.1 KiB

  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. [ "$timeout" = "0" ] && postargs=" -t $max_timeout"
  29. /usr/bin/lxc-stop -n "$name" "$postargs" &
  30. export STOPPID=$!
  31. fi
  32. }
  33. start() {
  34. config_load lxc-auto
  35. config_foreach start_container container
  36. }
  37. stop() {
  38. config_load lxc-auto
  39. config_foreach stop_container container
  40. # ensure e.g. shutdown doesn't occur before maximum timeout on
  41. # containers that are shutting down
  42. if [ $max_timeout -gt 0 ]; then
  43. for i in $(seq 1 $max_timeout); do
  44. if [ -d /proc/"$STOPPID" ]; then
  45. sleep 1s
  46. else
  47. return 0
  48. fi
  49. done
  50. fi
  51. }
  52. boot() {
  53. if [ ! -d /run ]; then
  54. ln -s /var/run /run
  55. fi
  56. start
  57. }