When installing packages with daemons, they often restart that service during installation/upgrade on Debian.

I got a daemon that has some options that can only be set on runtime, not configured. If the Debian package was under my control, I'd change the init-script so it contained a function to set those options and calls it after (re)starting the service.

As this daemon is from a remote repository and I don't want to build my own deb, I need a solution that does not change any files contained in the package(to avoid problems when updating the package via dpkg/apt).

So, is there a possibility to hook into that process to execute some commands or a script after the restart of that service in a clean way?

2 Answers 2


I know this question is old, but I found it when searching for "debian package hook" which was the wrong keyword list.

There might actually be a way with dpkg's triggers:

A dpkg trigger is a facility that allows events caused by one package but of interest to another package to be recorded and aggregated, and processed later by the interested package.

I knew it existed, but have never worked with it, yet.


If a delay of a few minutes would be acceptable then the easiest thing to do is to create a cronjob which runs a script to check whether the daemon is still running and if it still has the same PID, and if the PID has changed it would execute some commands.

You'd need to save the PID somewhere (jut a plain text file would suffice) so the next iteration of the script would know the old PID. If the PID changed it should then save the new PID.

The tool pgrep can be helpful in finding a process by name.

The monitoring tool monit https://packages.debian.org/jessie/monit can actually do this as well. It allows you to monitor, amongst other things, whether a daemon or service is still up and act accordingly. It will also notice changes in the PID. You can customise its behaviour when such events occur.

  • Sorry, but neither is pkill a good way to find a process name(that should be ps or pgrep) nor is waiting a few minutes okay. PID files are problematic if the service supports reload with takeover(read: 2 or more processes of the daemon with different PIDs are running after a service reload) This is also not really an answer to my question regarding whether there is a possibility to hook into the installation.
    – Izzy
    Sep 12, 2015 at 2:03
  • Not sure this is the right way to approach someone trying to help you. I provided some helpful tools. You can judge from my answer that I think there is no convenient way to do this. Which means I did answer your question "regarding whether there is a possibility to hook into the installation".
    – aseq
    Sep 12, 2015 at 3:01
  • Sorry if I came onto you in a rude way, but if the answer to my question would be "no", you should put that upfront, and maybe then explain alternatives. After all, this is a Q&A site for everybody ;)
    – Izzy
    Sep 14, 2015 at 8:39
  • No worries, and fair enough. I did consider it, but then somehow left it out.
    – aseq
    Sep 14, 2015 at 22:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .