#!/bin/sh # Copyright 2016 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. nginx @Argv global oldcksum := $[cksum /etc/nginx/conf.d/default.conf] inotifywait -e modify,move,create,delete -mr --timefmt '%d/%m/%y %H:%M' --format '%T' \ /etc/nginx/conf.d/ | while read date time { global newcksum := $[cksum /etc/nginx/conf.d/default.conf] if test $newcksum != $oldcksum { echo "At $(time) on $(date), config file update detected." global oldcksum := $newcksum nginx -s reload } } (CommandList children: [ (C {(nginx)} {(DQ ($ VSub_At "$@"))}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:oldcksum) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [(C {(cksum)} {(/etc/nginx/conf.d/default.conf)})] ) left_token: spids: [51 55] ) } spids: [50] ) ] spids: [50] ) (Pipeline children: [ (C {(inotifywait)} {(-e)} {(modify) (Lit_Comma ",") (move) (Lit_Comma ",") (create) (Lit_Comma ",") (delete)} {(-mr)} {(--timefmt)} {(SQ <"%d/%m/%y %H:%M">)} {(--format)} {(SQ <"%T">)} {(/etc/nginx/conf.d/)} ) (While cond: [(Sentence child:(C {(read)} {(date)} {(KW_Time time)}) terminator:)] body: (DoGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:newcksum) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [(C {(cksum)} {(/etc/nginx/conf.d/default.conf)})] ) left_token: spids: [103 107] ) } spids: [102] ) ] spids: [102] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(DQ ($ VSub_Name "$newcksum"))} {(KW_Bang "!") (Lit_Other "=")} {(DQ ($ VSub_Name "$oldcksum"))} {(Lit_Other "]")} ) terminator: ) ] action: [ (C {(echo)} { (DQ ("At ") (${ VSub_Name time) (" on ") (${ VSub_Name date) (", config file update detected.") ) } ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:oldcksum) op: Equal rhs: {($ VSub_Name "$newcksum")} spids: [146] ) ] spids: [146] ) (C {(nginx)} {(-s)} {(reload)}) ] spids: [-1 128] ) ] spids: [-1 157] ) ] spids: [98 160] ) ) ] negated: False ) ] )