# When is rc.local run?



## hruodr (Apr 17, 2019)

Excuse me the question, but I never understood why rc becomes always more complicated, non transparent and distateful (linux guys have, after many init levels, now a systemd).

As I see, /etc/rc.local is run by the script /etc/rc.d/local, but I do not know in what order the scripts in /etc/rc.d are run.

I just want a bell ringing three times after all booting is ready (because I want to boot without monitor/keyboard and then connect with internet).

Another question is, how to ring the bell. With the sh echo builtin should be with: `echo -e "\a"`. Is there a better way?


----------



## SirDice (Apr 17, 2019)

hruodr said:


> As I see, /etc/rc.local is run by the script /etc/rc.d/local, but I do not know in what order the scripts in /etc/rc.d are run.


rcorder(8): `rcorder /etc/rc.d/* /usr/local/etc/rc.d/*`. Scripts are executed from top to bottom in that order.


----------



## hruodr (Apr 17, 2019)

This means, rc.local is not the last script?

Is the solution to use brute force and add at the end of /etc/rc the commands for ringing bells?!

Is that the sense of this hypercomplicated rc system?!


----------



## SirDice (Apr 17, 2019)

If you look at the order you'll see that networking is already active long before the last script gets executed. So there's no need to wait until the very last script is executed.


----------



## hruodr (Apr 17, 2019)

/etc/rc ends with:


```
echo ''
date
exit 0
```

Some more echos after `date`, bell ringing echos, will not make a catastrophe.


----------



## SirDice (Apr 17, 2019)

Your solution is going to be removed next time you run an update.

It's actually quite simple. And easier to maintain, just create a /usr/local/etc/rc.d/beep:

```
#!/bin/sh

# REQUIRE: NETWORKING sshd
# PROVIDE: beep

. /etc/rc.subr

name="beep"
rcvar="${name}_enable"
start_cmd="beep_start"

: ${beep_enable:="NO"}

load_rc_config $name

beep_start () {
        echo -e "\a"
}

run_rc_command "$1"
```
Make sure it's executable: `chmod +x /usr/local/etc/rc.d/beep`. 

This will run when NETWORKING and sshd are done, you should have network access by that time. Enable it with `sysrc beep_enable="YES"`. I haven't actually tested this, besides just running it. I can't hear the server, it's in a datacenter a couple of kilometers away


----------



## hruodr (Apr 17, 2019)

Thanks. Good to get an idea of how this rc philosophy works. For patient people that only use FreeBSD may be recommendable to learn it. I like simplicity, even if it looks like less professional.


----------



## SirDice (Apr 17, 2019)

hruodr said:


> Good to get an idea of how this rc philosophy works.


Have a read through rc(8) and rc.subr(8). Then look at a few existing rc.d scripts. It's actually quite easy to use once you understand the basic concepts.


----------



## George (Apr 17, 2019)

You could also ring a bell right at the login prompt.
Just add `^G` to /etc/gettytab.

So for example, the default section in /etc/gettytab could then look like:

```
default:\
             :cb:ce:ck:lc:fd#1000:im=^G\r\n%s/%m (%h) (%t)\r\n\r\n:sp#1200:\
             :if=/etc/issue:
```


----------

