Linux Startup & Shutdown Beeper
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:
- Updates your packages (this assumes that you are using Ubuntu/any distro with apt as the package management)
- Installs the
beeppackage - Makes a new systemd service named
beep - Reloads systemd and enable the service to run on boot
What the systemd service does:
- Before running anything, it does
modprobe pcspkr, this loads the module needed to beep. - 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 - 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