# Beep on sucessful bootup



## Phishfry (Jan 15, 2018)

I have several headless machines and I would like to have a beep "song" play on successful bootup.
Just like pfSense. On my APU's it beeps on BIOS POST test but i want more.

What is recommended? Do I need to make a rc.d daemon that starts last?

Any tutorials or similar threads? I can't find what I am looking for.


----------



## Phishfry (Jan 15, 2018)

So `kldload speaker` and then `echo "cdefgab" > /dev/speaker`
That works. So I need to make an rc.d script??


----------



## Phishfry (Jan 15, 2018)

I also want to add this to some Arm devices with a Piezo buzzer.
How would I assign GPIO pin with a piezo buzzer to /dev/speaker ?


----------



## poorandunlucky (Jan 19, 2018)

Phishfry said:


> So `kldload speaker` and then `echo "cdefgab" > /dev/speaker`
> That works. So I need to make an rc.d script??



:'D

so much win!

that's the most awesome thing I ever...


----------



## mrclksr (Jan 20, 2018)

Phishfry said:


> Do I need to make a rc.d daemon that starts last?


An rc script should do the job. Just make it start after LOGIN.



Phishfry said:


> So  kldload speaker and then  echo "cdefgab" > /dev/speaker


Really nice! I couldn't resist:


```
#!/bin/sh

# PROVIDE: beep
# REQUIRE: LOGIN
#
# Add these lines to /etc/rc.conf.local or /etc/rc.conf
# to enable this service:
#
# beep_enable (bool):       Set to NO by default.
#                           Set it to YES to enable beep.
#

. /etc/rc.subr

name=beep
required_modules="speaker"
start_cmd="do_beep"
score="O0 G G G L8 D#. L16 A# L4 G L8 D#. L16 A# L2 G"

rcvar=beep_enable

load_rc_config $name

: ${beep_enable:="NO"}

do_beep()
{
   echo ${score} > /dev/speaker
}

run_rc_command "$1"
```


----------



## ralphbsz (Jan 20, 2018)

An rc.d script is the cleaner solution.  Would a single line in /etc/rc.local do the trick more easily?  That file is executed a little bit too early, but pretty close.


----------



## ShelLuser (Jan 20, 2018)

You could also consider using crontab, see crontab(5). If you use @reboot instead of specifying a time then the command you specify will run once as soon as cron starts.


----------



## Phishfry (Jan 20, 2018)

I am not sure which way to go yet.
Having a continually running daemon for a startup tone seems like a overkill for something that only runs on boot.
Can I have it close the daemon after running?

For a buzzer on Arm boards I could not find how to redirect gpio pin to /dev/speaker.
So I am using mono tone with beep-beep-beep by cycling power on the gpio pin in my rc.d script.
If I understand things right I could do a melody with the peizo buzzer if I used PWM. I don't need that level of sophistication.

What mechanisms exists if I wanted to do the reverse tone on shutdown?


----------



## mrclksr (Jan 20, 2018)

Phishfry said:


> Having a continually running daemon for a startup tone seems like a overkill for something that only runs on boot.
> Can I have it close the daemon after running?


The rc script I posted does what you want, if I understood your question correctly. It loads the speaker module if necessary, plays the motive of the _Imperial March_, and exits.


----------



## Phishfry (Jul 15, 2018)

Thanks to mrclksr as I stole his startup script and tweaked it for my use case.
I wanted Ascending notes for startup and Descending notes for exit. Just like monoWall used.
So I made two separate services. One for startup and next up one for shutdown.
/etc/rc.d/startup_sound

```
#!/bin/sh
# PROVIDE: startup_sound
# REQUIRE: LOGIN
#
# Add these lines to /etc/rc.conf.local or /etc/rc.conf
# to enable this service:
# kld_list="speaker"
# startup_sound_enable (bool):  Set to NO by default.
#                               Set it to YES to enable startup_sound.
#

. /etc/rc.subr

name=startup_sound
required_modules="speaker"
start_cmd="play_startup_sound"
notes="FGABC"

rcvar=startup_sound_enable

load_rc_config $name

: ${startup_sound_enable:="NO"}

play_startup_sound()
{
   echo ${notes} > /dev/speaker
}

run_rc_command "$1"
```

Now make it executable; `chmod +x /etc/rc.d/startup_sound`


----------

