5 dh_installinit - install init scripts into package build directories
10 use Debian::Debhelper::Dh_Lib;
14 B<dh_installinit> [S<I<debhelper options>>] [B<--init-script=>I<scriptname>] [B<-n>] [B<-r>] [B<-d>] [S<B<--> I<params>>]
18 dh_installinit is a debhelper program that is responsible for installing
19 init scripts and associated defaults files into package build directories.
21 It also automatically generates the postinst and postrm and prerm commands
22 needed to set up the symlinks in /etc/rc*.d/ and to start and stop the init
25 If a file named debian/package.init exists, then it is installed into
26 etc/init.d/package in the package build directory, with "package" replaced
29 If a file named debian/package.default exists, then it is installed into
30 etc/default/package in the package build directory, with "package" replaced
33 Historically this program generates postrm and prerm commands that run the
34 init scripts by hand. In V4 mode, it uses the invoke-rc.d program instead.
35 See L<debhelper(1)> for details about V4 mode. If you decide to use this, you
36 should make your package depend on sysvinit (>= 2.80-1) (this dependency is
37 added to ${misc:Depends} by this program in V4 mode).
43 =item B<-n>, B<--noscripts>
45 Do not modify postinst/postrm/prerm scripts.
47 =item B<-r>, B<--no-restart-on-upgrade>
49 Do not restart daemon on upgrade.
51 =item B<-d>, B<--remove-d>
53 Remove trailing "d" from the name of the package, and use the result for the
54 filename the init script is installed as in etc/init.d/ , and the default file
55 is installed as in etc/default/ . This may be useful for daemons with names
56 ending in "d". (Note: this takes precedence over the --init-script parameter
59 =item B<-u>I<params> B<--update-rcd-params=>I<params>
63 Pass "params" to L<update-rc.d(8)>. If not specified, "defaults" will be
64 passed to L<update-rc.d(8)>.
66 =item B<--init-script=>I<scriptname>
68 Use "scriptname" as for the filename the init script is installed as in
69 etc/init.d/ (and also use it as the filename for the defaults file, if it
70 is installed). This is useful if you need to have an init script with a name
71 different from the package's name. Note that if you use this parameter,
72 dh_installinit will look to see if a file in the debian/ directory exists
73 that looks like "package.scriptname" and if so will install it as the init
74 script in preference to the files it normally installs. This feature is really
75 only useful if you need a single package to install more than one init script.
81 Note that this command is not idempotent. "dh_clean -k" should be called
82 between invocations of this command. Otherwise, it may cause multiple
83 instances of the same text to be added to maintainer scripts.
89 foreach my $package (@{$dh{DOPACKAGES}}) {
90 my $tmp=tmpdir($package);
92 # Figure out what filename to install it as.
95 # -d on the command line sets D_FLAG. We will
96 # remove a trailing 'd' from the package name and
97 # use that as the name.
99 if ($script=~m/(.*)d$/) {
103 warning("\"$package\" has no final d' in its name, but -d was specified.");
106 elsif ($dh{INIT_SCRIPT}) {
107 $script=$dh{INIT_SCRIPT};
113 my $init=pkgfile($package,$script) || pkgfile($package,"init") ||
114 pkgfile($package,"init.d");
115 my $default=pkgfile($package,'default');
117 if ($default ne '') {
118 if (! -d "$tmp/etc/default") {
119 doit("install","-d","$tmp/etc/default");
121 doit("install","-p","-m644",$default,"$tmp/etc/default/$script");
125 if (! -d "$tmp/etc/init.d") {
126 doit("install","-d","$tmp/etc/init.d");
129 doit("install","-p","-m755",$init,"$tmp/etc/init.d/$script");
131 # This is set by the -u "foo" command line switch, it's
132 # the parameters to pass to update-rc.d. If not set,
133 # we have to say "defaults".
135 if (defined($dh{U_PARAMS})) {
136 $params=join(' ',@{$dh{U_PARAMS}});
143 if (! $dh{NOSCRIPTS}) {
144 # In v4 mode, use invoke-rc.d versions of the
145 # autoscripts; prior to that use the old,
146 # manual-invoking versions.
150 addsubstvar($package, "misc:Depends", "sysvinit", ">= 2.80-1");
153 # -r on the command line sets R_FLAG. If it's set,
154 # there is no restart on upgrade.
156 autoscript($package,"postinst", "postinst-init-norestart$tailstr",
157 "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/");
158 autoscript($package,"prerm","prerm-init-norestart$tailstr",
159 "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/");
162 autoscript($package,"postinst","postinst-init$tailstr",
163 "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/");
164 autoscript($package,"prerm","prerm-init$tailstr",
165 "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/");
167 # This script just removes the links, so it's the
168 # same for all varients.
169 autoscript($package,"postrm","postrm-init",
170 "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/");
173 if (! $substvaradded) {
174 # Remove it, for idemotency's sake.
175 addsubstvar($package, "misc:Depends", "sysvinit", ">= 2.80-1", 1);
184 This program is a part of debhelper.
188 Joey Hess <joeyh@debian.org>