Debian Codegraph @

ansible_collections/community/docker/tests/images/healthcheck/is-healthy.go

raw symbols SCIP
1 /*
2 Copyright (c) Ansible Project
3 GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
4 SPDX-License-Identifier: GPL-3.0-or-later
5 */
6
7 package main
8
9 import (
10 "bytes"
11 "fmt"
12 "os"
13 )
14
15 func main() {
16 data, err := os.ReadFile("/health.txt")
17 if err != nil {
18 fmt.Fprintf(os.Stderr, "Error while reading health status: %s\n", err)
19 os.Exit(1)
20 }
21 if bytes.Equal(data, []byte("healthy")) {
22 fmt.Fprintf(os.Stdout, "Healthy.\n")
23 os.Exit(0)
24 }
25 if bytes.Equal(data, []byte("unhealthy")) {
26 fmt.Fprintf(os.Stdout, "Unhealthy!\n")
27 os.Exit(1)
28 }
29 if bytes.Equal(data, []byte("starting")) {
30 fmt.Fprintf(os.Stdout, "Starting...\n")
31 os.Exit(1)
32 }
33 fmt.Fprintf(os.Stderr, "Unknown health status: %s\n", data)
34 os.Exit(1)
35 }