Details of the differences between and etc and rc local and and etc and and rc local in ubuntu system

  • 2020-06-12 11:39:48
  • OfStack

preface

We need to add 1 program to boot under ubuntu, 1 can be completed by modifying rc.local generally, but there are two rc.local files under ubuntu. Respectively is/etc rc local and/etc init d/rc local. You can find the relationship between them by looking at the contents of the following two files:

/etc/init.d/rc.local


#! /bin/sh
### BEGIN INIT INFO
# Provides:  rc.local
# Required-Start: $all
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop:
# Short-Description: Run /etc/rc.local if it exist
### END INIT INFO


PATH=/sbin:/usr/sbin:/bin:/usr/bin

. /lib/init/vars.sh
. /lib/lsb/init-functions

do_start() {
 if [ -x /etc/rc.local ]; then
  [ "$VERBOSE" != no ] && log_begin_msg "Running local boot scripts (/etc/rc.local)"
 /etc/rc.local
 ES=$?
 [ "$VERBOSE" != no ] && log_end_msg $ES
 return $ES
 fi
}

case "$1" in
 start)
 do_start
 ;;
 restart|reload|force-reload)
 echo "Error: argument '$1' not supported" >&2
 exit 3
 ;;
 stop)
 ;;
 *)
 echo "Usage: $0 start|stop" >&2
 exit 3
 ;;
esac

As you can see from the comments, this script runs at the startup level of 2, 3, 4, and 5, can only handle the parameters of start, then execute start, or /etc/ rc.local if there is a /etc/ rc.local file. If you want to put the startup procedures/etc/init d/rc local file, remember don't 1 brain write files the back to go, because in case script will exit in the block.

/etc/rc.local


#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

exit 0

There's basically nothing in this script. It's just a template for putting bootstrap programs on your computer. Just write your program before exit line 0.

So to add a boot entry, simply add it to the /etc/ rc.local file.

Startup level of ubuntu:

0 to turn it off

A single user

2-5 Multi-user graphical interfaces

6 to restart

For each startup level, there is a directory like /etc/ rc5.d /. Here is a list of scripts that are basically soft links to /etc/ init.d /.

Note: My system is ubuntu 15.04

conclusion


Related articles: