On Wed, 2009-09-16 at 17:45 -0700, Sandeep Puddupakkam (spuddupa) wrote: > Using upstart 0.5. > > I have a job file like this. File blah does not exist. > > [172:/etc/init/jobs.d]$ cat test > > console output > > script > > echo "Starting here..." > > val=$(ls blah) > > echo This line is not being printed.. ls returned $? Val=$val > > end script > Shell scripts run by Upstart are run with -e set (consult your shell manual), but in principle this means that any command that fails will result in the failure of the entire script, unless the result is otherwise used in a logic statement.
To quote from POSIX.1:
-e When this option is on, if a simple command fails for any
of the reasons listed in
http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_08_01
or returns an exit status value >0, and is not part of the
compound list following a while, until, or if keyword, and is
not a part of an AND or OR list, and is not a pipeline preceded
by the ! reserved word, then the shell shall immediately exit.
> In the sample above `ls blah` returns 1 and this is being shown as the
> termination code of test.
>
Correct.
> However when I run the same stuff using a shell script I see this
> output
>
Add "set -e" to your shell script, or "#!/bin/sh -e" to see results
identical to what Upstart does.
> So my questions.
>
> 1) Why is the output different when I run stuff using a job file vs a
> script.
>
Your script is not using "set -e", Upstart enforces "-e" for all
scripts.
> 2) How do I make sure my job continues to run even if there is a
> failure.
>
If you want the empty string when "blah" does not exist:
val=$(ls blah 2>/dev/null || true)
If you want to handle the case of blah not existing independently,
exactly as you did below:
> echo "Starting here..."
>
> if val=$(ls blah); then
>
> echo "exit status: $?"
>
> fi
>
> echo "came past exit."
>
> end script
>
Scott
--
Have you ever, ever felt like this?
Had strange things happen? Are you going round the twist?
signature.asc
Description: This is a digitally signed message part
-- upstart-devel mailing list [email protected] Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/upstart-devel
