postinst maintainer script stops systemd unit file from starting automatically on install

I’m creating a small Debian package to install systemd unit files, specifically *.service files.

My package looks like:

            |- comapat
            |- preinst
            |- postinst
            |- rules
            |- myservice.service

When I install my package, the systemd services are automatically disabled and they do not start up.

Right after install, systemctl status myservice shows

[email protected]:~# systemctl status myservice
  ● myservice.service - My Service - echos output and says when it started
  Loaded: loaded (/lib/systemd/system/myservice.service; disabled; vendor preset: enabled)
  Active: inactive (dead)

However, when I install my package without a postinst script, the systemd services are automatically enabled and they do start up after install.

[email protected]:~# systemctl status myservice
● myservice.service - MyService - echos output and says when it started
Loaded: loaded (/lib/systemd/system/myservice.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2018-02-09 15:06:36 UTC; 10s ago
Main PID: 5024 (sh)
Tasks: 2
Memory: 172.0K
  CPU: 1ms
CGroup: /system.slice/myservice.service
       ├─5024 /bin/sh -c echo 'myservice.service started' && echo $(date +%s) && sleep infinity
       └─5026 sleep infinity

I’m confused because my postinst is “small and dumb”:

#!/bin/sh -e
# POSTINST script for myservice
set -e

echo "\033[36m HI I'M A POSTINST SCRIPT `date +"%s"` \033[39m"

Why does the presence of a postinst overwrite the “automatic enabling and starting” of a systemd service?

What part of debhelper deals with this and what am I missing?

Or what should I add to my postinst maintainer script to get my services up and running on install?

NOTES: My environment is a small vagrant box with a virtualbox provider. I am using the ubuntu-xenial64 Vagrant box. Not sure if this environment affects this.

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

You need to add the debhelper placeholder to your postinst:


So your postinst should look like

# POSTINST script for intera
set -e

echo "\033[36m HI I'M A POSTINST SCRIPT `date +"%s"` \033[39m"


exit 0

If you don’t include that, debhelper won’t add its auto-generated postinst snippets to your maintainer script. When you don’t have a postinst at all, it just generates the entire script; but if you have your own version, it only changes the placeholder.

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply