This snippet will pipe the output of your service
into logger, while still allowing you to exec the
service process (thus replacing the shell process)
so that upstart doesn't get confused. It also makes
sure the logger process is reparented to init, so
it's not a child of your service, and it avoids
leaving cruft sitting around in the filesystem, even
though it needs to create a fifo temporarily.
script
set -e
mkfifo /tmp/myservice-log-fifo
( logger -t myservice </tmp/myservice-log-fifo & )
exec >/tmp/myservice-log-fifo
rm /tmp/myservice-log-fifo
exec myservice 2>/dev/null
end script
Here's how it works:
mkfifo /tmp/myservice-log-fifo simply makes the fifo special file
(aka named pipe). Type man 7 fifo for more info.
( logger ... </tmp/myservice-log-fifo & ) starts logger reading from the fifo, in the background. The parens cause the logger process to be reparented to init, rather than remaining a child of the current shell process.
exec >/tmp/myservice-log-fifo redirects the current shell's stdout to the fifo. Now we have an open file descriptor for that fifo, and we don't actually need the filesystem entry any more...
rm /tmp/myservice-log-fifo so we'll remove it.
exec myservice 2>/dev/null simply runs the service in the usual way. Stdout is already going to the fifo, and that won't change when the new program executes.