]> git.donarmstrong.com Git - debhelper.git/blob - dh_installinit
Apply manual pages conventions
[debhelper.git] / dh_installinit
1 #!/usr/bin/perl -w
2
3 =head1 NAME
4
5 dh_installinit - install upstart jobs or init scripts into package build directories
6
7 =cut
8
9 use strict;
10 use Debian::Debhelper::Dh_Lib;
11
12 =head1 SYNOPSIS
13
14 B<dh_installinit> [S<I<debhelper options>>] [B<--name=>I<name>] [B<-n>] [B<-R>] [B<-r>] [B<-d>] [B<-O>] [S<B<--> I<params>>]
15
16 =head1 DESCRIPTION
17
18 B<dh_installinit> is a debhelper program that is responsible for installing
19 upstart job files or init scripts with associated defaults files into package
20 build directories, and in the former case providing compatibility handling
21 for non-upstart systems.
22
23 It also automatically generates the F<postinst> and F<postrm> and F<prerm> commands
24 needed to set up the symlinks in F</etc/rc*.d/> and to start and stop the init
25 scripts.
26
27 =head1 FILES
28
29 =over 4
30
31 =item debian/I<package>.upstart
32
33 If this exists, it is installed into etc/init/I<package>.conf in the package
34 build directory.
35
36 =item debian/I<package>.init
37
38 Otherwise, if this exists, it is installed
39 into etc/init.d/I<package> in the package build directory.
40
41 =item debian/I<package>.default
42
43 If this exists, it is installed into etc/default/I<package> in the package
44 build directory.
45
46 =back
47
48 =head1 OPTIONS
49
50 =over 4
51
52 =item B<-n>, B<--noscripts>
53
54 Do not modify F<postinst>/F<postrm>/F<prerm> scripts.
55
56 =item B<-o>, B<--onlyscripts>
57
58 Only modify F<postinst>/F<postrm>/F<prerm> scripts, do not actually install any init
59 script, default files, or upstart job. May be useful if the init script or
60 upstart job is shipped and/or installed by upstream in a way that doesn't
61 make it easy to let B<dh_installinit> find it.
62
63 If no upstart job file is installed in the target directory when
64 B<dh_installinit --onlyscripts> is called, this program will assume that an
65 init script is being installed and not provide the compatibility symlinks
66 or upstart dependencies.
67
68 =item B<-R>, B<--restart-after-upgrade>
69
70 Do not stop the init script until after the package upgrade has been
71 completed. This is different than the default behavior, which stops the
72 script in the F<prerm>, and starts it again in the F<postinst>.
73
74 This can be useful for daemons that should not have a possibly long
75 downtime during upgrade. But you should make sure that the daemon will not
76 get confused by the package being upgraded while it's running before using
77 this option.
78
79 =item B<-r>, B<--no-restart-on-upgrade>
80
81 Do not stop init script on upgrade.
82
83 =item B<--no-start>
84
85 Do not start the init script on install or upgrade, or stop it on removal.
86 Only call B<update-rc.d>. Useful for rcS scripts.
87
88 =item B<-d>, B<--remove-d>
89
90 Remove trailing B<d> from the name of the package, and use the result for the
91 filename the upstart job file is installed as in F<etc/init/> , or for the
92 filename the init script is installed as in etc/init.d and the default file
93 is installed as in F<etc/default/> . This may be useful for daemons with names
94 ending in B<d>. (Note: this takes precedence over the B<--init-script> parameter
95 described below.)
96
97 =item B<-u>I<params> B<--update-rcd-params=>I<params>
98
99 =item B<--> I<params>
100
101 Pass I<params> to L<update-rc.d(8)>. If not specified, B<defaults> will be
102 passed to L<update-rc.d(8)>.
103
104 =item B<--name=>I<name>
105
106 Install the upstart job file or the init script (and default file) using the
107 filename I<name> instead of the default filename, which is the package name.
108 When this parameter is used, B<dh_installinit> looks for and installs files
109 named F<debian/package.name.upstart>, F<debian/package.name.init> and
110 F<debian/package.name.default>, instead of the usual F<debian/package.upstart>,
111 F<debian/package.init> and F<debian/package.default>.
112
113 =item B<--init-script=>I<scriptname>
114
115 Use I<scriptname> as the filename the init script is installed as in
116 F<etc/init.d/> (and also use it as the filename for the defaults file, if it
117 is installed). If you use this parameter, B<dh_installinit> will look to see
118 if a file in the F<debian/> directory exists that looks like
119 F<package.scriptname> and if so will install it as the init script in
120 preference to the files it normally installs.
121
122 This parameter is deprecated, use the B<--name> parameter instead. This
123 parameter will be ignored completely for upstart jobs.
124
125 =item B<--error-handler=>I<function>
126
127 Call the named shell I<function> if running the init script fails. The
128 function should be provided in the F<prerm> and F<postinst> scripts, before the
129 B<#DEBHELPER#> token.
130
131 =back
132
133 =head1 NOTES
134
135 Note that this command is not idempotent. L<dh_prep(1)> should be called
136 between invocations of this command. Otherwise, it may cause multiple
137 instances of the same text to be added to maintainer scripts.
138
139 =cut
140
141 init(options => {
142         "r" => \$dh{R_FLAG},
143         "no-restart-on-upgrade" => \$dh{R_FLAG},
144         "no-start" => \$dh{NO_START},
145         "R|restart-after-upgrade" => \$dh{RESTART_AFTER_UPGRADE},
146         "init-script=s" => \$dh{INIT_SCRIPT},
147         "update-rcd-params=s", => \$dh{U_PARAMS},
148         "remove-d" => \$dh{D_FLAG},
149 });
150
151 foreach my $package (@{$dh{DOPACKAGES}}) {
152         my $tmp=tmpdir($package);
153
154         # Figure out what filename to install it as.
155         my $script;
156         my $jobfile=$package;
157         if (defined $dh{NAME}) {
158                 $jobfile=$script=$dh{NAME};
159         }
160         elsif ($dh{D_FLAG}) {
161                 # -d on the command line sets D_FLAG. We will 
162                 # remove a trailing 'd' from the package name and 
163                 # use that as the name.
164                 $script=$package;
165                 if ($script=~m/(.*)d$/) {
166                         $jobfile=$script=$1;
167                 }
168                 else {
169                         warning("\"$package\" has no final d' in its name, but -d was specified.");
170                 }
171         }       
172         elsif ($dh{INIT_SCRIPT}) {
173                 $script=$dh{INIT_SCRIPT};
174         }
175         else {
176                 $script=$package;
177         }       
178         
179         my $job=pkgfile($package,"upstart");
180         my $init='';
181
182         if ($job ne '' || ($dh{ONLYSCRIPTS} && -e "$tmp/etc/init/$jobfile.conf")) {
183                 if (! $dh{ONLYSCRIPTS}) {
184                         if (! -d "$tmp/etc/init") {
185                                 doit("install","-d","$tmp/etc/init");
186                         }
187                 
188                         doit("install","-p","-m644",$job,"$tmp/etc/init/$jobfile.conf");
189                 }
190                 
191                 # ensures that our /etc/init.d/ symlink points to a valid
192                 # implementation
193                 addsubstvar($package, "misc:Depends", "upstart-job");
194
195                 if (! -d "$tmp/etc/init.d") {
196                         doit("install","-d","$tmp/etc/init.d");
197                 }
198                 doit("ln","-sf","/lib/init/upstart-job","$tmp/etc/init.d/$jobfile");
199         }
200         else {
201                 $init=pkgfile($package,$script) || pkgfile($package,"init") ||
202                         pkgfile($package,"init.d");
203         }
204
205         my $default=pkgfile($package,'default');
206         if ($default ne '' && ! $dh{ONLYSCRIPTS}) {
207                 if (! -d "$tmp/etc/default") {
208                         doit("install","-d","$tmp/etc/default");
209                 }
210                 doit("install","-p","-m644",$default,"$tmp/etc/default/$script");
211         }
212
213         if ($init ne '' && ! $dh{ONLYSCRIPTS}) {
214                 if (! -d "$tmp/etc/init.d") {
215                         doit("install","-d","$tmp/etc/init.d");
216                 }
217                 
218                 doit("install","-p","-m755",$init,"$tmp/etc/init.d/$script");
219         }
220
221         if ($job ne '' || $init ne '' || $dh{ONLYSCRIPTS}) {
222                 if (-e "$tmp/etc/init/$jobfile.conf") {
223                         $script=$jobfile;
224                 }
225
226                 # This is set by the -u "foo" command line switch, it's
227                 # the parameters to pass to update-rc.d. If not set,
228                 # we have to say "defaults".
229                 my $params='';
230                 if (defined($dh{U_PARAMS})) {
231                         $params=join(' ',@{$dh{U_PARAMS}});
232                 }       
233                 if ($params eq '') {
234                         $params="defaults";
235                 }
236                 
237                 if (! $dh{NOSCRIPTS}) {
238                         if (! $dh{NO_START}) {
239                                 if ($dh{RESTART_AFTER_UPGRADE}) {
240                                         # update-rc.d, and restart (or
241                                         # start if new install) script
242                                         autoscript($package,"postinst", "postinst-init-restart",
243                                                 "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/;s/#ERROR_HANDLER#/$dh{ERROR_HANDLER}/");
244                                 }
245                                 else {
246                                         # update-rc.d, and start script
247                                         autoscript($package,"postinst", "postinst-init",
248                                                 "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/;s/#ERROR_HANDLER#/$dh{ERROR_HANDLER}/");
249                                 }
250                         
251                                 if ($dh{R_FLAG} || $dh{RESTART_AFTER_UPGRADE}) {
252                                         # stops script only on remove
253                                         autoscript($package,"prerm","prerm-init-norestart",
254                                                 "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/;s/#ERROR_HANDLER#/$dh{ERROR_HANDLER}/");
255                                 }
256                                 else {
257                                         # always stops script
258                                         autoscript($package,"prerm","prerm-init",
259                                                 "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/;s/#ERROR_HANDLER#/$dh{ERROR_HANDLER}/");
260                                 }
261                         }
262                         else {
263                                 # just update-rc.d
264                                 autoscript($package,"postinst", "postinst-init-nostart",
265                                         "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/;s/#ERROR_HANDLER#/$dh{ERROR_HANDLER}/");
266                         }
267
268                         # removes rc.d links
269                         autoscript($package,"postrm","postrm-init",
270                                 "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/;s/#ERROR_HANDLER#/$dh{ERROR_HANDLER}/");
271                 }
272         }
273 }
274
275 =head1 SEE ALSO
276
277 L<debhelper(7)>
278
279 This program is a part of debhelper.
280
281 =head1 AUTHORS
282
283 Joey Hess <joeyh@debian.org>
284
285 Steve Langasek <steve.langasek@canonical.com>
286
287 =cut