Getting ready

In Ubuntu 16.04 LTS (and other distributions), use systemd. Knowledge of both the init.d and systemd service control systems is certainly worth having as many embedded systems use Busybox. BusyBox uses the init.d system instead of systemd.

Before diving into the "how to do it" section, we are going to create a template init script for posterity and awareness should you run into them. It will be called myscript and it will run myscript.sh. At a minimum, a system.d compatible script looks like the following:

#!/bin/sh### BEGIN INIT INFO# Provides: myscript# Required-Start: $local_fs# Required-Stop: $local_fs# Default-Start: 2 3 4 5# Default-Stop: 0 1 6# Short-Description: Start script or daemons example### END INIT INFOPATH=/sbin:/bin:/usr/sbin:/usr/bin ...

Get Bash Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.