とんちゃんといっしょ

Cloudに関する技術とか日常とかについて書いたり書かなかったり

halyardをUpdateしたら動かなくなったのでJava RuntimeをUpdateした話

いつもどおりhalyardをUpdateしたはずが、Halyard Daemonが動かなくなった。

$ sudo update-halyard

Install completed... restarting Halyard
The halyard daemon isn't running yet... starting it manually........................................................
Waiting for halyard to start timed out after 122 seconds

原因がわからないのでどうしたもんかと思ったが、とりあえず which hal して実行元を見に行く

$  which hal
/usr/local/bin/hal

次にwhichで出てきた先を見に行く

$ cat /usr/local/bin/hal
#!/usr/bin/env bash

set -e

HALYARD_DAEMON_PID_FILE=/opt/halyard/pid
HALYARD_DAEMON_PID=""
HALYARD_STARTUP_TIMEOUT_SECONDS=120

HAL=/opt/halyard/bin/hal

function start_daemon() {
    printf "The halyard daemon isn't running yet... starting it manually"

    /opt/halyard/bin/halyard \
      2> /var/log/spinnaker/halyard/halyard.err \
      > /var/log/spinnaker/halyard/halyard.log &

    echo $! > $HALYARD_DAEMON_PID_FILE

    local wait_start=$(date +%s)

    set +e
    $HAL --ready &> /dev/null
    while [ "$?" != "0" ]; do
        local wait_now=$(date +%s)
        local wait_time=$(( $wait_now - $wait_start ))

        if [ "$wait_time" -gt "$HALYARD_STARTUP_TIMEOUT_SECONDS" ]; then
            >&2 echo ""
            >&2 echo "Waiting for halyard to start timed out after $wait_time seconds"
            exit 1
        fi

        printf '.'
        sleep 2
        $HAL --ready &> /dev/null
    done
    set -e

    echo ""
}

function kill_daemon() {
    pkill -f '/opt/halyard/lib/halyard-web' || true
}

if [ -f "$HALYARD_DAEMON_PID_FILE" ]; then
    HALYARD_DAEMON_PID=$(cat $HALYARD_DAEMON_PID_FILE)
fi

if [ -z "$HALYARD_DAEMON_PID" ]; then
    kill_daemon
    start_daemon
else
    set +e
    ps $HALYARD_DAEMON_PID &> /dev/null
    exit_code=$?
    set -e

    if [ "$exit_code" != "0" ]; then
        kill_daemon
        start_daemon
    fi
fi

$HAL "$@"

/opt/halyard/bin/hal --ready あたりを見ればなんとなく分かりそうだなとわかったのでやってみる

$  /opt/halyard/bin/hal --ready
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/netflix/spinnaker/halyard/cli/Main has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0

どうやらJava Runtimeのバージョンが古いことが原因らしいので上げればいけるっぽいのでまず手元のJavaのバージョンを確認

$ java -version
openjdk version "1.8.0_272"
OpenJDK Runtime Environment (build 1.8.0_272-8u272-b10-0+deb9u1-b10)
OpenJDK 64-Bit Server VM (build 25.272-b10, mixed mode)

OpenJDKの1.8らしいのでそれより上にすれば行けそう。 OpenJDKの11が出ているのでそれにしてみる。

$ sudo apt install openjdk-11-jre openjdk-11-jdk
$ java -version
openjdk version "11.0.6" 2020-01-14
OpenJDK Runtime Environment (build 11.0.6+10-post-Debian-1bpo91)
OpenJDK 64-Bit Server VM (build 11.0.6+10-post-Debian-1bpo91, mixed mode, sharing)

Java Runtimeのバージョンが上がったところでもう一度 update-halyard を試す

$ sudo update-halyard

Install completed... restarting Halyard
The halyard daemon isn't running yet... starting it manually.....
1.40.0-20201028133206
No completion file found at '/etc/bash_completion.d/hal'.
Assuming no bash completion is configured, skipping.

最後にファイルが見つからないみたいなのが出たけど、halyard Daemonは動いたようなのでひとまずOK