@@ -415,6 +415,8 @@ export function buildMysqlctldUnit(config: VitessServiceConfig): string {
415415
416416/** Where the generated vtgate credentials live. */
417417export const VITESS_AUTH_FILE = '/etc/vitess/auth.json'
418+ /** Last credential document successfully loaded by vtgate. */
419+ export const VITESS_AUTH_APPLIED_FILE = '/var/lib/vitess/vtgate-auth.sha256'
418420
419421/**
420422 * vtgate's static credentials file.
@@ -439,8 +441,9 @@ export function buildVitessAuthFileScript(config: VitessServiceConfig): string[]
439441 `cat > "$VTESS_AUTH_TMP" <<'TS_CLOUD_VITESS_AUTH_EOF'` ,
440442 auth ,
441443 'TS_CLOUD_VITESS_AUTH_EOF' ,
442- `VTESS_VTGATE_AUTH_CHANGED=0` ,
443- `cmp -s "$VTESS_AUTH_TMP" ${ VITESS_AUTH_FILE } || VTESS_VTGATE_AUTH_CHANGED=1` ,
444+ `VTESS_VTGATE_AUTH_SHA="$(sha256sum "$VTESS_AUTH_TMP" | awk '{print $1}')"` ,
445+ `VTESS_VTGATE_AUTH_CHANGED=1` ,
446+ `if [ -f ${ VITESS_AUTH_APPLIED_FILE } ] && [ "$(cat ${ VITESS_AUTH_APPLIED_FILE } )" = "$VTESS_VTGATE_AUTH_SHA" ]; then VTESS_VTGATE_AUTH_CHANGED=0; fi` ,
444447 // Contains a password: readable by the daemon, nobody else.
445448 `install -o ${ VITESS_USER } -g ${ VITESS_USER } -m 0600 "$VTESS_AUTH_TMP" ${ VITESS_AUTH_FILE } ` ,
446449 'rm -f "$VTESS_AUTH_TMP"' ,
@@ -678,7 +681,7 @@ export function buildVitessProvisionScript(value: boolean | VitessServiceConfig
678681 // changed static-auth file is only read at process start, so rotate it
679682 // before the health gate while avoiding needless router restarts when the
680683 // desired credentials are unchanged.
681- ' if [ "$VTESS_VTGATE_AUTH_CHANGED" = 1 ]; then systemctl restart vitess-vtgate.service; fi' ,
684+ ` if [ "$VTESS_VTGATE_AUTH_CHANGED" = 1 ]; then systemctl restart vitess-vtgate.service; printf '%s\\n' "$VTESS_VTGATE_AUTH_SHA" > ${ VITESS_AUTH_APPLIED_FILE } ; chown ${ VITESS_USER } : ${ VITESS_USER } ${ VITESS_AUTH_APPLIED_FILE } ; chmod 0600 ${ VITESS_AUTH_APPLIED_FILE } ; fi` ,
682685 ...buildVitessBootstrapScript ( config ) ,
683686 ...buildVitessHealthCheck ( config ) ,
684687 )
0 commit comments