1

While troubleshooting a failed Docker deploy, I noticed this line was in the Dockerfile. What does the following line do exactly?

#!/bin/sh\nexit 0" > /usr/sbin/policy-rc.d
david
  • 135
  • 7

1 Answers1

2

There are four components to this bit of code:

1). #!/bin/sh is a "shebang" which points to the specific interpreter in which the subsequent code is run through. In this case the code that comes after the shebang is sent to Sh, which is most probably Bash ( probably the most common Linux shell).

2). \n is a special character that defines a newline.

3). exit 0 is used in scripts to define how it ends. Generally, an exit code of zero means the program finished successfully (not always true, so please bear that in mind).

4). > is a Linux redirection. There are several operators that can manipulate Stdin, Stdout and Stderr. In this case, the results of Stdin (to the left of the operator) are sent to a file (defined by the file name on the right of the operator). That's how that particular file is updated.

Assuming this is a Debian/Ubuntu distro, the policy-rc.d determines if a daemon starts/restarts if it has just been installed/upgraded. It does this by reading the exit code, so in this example "0" would mean it is OK to start automatically.

Usually in chrooted environments this exit code is set to 101 to prevent daemons starting. Here's a useful link for more info: https://people.debian.org/~hmh/invokerc.d-policyrc.d-specification.txt

Brett Levene
  • 786
  • 6
  • 9