5 dh_installinit - install upstart jobs and/or init scripts 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 upstart job files and init scripts with associated defaults files into
20 package build directories.
22 It also automatically generates the F<postinst> and F<postrm> and F<prerm> commands
23 needed to set up the symlinks in F</etc/rc*.d/> to start and stop the init
30 =item debian/I<package>.upstart
32 If this exists, it is installed into etc/init/I<package>.conf in the package
35 =item debian/I<package>.init
37 If this exists, it is installed into etc/init.d/I<package> in the package
40 =item debian/I<package>.default
42 If this exists, it is installed into etc/default/I<package> 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 upstart job file and init script (and default file) using the
101 filename I<name> instead of the default filename, which is the package name.
102 When this parameter is used, B<dh_installinit> looks for and installs files
103 named F<debian/package.name.upstart>, F<debian/package.name.init> and
104 F<debian/package.name.default>, instead of the usual F<debian/package.upstart>,
105 F<debian/package.init> and F<debian/package.default>.
107 =item B<--init-script=>I<scriptname>
109 Use I<scriptname> as the filename the init script is installed as in
110 F<etc/init.d/> (and also use it as the filename for the defaults file, if it
111 is installed). If you use this parameter, B<dh_installinit> will look to see
112 if a file in the F<debian/> directory exists that looks like
113 F<package.scriptname> and if so will install it as the init script in
114 preference to the files it normally installs.
116 This parameter is deprecated, use the B<--name> parameter instead. This
117 parameter is incompatible with the use of upstart jobs.
119 =item B<--error-handler=>I<function>
121 Call the named shell I<function> if running the init script fails. The
122 function should be provided in the F<prerm> and F<postinst> scripts, before the
123 B<#DEBHELPER#> token.
129 Note that this command is not idempotent. L<dh_prep(1)> should be called
130 between invocations of this command. Otherwise, it may cause multiple
131 instances of the same text to be added to maintainer scripts.
137 "no-restart-on-upgrade" => \$dh{R_FLAG},
138 "no-start" => \$dh{NO_START},
139 "R|restart-after-upgrade" => \$dh{RESTART_AFTER_UPGRADE},
140 "init-script=s" => \$dh{INIT_SCRIPT},
141 "update-rcd-params=s", => \$dh{U_PARAMS},
142 "remove-d" => \$dh{D_FLAG},
145 foreach my $package (@{$dh{DOPACKAGES}}) {
146 my $tmp=tmpdir($package);
148 # Figure out what filename to install it as.
150 my $jobfile=$package;
151 if (defined $dh{NAME}) {
152 $jobfile=$script=$dh{NAME};
154 elsif ($dh{D_FLAG}) {
155 # -d on the command line sets D_FLAG. We will
156 # remove a trailing 'd' from the package name and
157 # use that as the name.
159 if ($script=~m/(.*)d$/) {
163 warning("\"$package\" has no final d' in its name, but -d was specified.");
166 elsif ($dh{INIT_SCRIPT}) {
167 $script=$dh{INIT_SCRIPT};
173 my $job=pkgfile($package,"upstart");
175 if ($job ne '' && ! $dh{ONLYSCRIPTS}) {
176 if (! -d "$tmp/etc/init") {
177 doit("install","-d","$tmp/etc/init");
180 doit("install","-p","-m644",$job,"$tmp/etc/init/$jobfile.conf");
183 my $default=pkgfile($package,'default');
184 if ($default ne '' && ! $dh{ONLYSCRIPTS}) {
185 if (! -d "$tmp/etc/default") {
186 doit("install","-d","$tmp/etc/default");
188 doit("install","-p","-m644",$default,"$tmp/etc/default/$script");
191 my $init=pkgfile($package,$script) || pkgfile($package,"init") ||
192 pkgfile($package,"init.d");
193 if ($init ne '' && ! $dh{ONLYSCRIPTS}) {
194 if (! -d "$tmp/etc/init.d") {
195 doit("install","-d","$tmp/etc/init.d");
198 doit("install","-p","-m755",$init,"$tmp/etc/init.d/$script");
201 if ($dh{INIT_SCRIPT} && $job ne '' && $init ne '') {
202 error("Can't use --init-script with an upstart job");
205 if ($job ne '' || $init ne '' || $dh{ONLYSCRIPTS}) {
206 # This is set by the -u "foo" command line switch, it's
207 # the parameters to pass to update-rc.d. If not set,
208 # we have to say "defaults".
210 if (defined($dh{U_PARAMS})) {
211 $params=join(' ',@{$dh{U_PARAMS}});
217 if (! $dh{NOSCRIPTS}) {
218 if (! $dh{NO_START}) {
219 if ($dh{RESTART_AFTER_UPGRADE}) {
220 # update-rc.d, and restart (or
221 # start if new install) script
222 autoscript($package,"postinst", "postinst-init-restart",
223 "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/;s/#ERROR_HANDLER#/$dh{ERROR_HANDLER}/");
226 # update-rc.d, and start script
227 autoscript($package,"postinst", "postinst-init",
228 "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/;s/#ERROR_HANDLER#/$dh{ERROR_HANDLER}/");
231 if ($dh{R_FLAG} || $dh{RESTART_AFTER_UPGRADE}) {
232 # stops script only on remove
233 autoscript($package,"prerm","prerm-init-norestart",
234 "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/;s/#ERROR_HANDLER#/$dh{ERROR_HANDLER}/");
237 # always stops script
238 autoscript($package,"prerm","prerm-init",
239 "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/;s/#ERROR_HANDLER#/$dh{ERROR_HANDLER}/");
244 autoscript($package,"postinst", "postinst-init-nostart",
245 "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/;s/#ERROR_HANDLER#/$dh{ERROR_HANDLER}/");
249 autoscript($package,"postrm","postrm-init",
250 "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/;s/#ERROR_HANDLER#/$dh{ERROR_HANDLER}/");
259 This program is a part of debhelper.
263 Joey Hess <joeyh@debian.org>
265 Steve Langasek <steve.langasek@canonical.com>