auto run script improvements

shut down previously running program cleanly before the system shuts
down