# vim:ft=upstart:
description "SauceLabs' Sauce Connect tunnel worker supervisor service"

start on runlevel [2345]
stop on runlevel [016]

pre-start script
    # Load configuration
    test -r /etc/default/sc || { stop; exit 0; }
    . /etc/default/sc
    test -n "$SE_PORTS" || { stop; exit 1; }

    for se_port in $SE_PORTS
    do
        start sc_worker SE_PORT=$se_port
    done
end script

post-stop script
    # Load configuration
    test -r /etc/default/sc || { stop; exit 0; }
    . /etc/default/sc
    test -n "$SE_PORTS" || { stop; exit 1; }

    for se_port in $SE_PORTS
    do
        stop sc_worker SE_PORT=$se_port || true  # ignore shutdown instances
    done
end script
