What is the purpose of the exit code in rc.local? I seem to execute just fine without it. The header shows:

#!/bin/sh -e
# rc.local - executed at the end of each multiuser runlevel
# Make sure that the script will "exit 0" on success or any other
# value on error.

Who checks the return code? Does it default to 0 anyways?


It doesn't say "always exit 0". Read it again without the line break.

Make sure that the script will "exit 0" on success or any other value on error.

  • To indicate success, exit 0.
  • To indicate error, exit any other value.

There isn't necessarily anything that will check its status, but some init systems will display "[OK]" or "[FAIL]" on screen for the user. In any case, it's good practice to make sure your scripts exit with a meaningful return code.

The default exit status, like any other script, will be the exit status of the last command run in the script.

  • Nice. But the question still stands: what, if anything, checks that exit status? – dhag Dec 4 '15 at 16:47
  • What do you mean by "some init systems"? – jarno Feb 17 '16 at 21:25
  • 2
    sysv init on Linux did that for a while. – bahamat Feb 18 '16 at 0:26
  • I misread the instruction as 'your script should always exit 0' too. Perhaps the comment could be reworded for clarity? – Colonel Panic Jun 21 '17 at 11:19

You do not need exit 0 at the end of the script.

Run locate rc.local | grep -vF /etc/rc.local to find files that may be involved in calling /etc/rc.local and examining its exit code.

/etc/init.d/rc.local seems to be such an init script in my Xubuntu 15.10: It seems to get the exit code and log something using that value, if "$VERBOSE" variable is not "no".

You may put line echo "$(ps -o args= $PPID)" >/tmp/caller to /etc/rc.local, and it writes the caller's name in file /tmp/caller during boot. In my Xubuntu 15.10 system that is "/sbin/init persistent splash".


rc.local is a script file you can put your script for last running command after linux up

rc.local doesn't provide a way to intelligently recover from errors. If any command fails, it stops running, exit 0 help if any error occur

Exit codes are a number between 0 and 255, which is returned by any Unix command when it returns control to its parent process.

  • If, indeed, rc.local execution stops on the first error, then exit 0 won't help since it will only run if all preceding commands exit successfully. Do you mean perhaps that exit 0 is there for the specific case where the file contains no commands at all? In any case, it would be nice to find authoritative references. – dhag Dec 4 '15 at 16:43
  • rc.local doesn't terminate on first failure. It runs just like any other script would. – David King Dec 4 '15 at 16:48
  • 2
    … any other script with the -e option passed to the shell, that is. Read the first line of the script as given in the question. – JdeBP Dec 4 '15 at 18:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.