lede-packages-rs

git clone git://archive.git.mtrnord.blog/MTRNord/lede-packages-rs.git
Log | Files | Refs | README | LICENSE

lxc-auto.init (983B)


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