7

I have a project.init file in the debian directory (along with rules, control, etc), and I have dh_installinit in my rules file (in the binary-arch rule).

When dpkg-buildpackage completes, the init script has been copied to debian/project/etc/init.d/project, and the various pre/post scripts have been created.

However, when I actually install the .deb (with dpkg -i), the init.d script does not get installed, so I must be missing part of this process. The "New Maintainer's Guide" is pretty sparse on init.d details (it basically says not to use them, because they are too advanced).

The verbose output of the dh_installinit command is:

dh_installinit
    install -p -m755 debian/project.init debian/project/etc/init.d/project
    echo "# Automatically added by dh_installinit">> debian/project.postinst.debhelper
    sed "s/#SCRIPT#/project/;s/#INITPARMS#/defaults/;s/#ERROR_HANDLER#/exit \$?/" /usr/share/debhelper/autoscripts/postinst-init >> debian/project.postinst.debhelper
    echo '# End automatically added section' >> debian/project.postinst.debhelper
    echo "# Automatically added by dh_installinit">> debian/project.prerm.debhelper
    sed "s/#SCRIPT#/project/;s/#INITPARMS#/defaults/;s/#ERROR_HANDLER#/exit \$?/" /usr/share/debhelper/autoscripts/prerm-init >> debian/project.prerm.debhelper
    echo '# End automatically added section' >> debian/project.prerm.debhelper
    echo "# Automatically added by dh_installinit">> debian/project.postrm.debhelper
    sed "s/#SCRIPT#/project/;s/#INITPARMS#/defaults/;s/#ERROR_HANDLER#/exit \$?/" /usr/share/debhelper/autoscripts/postrm-init >> debian/project.postrm.debhelper
    echo '# End automatically added section' >> debian/project.postrm.debhelper
Mikel
  • 24,855
  • 8
  • 65
  • 66
Tony Meyer
  • 10,079
  • 6
  • 41
  • 47
  • 2
    What exactly do you mean by "does not get installed"? It doesn't exist in the deb, it's not installed into /etc/init.d or no start/stop links are created? – Torsten Marek May 28 '09 at 23:33
  • I'm not sure how to test whether it is in the .deb or not. It doesn't appear in /etc/init.d (and so obviously the start/stop links aren't created). – Tony Meyer Jun 01 '09 at 01:52
  • I was having a very similar problem, where a upstart script was being included in the package (you could even see it when listed with dpkg -c), but it wouldn't install. I eventually tried to changing the compat version (it using 7 and I switched it to 8) and then it installed just fine. – John Bowers Apr 19 '13 at 21:17

5 Answers5

8

Does your package have an entry for your init script under the Conffiles block in /var/lib/dpkg/status, e.g.

Package: <project>
...
Conffiles:
 /etc/init.d/<project> d41d8cd98f00b204e9800998ecf8427e

and does /var/lib/dpkg/info/<project>.conffiles contain /etc/init.d/<project>?

Here's what's happening...

init scripts are marked as configuration files by default, since they live under /etc.1

I'm guessing you installed the package, removed the init file, then reinstalled the package.

In this case, removing the init file counts as modifying it2, and dpkg refuses to "overwrite" the "configuration file".

You should be able to fix the problem by removing the Conffiles section from /var/lib/dpkg/status.

Notes:

  1. conffiles - Debian New Maintainer's Guide
  2. An empty file has MD5sum d41d8cd98f00b204e9800998ecf8427e, but any non-matching checksum will cause the same behavior
Mikel
  • 24,855
  • 8
  • 65
  • 66
  • 2
    Instead of remove the conffiles entries (and change an expected behavior), maybe it's better ask the `apt` to force the install of the conffiles: `sudo apt-get -o Dpkg::Options::="--force-confmiss" install --reinstall ` – Rael Gugelmin Cunha May 22 '14 at 14:49
  • I installed a custom package using dpkg-scanpackges and apt-get update/install (with --force-confnew flag). Then I uninstalled it using apt-get remove. Then I deleted my config/log files left over after. Then I re-installed the package in the same way, but the config files were not installed at all. Removing the Conffiles section fixed my problem too, thanks! – wrapperapps Apr 07 '15 at 18:35
  • 1
    I also used "--force-confmiss" additionally in order to resolve a similar but separate issue with my init script not being installed after deleting it, as suggested by @RaelGugelminCunha – wrapperapps Sep 07 '16 at 14:10
2

I believe you should be looking at the utility script "update-rc.d" which takes care of creating / removing symlinks in /etc/init.d/ .

Use this script in the DEBIAN control files "postinst" & "postrm".

E.g. for 'postinst': update-rc.d mswitch start 20 2 3 4 5 . stop 0 1 6 .

E.g. for 'postrm': update-rc.d mswitch remove

jldupont
  • 93,734
  • 56
  • 203
  • 318
  • 1
    I wasn't the downvoter, but they probably downvoted this because it's not the right answer, and it's not generally good packaging advice. The `dh_installinit` tool will take care of inserting the right `update-rc.d` calls in postinst and postrm, including making sure the maintainer scripts are being called during the appropriate state transitions. – the paul Oct 11 '12 at 04:33
  • Thanks for the note, "the paul". Note that this procedure worked for me but I take good note there is a better way. – jldupont Oct 11 '12 at 15:40
1

At this point I would check the content of the .deb file that is created. You can use dpkg-deb -c for that purpose.

If the init script is in the .deb, it should get installed in /etc/init.d, just like this:

...
drwxr-xr-x root/root         0 2009-06-03 14:01 ./etc/
drwxr-xr-x root/root         0 2009-06-03 14:01 ./etc/init.d/
-rwxr-xr-x root/root      2558 2009-02-13 11:27 ./etc/init.d/balance
...

If your run a recent version of Debian, the content of your package may be generate from debian/tmp instead of debian/project as you seem to expect. You can move the files from debian/projet to debian/tmp using dh_install.

  • Good theory, but in my case `dpkg-deb -c` shows the file is present in the `.deb`. – Mikel Sep 19 '12 at 21:13
  • so does the init-script show-up when you extract the package? something like `mkdir /tmp/foo; dpkg -x packge.deb /tmp/foo; ls -l /tmp/foo/etc/init.d` – umläute Sep 26 '12 at 09:19
0

I had success, when i only put the project.init file into debian-folder and do not add any special constraints to the rules-file. After this step is working, test to add you're special constraints.

To control the success in debian-folder cat *.postinst.debhelper contains:

# Automatically added by dh_installinit
if [ -x "/etc/init.d/<packagename>" ]; then
    if [ ! -e "/etc/init/<packagename>.conf" ]; then
        update-rc.d <packagename> defaults >/dev/null
    fi
    invoke-rc.d <packagename> start || exit $?
fi
imizeropt
  • 176
  • 1
  • 13
0

Just a guess, are you using a -P option to other dh_* scripts but not this one? If you use that option, you need to use it on all the dh_* scripts.

Mark Baker
  • 5,588
  • 2
  • 27
  • 25