#!/bin/bash # Copyright 2015 The Kubernetes Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # loadedImageFlags is a bit-flag to track which docker images loaded successfully. let loadedImageFlags=0 while true { global restart_docker := 'false' if which docker !1 >/dev/null !2 > !1 { timeout 120 docker load -i /srv/salt/kube-bins/kube-proxy.tar !1 >/dev/null !2 > !1 global rc := $Status if [[ "${rc}" == 0 ]] { let loadedImageFlags="$(loadedImageFlags)|1" } elif [[ "${rc}" == 124 ]] { global restart_docker := 'true' } } # required docker images got installed. exit while loop. if [[ "${loadedImageFlags}" == 1 ]] { break; } # Sometimes docker load hang, restart docker daemon resolve the issue if [[ "${restart_docker}" ]] { service docker restart; } # sleep for 15 seconds before attempting to load docker images again sleep 15 } # Now exit. After kube-push, salt will notice that the service is down and it # will start it and new docker images will be loaded. (CommandList children: [ (C {(let)} {(Lit_VarLike "loadedImageFlags=") (0)}) (While cond: [(Sentence child:(C {(true)}) terminator:)] body: (DoGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:restart_docker) op: Equal rhs: {(false)} spids: [61] ) ] spids: [61] ) (If arms: [ (if_arm cond: [ (Sentence child: (SimpleCommand words: [{(which)} {(docker)}] redirects: [ (Redir op_id: Redir_Great fd: 1 arg_word: {(/dev/null)} spids: [72] ) (Redir op_id: Redir_GreatAnd fd: 2 arg_word: {(1)} spids: [75] ) ] ) terminator: ) ] action: [ (SimpleCommand words: [ {(timeout)} {(120)} {(docker)} {(load)} {(-i)} {(/srv/salt/kube-bins/kube-proxy.tar)} ] redirects: [ (Redir op_id: Redir_Great fd: 1 arg_word: {(/dev/null)} spids: [95] ) (Redir op_id: Redir_GreatAnd fd: 2 arg_word: {(1)} spids: [98] ) ] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:rc) op: Equal rhs: {($ VSub_QMark "$?")} spids: [102] ) ] spids: [102] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {(DQ (${ VSub_Name rc))} right: {(0)} ) ) terminator: ) ] action: [ (C {(let)} {(Lit_VarLike "loadedImageFlags=") (DQ (${ VSub_Name loadedImageFlags) ("|1")) } ) ] spids: [-1 123] ) (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {(DQ (${ VSub_Name rc))} right: {(124)} ) ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:restart_docker) op: Equal rhs: {(true)} spids: [157] ) ] spids: [157] ) ] spids: [137 154] ) ] spids: [-1 161] ) ] spids: [-1 79] ) ] spids: [-1 164] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {(DQ (${ VSub_Name loadedImageFlags))} right: {(1)} ) ) terminator: ) ] action: [ (Sentence child: (ControlFlow token:) terminator: ) ] spids: [-1 189] ) ] spids: [-1 194] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr:(WordTest w:{(DQ (${ VSub_Name restart_docker))})) terminator: ) ] action: [ (Sentence child: (C {(service)} {(docker)} {(restart)}) terminator: ) ] spids: [-1 215] ) ] spids: [-1 224] ) (C {(sleep)} {(15)}) ] spids: [58 237] ) ) ] )