My upstart job is failing in pre-start, when it moves any previous logfile to a backup:
pre-start script
mv -f $LOGDIR/$LOGFILE $LOGDIR/$LOGFILE.bak
touch $LOGDIR/$LOGFILE
end script
I expect the mv
to fail if the previous logfile doesn't exist, so added the touch
to ensure that the last command in the script body returns 0.
However if the script runs when there isn't a previous logfile in the log directory, it fails in pre-start:
Jan 9 17:21:14 ip-172-30-1-54 kernel: [ 250.154908] init: myscript state changed from starting to security
Jan 9 17:21:14 ip-172-30-1-54 kernel: [ 250.154951] init: myscript state changed from security to pre-start
Jan 9 17:21:14 ip-172-30-1-54 kernel: [ 250.155652] init: myscript pre-start process (1425)
Jan 9 17:21:14 ip-172-30-1-54 kernel: [ 250.157167] init: myscript pre-start process (1425) terminated with status 1
Jan 9 17:21:14 ip-172-30-1-54 kernel: [ 250.157280] init: myscript goal changed from start to stop
If I then start the script again, it gets through pre-start successfully and into the main script body:
Jan 9 17:21:29 ip-172-30-1-54 kernel: [ 265.444327] init: myscript state changed from starting to security
Jan 9 17:21:29 ip-172-30-1-54 kernel: [ 265.444371] init: myscript state changed from security to pre-start
Jan 9 17:21:29 ip-172-30-1-54 kernel: [ 265.445359] init: myscript pre-start process (1431)
Jan 9 17:21:29 ip-172-30-1-54 kernel: [ 265.447203] init: myscript pre-start process (1431) exited normally
Jan 9 17:21:29 ip-172-30-1-54 kernel: [ 265.447249] init: myscript state changed from pre-start to spawned
Jan 9 17:21:29 ip-172-30-1-54 kernel: [ 265.447874] init: myscript main process (1434)
Jan 9 17:21:29 ip-172-30-1-54 kernel: [ 265.447896] init: myscript state changed from spawned to post-start
Jan 9 17:21:29 ip-172-30-1-54 kernel: [ 265.447972] init: myscript state changed from post-start to running
From this behavior, I'm inferring that the script body is executed one line at a time, and any failure terminates the script (much like a make
). The documentation of the script
directive does not give any guidance:
Allows the specification of a multi-line block of shell code to be executed. Block is terminated by end script.
Can anyone either confirm or deny my belief? If confirmed, I can simply run a self-contained shell script with exec
. If denied, I need to look elsewhere for my problem.