# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.

# This upstart version lacks the ability of unloading modules with
# the "stop" directive, as upstart does not support a feature like
# systemd's RemainAfterExit option.


description "Apply kpatch kernel patches"

start on runlevel [2345] # Roughly equivalent to multi-user.target

# We are not a daemon
task

# Emulating systemd's ConditionKernelCommandLine option.
pre-start script
    if [[ -e /proc/cmdline ]]
    then
        grep -q "kpatch.enable=0" /proc/cmdline && exit 1
    else
        dmesg | grep -q "Command line.*kpatch.enable=0" && exit 1
    fi

    exit 0
end script

# Main process (start)
exec PREFIX/sbin/kpatch load --all

