
# testselection - service manager for januz / test selection app
#
# Note: this conf file lives at /etc/init/testselection.conf on sun-tmvm-fwvalapp03-prod
#       updates made to this file should be propagated to that file on that system
#
# Usage: sudo service testselection start
#        sudo service testselection status
#        sudo service testselection stop

description "Test Selection Upstart wrapper for januz.py"
author "Tushar Rawat <trawat@zoox.com>"

# Start when filesystem and networking are available
start on filesystem or runlevel [2345]

# stop if system is entering shutdown
stop on shutdown

# respawn if an error is encountered
respawn

# respawn limit is 10 attempts w/ 5 seconds between attempt. After this limit respawn is halted
# and the upstart job goes to stopped/waiting state
respawn limit 10 5

# Main body of the job, executed after pre-start script but before pre-stop script
script

    export PYTHON_HOME=/home/svc-citeststation/VirtualEnvs/selection_app/bin
    echo $$ > /var/run/januz.pid
    # Because januz relies on repo_info it must be started in the driving root directory
    cd /home/svc-citeststation/zoox/driving
    # And of course upstart uses /bin/sh so we need to include variables that would normally
    # be loaded by ~/.bashrc
    . /home/svc-citeststation/.e2eaf_creds
    # launch the actual application
    exec $PYTHON_HOME/python /home/svc-citeststation/zoox/driving/januz.py

end script

# Before running the script section, embed the date of start into the testselection log
pre-start script
    echo "[`date`] (Januz) Test Selection Starting" >> /var/log/upstart/testselection.log
end script

# Before stopping the job, embed the date of stop into the testselection log
pre-stop script
    rm /var/run/januz.pid
    echo "[`date`] (Januz) Test Selection Stopping" >> /var/log/upstart/testselection.log
end script
