Linux Startup & Shutdown Beeper

#linux

Based on the blog post Beep on startup and shutdown, I decided to port their beeper to Systemd and a shortened snippet to simply copy and paste to my servers:

apt update
apt install -y beep

cat <<EOF > /etc/systemd/system/beep.service
[Unit]
Description=Beep on startup and shutdown

[Service]
Type=oneshot
RemainAfterExit=true
ExecStartPre=/usr/sbin/modprobe pcspkr
ExecStart=/usr/bin/beep -l 75 -f 500 -n -l 75 -f 1000 -n -l 75 -f 2000 -n -l 75 -f 3000
ExecStop=/usr/bin/beep -l 75 -f 3000 -n -l 75 -f 2000 -n -l 75 -f 1000 -n -l 75 -f 500

[Install]
WantedBy=multi-user.target

EOF

systemctl daemon-reload
systemctl enable --now beep

What the snippet does:

  1. Updates your packages (this assumes that you are using Ubuntu/any distro with apt as the package management)
  2. Installs the beep package
  3. Makes a new systemd service named beep
  4. Reloads systemd and enable the service to run on boot

What the systemd service does:

  1. Before running anything, it does modprobe pcspkr, this loads the module needed to beep.
  2. When the service starts, it plays beep -l 75 -f 500 -n -l 75 -f 1000 -n -l 75 -f 2000 -n -l 75 -f 3000
  3. When the service stops, it plays beep -l 75 -f 3000 -n -l 75 -f 2000 -n -l 75 -f 1000 -n -l 75 -f 500