dh_installinit - Linux


dh_installinit is a utility used in Debian package creation to generate a default init script for a service. It is designed to simplify the process of creating a properly formatted init script that follows Debian packaging guidelines.


dh_installinit [-a architecture] [-g group] [-i init file] [-l layout] [-n name]
[-p priority] [-u user] [-v value] [-x control value] [files...]


  • -a architecture: Specify the target architecture for the init script. Default is the current architecture.
  • -g group: Set the group ownership of the generated init script. Default is ‘debian-sys-maint’.
  • -i init file: Specify a custom init file template to use. Default is ‘/usr/share/debhelper/init.d/debian’.
  • -l layout: Define the layout of the generated init script. Valid values are ‘sysv’ and ‘upstart’. Default is ‘sysv’.
  • -n name: Assign a name to the service. Default is the package name.
  • -p priority: Set the priority of the init script. Default is ’90’.
  • -u user: Specify the user ownership of the generated init script. Default is ‘root’.
  • -v value: Define a variable to be passed to the init file template.
  • -x control value: Remove the specified control word from the generated init script.
  • files…: Additional files to include in the init script. Typically used to add dependencies or startup scripts.


Simple usage:


This will generate a default init script with the package name as the service name and other settings using Debian defaults.

Customizing the service name and layout:

dh_installinit -n myservice -l upstart

This will generate an init script for the ‘myservice’ service using the Upstart layout.

Setting a custom variable for the template:

dh_installinit -v DEPEND_LIST=xserver-xorg-input-all

This will pass the variable DEPEND_LIST with the value xserver-xorg-input-all to the init file template.

Common Issues

  • Missing dependencies: Ensure that the package being built has declared all required dependencies. Otherwise, the generated init script may fail to start the service.
  • Incorrect permissions: The init script should have proper file permissions (755) and ownership (root:debian-sys-maint). Incorrect permissions can cause startup failures.


Using dh_installinit with dh:

dh $@

This sequence can be used in a Debian package build script to generate an init script after package installation.

Combining with other commands:

sudo service myservice start
sudo update-rc.d myservice defaults

This can be used to start the service and add it to the default runlevels after the init script has been generated.

Related Commands

  • dh: The Debian helper tool that automates many tasks in Debian package creation.
  • service: Command for controlling services (starting, stopping, restarting).
  • update-rc.d: Command for managing runlevels and service startup/stop scripts.