I got a problem with the upstart files of Ubuntu in /etc/init/. I am trying to run a process if it does not already exist. So I wrote a conf file and start with "start"
The following two files are mostly same except for the process being searched. The init process in the first file is always found and a few repetitions of "1 2 4" are output into $TMPFILE as a result.
start on filesystem and net-device-up IFACE!=lo
stop on runlevel [016]
respawn
script
TMPFILE=/var/log/tmp.log
echo 1 >> $TMPFILE
PID=$(pgrep -f "init" -o)
echo 2 >> $TMPFILE
if [ -z $PID ] ; then
echo 3 >> $TMPFILE
fi
echo 4 >> $TMPFILE
end script
For the second file, doesnotexist is not found by pgrep. However, only repetitions of "1 " is output into $TMPFILE. I also tried running the script part separately, and that outputs "1 2 3 4" just as expected.
start on filesystem and net-device-up IFACE!=lo
stop on runlevel [016]
respawn
script
TMPFILE=/var/log/tmp.log
echo 1 >> $TMPFILE
PID=$(pgrep -f "doesnotexist" -o)
echo 2 >> $TMPFILE
if [ -z $PID ] ; then
echo 3 >> $TMPFILE
fi
echo 4 >> $TMPFILE
end script
- How did this happen? Did upstart receive the result of pgrep as an exception?
- How can I fix this issue?
- Why would there be a few repetitions of the output instead of one? The output is not growing indefinitely and does not seem like re-spawning.