description "Starts bootstrap zlog"

start on filesystem or runlevel [2345]
stop on shutdown

# Upstart doesn't respect limits.conf, so the limit is manually set here
limit nofile 50000 50000
kill signal SIGINT
kill timeout 60
setuid zoox
setgid zoox

script
    deploy_dir=/opt/zoox/ai/zoox
    PATH=$PATH:$deploy_dir/bin
    export PATH

    bootstrap_zlog
end script

pre-start script
    # We have to set the path before we check for the existence of this binary
    deploy_dir=/opt/zoox/ai/zoox
    PATH=$PATH:$deploy_dir/bin

    if ! [ -x "$(command -v bootstrap_zlog)" ]; then
        echo "No bootstrap zlog installed, not starting"
        sudo stop zlog ; exit 0
    fi

    now=$(date +"%T")
    echo "Starting zlog at $now..."
    cd $deploy_dir
end script

pre-stop script
    now=$(date +"%T")
    echo "Stopping bootstrap zlog at $now..."
end script

post-stop script
    echo "done with bootstrap stopping zlog"
end script
