5 dh_installinit - install init scripts and/or upstart jobs into package build directories
10 use Debian::Debhelper::Dh_Lib;
14 B<dh_installinit> [S<I<debhelper options>>] [B<--name=>I<name>] [B<-n>] [B<-R>] [B<-r>] [B<-d>] [S<B<--> I<params>>]
18 B<dh_installinit> is a debhelper program that is responsible for installing
19 init scripts with associated defaults files, as well as upstart job files
20 into package build directories.
22 It also automatically generates the F<postinst> and F<postrm> and F<prerm>
23 commands needed to set up the symlinks in F</etc/rc*.d/> to start and stop
30 =item debian/I<package>.init
32 If this exists, it is installed into etc/init.d/I<package> in the package
35 =item debian/I<package>.default
37 If this exists, it is installed into etc/default/I<package> in the package
40 =item debian/I<package>.upstart
42 If this exists, it is installed into etc/init/I<package>.conf in the package
51 =item B<-n>, B<--noscripts>
53 Do not modify F<postinst>/F<postrm>/F<prerm> scripts.
55 =item B<-o>, B<--onlyscripts>
57 Only modify F<postinst>/F<postrm>/F<prerm> scripts, do not actually install any init
58 script, default files, or upstart job. May be useful if the init script or
59 upstart job is shipped and/or installed by upstream in a way that doesn't
60 make it easy to let B<dh_installinit> find it.
62 =item B<-R>, B<--restart-after-upgrade>
64 Do not stop the init script until after the package upgrade has been
65 completed. This is different than the default behavior, which stops the
66 script in the F<prerm>, and starts it again in the F<postinst>.
68 This can be useful for daemons that should not have a possibly long
69 downtime during upgrade. But you should make sure that the daemon will not
70 get confused by the package being upgraded while it's running before using
73 =item B<-r>, B<--no-restart-on-upgrade>
75 Do not stop init script on upgrade.
79 Do not start the init script on install or upgrade, or stop it on removal.
80 Only call B<update-rc.d>. Useful for rcS scripts.
82 =item B<-d>, B<--remove-d>
84 Remove trailing B<d> from the name of the package, and use the result for the
85 filename the upstart job file is installed as in F<etc/init/> , and for the
86 filename the init script is installed as in etc/init.d and the default file
87 is installed as in F<etc/default/> . This may be useful for daemons with names
88 ending in B<d>. (Note: this takes precedence over the B<--init-script> parameter
91 =item B<-u>I<params> B<--update-rcd-params=>I<params>
95 Pass I<params> to L<update-rc.d(8)>. If not specified, B<defaults> will be
96 passed to L<update-rc.d(8)>.
98 =item B<--name=>I<name>
100 Install the init script (and default file) as well as upstart job file
101 using the filename I<name> instead of the default filename, which is
102 the package name. When this parameter is used, B<dh_installinit> looks
103 for and installs files named F<debian/package.name.init>,
104 F<debian/package.name.default> and F<debian/package.name.upstart>
105 instead of the usual F<debian/package.init>, F<debian/package.default> and
106 F<debian/package.upstart>.
108 =item B<--init-script=>I<scriptname>
110 Use I<scriptname> as the filename the init script is installed as in
111 F<etc/init.d/> (and also use it as the filename for the defaults file, if it
112 is installed). If you use this parameter, B<dh_installinit> will look to see
113 if a file in the F<debian/> directory exists that looks like
114 F<package.scriptname> and if so will install it as the init script in
115 preference to the files it normally installs.
117 This parameter is deprecated, use the B<--name> parameter instead. This
118 parameter is incompatible with the use of upstart jobs.
120 =item B<--error-handler=>I<function>
122 Call the named shell I<function> if running the init script fails. The
123 function should be provided in the F<prerm> and F<postinst> scripts, before the
124 B<#DEBHELPER#> token.
130 Note that this command is not idempotent. L<dh_prep(1)> should be called
131 between invocations of this command. Otherwise, it may cause multiple
132 instances of the same text to be added to maintainer scripts.
138 "no-restart-on-upgrade" => \$dh{R_FLAG},
139 "no-start" => \$dh{NO_START},
140 "R|restart-after-upgrade" => \$dh{RESTART_AFTER_UPGRADE},
141 "init-script=s" => \$dh{INIT_SCRIPT},
142 "update-rcd-params=s", => \$dh{U_PARAMS},
143 "remove-d" => \$dh{D_FLAG},
146 foreach my $package (@{$dh{DOPACKAGES}}) {
147 my $tmp=tmpdir($package);
149 # Figure out what filename to install it as.
151 my $jobfile=$package;
152 if (defined $dh{NAME}) {
153 $jobfile=$script=$dh{NAME};
155 elsif ($dh{D_FLAG}) {
156 # -d on the command line sets D_FLAG. We will
157 # remove a trailing 'd' from the package name and
158 # use that as the name.
160 if ($script=~m/(.*)d$/) {
164 warning("\"$package\" has no final d' in its name, but -d was specified.");
167 elsif ($dh{INIT_SCRIPT}) {
168 $script=$dh{INIT_SCRIPT};
174 my $job=pkgfile($package,"upstart");
176 if ($job ne '' && ! $dh{ONLYSCRIPTS}) {
177 if (! -d "$tmp/etc/init") {
178 doit("install","-d","$tmp/etc/init");
181 doit("install","-p","-m644",$job,"$tmp/etc/init/$jobfile.conf");
184 my $default=pkgfile($package,'default');
185 if ($default ne '' && ! $dh{ONLYSCRIPTS}) {
186 if (! -d "$tmp/etc/default") {
187 doit("install","-d","$tmp/etc/default");
189 doit("install","-p","-m644",$default,"$tmp/etc/default/$script");
192 my $init=pkgfile($package,$script) || pkgfile($package,"init") ||
193 pkgfile($package,"init.d");
194 if ($init ne '' && ! $dh{ONLYSCRIPTS}) {
195 if (! -d "$tmp/etc/init.d") {
196 doit("install","-d","$tmp/etc/init.d");
199 doit("install","-p","-m755",$init,"$tmp/etc/init.d/$script");
202 if ($dh{INIT_SCRIPT} && $job ne '' && $init ne '') {
203 error("Can't use --init-script with an upstart job");
206 if ($job ne '' || $init ne '' || $dh{ONLYSCRIPTS}) {
207 # This is set by the -u "foo" command line switch, it's
208 # the parameters to pass to update-rc.d. If not set,
209 # we have to say "defaults".
211 if (defined($dh{U_PARAMS})) {
212 $params=join(' ',@{$dh{U_PARAMS}});
218 if (! $dh{NOSCRIPTS}) {
219 if (! $dh{NO_START}) {
220 if ($dh{RESTART_AFTER_UPGRADE}) {
221 # update-rc.d, and restart (or
222 # start if new install) script
223 autoscript($package,"postinst", "postinst-init-restart",
224 "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/;s/#ERROR_HANDLER#/$dh{ERROR_HANDLER}/");
227 # update-rc.d, and start script
228 autoscript($package,"postinst", "postinst-init",
229 "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/;s/#ERROR_HANDLER#/$dh{ERROR_HANDLER}/");
232 if ($dh{R_FLAG} || $dh{RESTART_AFTER_UPGRADE}) {
233 # stops script only on remove
234 autoscript($package,"prerm","prerm-init-norestart",
235 "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/;s/#ERROR_HANDLER#/$dh{ERROR_HANDLER}/");
238 # always stops script
239 autoscript($package,"prerm","prerm-init",
240 "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/;s/#ERROR_HANDLER#/$dh{ERROR_HANDLER}/");
245 autoscript($package,"postinst", "postinst-init-nostart",
246 "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/;s/#ERROR_HANDLER#/$dh{ERROR_HANDLER}/");
250 autoscript($package,"postrm","postrm-init",
251 "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/;s/#ERROR_HANDLER#/$dh{ERROR_HANDLER}/");
260 This program is a part of debhelper.
264 Joey Hess <joeyh@debian.org>
266 Steve Langasek <steve.langasek@canonical.com>