6

I need to write a couple of Linux (Debian) startup scripts.

Are there any accurate templates available?

Mat
  • 52,586

3 Answers3

9

Just have a look at the scripts present in /etc/init.d/. Especially note the README file there. It also hints to this Debian Policy Manual section on init scripts.

Actually, what you're looking for might be /etc/init.d/skeleton:

# Short-Description: Example initscript
# Description:       This file should be used to construct scripts to be
#                    placed in /etc/init.d.
sr_
  • 15,384
2
gedit /usr/share/doc/initscripts-*/sysvinitfiles
宏杰李
  • 121
1

Debian used to ship an example initscript with dh-make (/usr/share/debhelper/dh_make/debian/init.d.ex) until jessie. But has dropped that since stretch (changelog [2]), because Debian was moving to systemd, and there were incompatibilities as addressed in bug #832764 [1]. However, if systemd interoperability is not a concern, we can still pull a copy of that file from old archives [3]. Another approach would be using the init-d-script (with manual in section 5) contained in package sysvinit-utils, with help of this, one can write a brief file only providing an (optional) LSB header, the daemon name, commandline arguments, pidfile, etc., then source /lib/init/init-d-script, and place this file under /etc/init.d. This actually is what was going on with init.d.ex of dh-make before it was then removed. Beside this, /lib/init/init-d-script can itself be used as (part of) an init script template for it has much of the init script functionality implemented.

[1] https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=832764 [2] http://metadata.ftp-master.debian.org/changelogs/main/d/dh-make/dh-make_2.201608_changelog [3] https://www.apt-browse.com/browse/debian/jessie/main/all/dh-make/1.20140617/file/usr/share/debhelper/dh_make/debian/init.d.ex