]> git.donarmstrong.com Git - debhelper.git/blob - dh_installinit
Updated French man page translation. Closes: #685560
[debhelper.git] / dh_installinit
1 #!/usr/bin/perl -w
2
3 =head1 NAME
4
5 dh_installinit - install init scripts and/or upstart jobs 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>] [S<B<--> I<params>>]
15
16 =head1 DESCRIPTION
17
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.
21
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
24 the init scripts.
25
26 =head1 FILES
27
28 =over 4
29
30 =item debian/I<package>.init
31
32 If this exists, it is installed into etc/init.d/I<package> in the package
33 build directory.
34
35 =item debian/I<package>.default
36
37 If this exists, it is installed into etc/default/I<package> in the package
38 build directory.
39
40 =item debian/I<package>.upstart
41
42 If this exists, it is installed into etc/init/I<package>.conf in the package
43 build directory.
44
45 =back
46
47 =head1 OPTIONS
48
49 =over 4
50
51 =item B<-n>, B<--noscripts>
52
53 Do not modify F<postinst>/F<postrm>/F<prerm> scripts.
54
55 =item B<-o>, B<--onlyscripts>
56
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.
61
62 =item B<-R>, B<--restart-after-upgrade>
63
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>.
67
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
71 this option.
72
73 =item B<-r>, B<--no-restart-on-upgrade>
74
75 Do not stop init script on upgrade.
76
77 =item B<--no-start>
78
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.
81
82 =item B<-d>, B<--remove-d>
83
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
89 described below.)
90
91 =item B<-u>I<params> B<--update-rcd-params=>I<params>
92
93 =item B<--> I<params>
94
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)>.
97
98 =item B<--name=>I<name>
99
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>.
107
108 =item B<--init-script=>I<scriptname>
109
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.
116
117 This parameter is deprecated, use the B<--name> parameter instead. This
118 parameter is incompatible with the use of upstart jobs.
119
120 =item B<--error-handler=>I<function>
121
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.
125
126 =back
127
128 =head1 NOTES
129
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.
133
134 =cut
135
136 init(options => {
137         "r" => \$dh{R_FLAG},
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},
144 });
145
146 foreach my $package (@{$dh{DOPACKAGES}}) {
147         my $tmp=tmpdir($package);
148
149         # Figure out what filename to install it as.
150         my $script;
151         my $jobfile=$package;
152         if (defined $dh{NAME}) {
153                 $jobfile=$script=$dh{NAME};
154         }
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.
159                 $script=$package;
160                 if ($script=~m/(.*)d$/) {
161                         $jobfile=$script=$1;
162                 }
163                 else {
164                         warning("\"$package\" has no final d' in its name, but -d was specified.");
165                 }
166         }       
167         elsif ($dh{INIT_SCRIPT}) {
168                 $script=$dh{INIT_SCRIPT};
169         }
170         else {
171                 $script=$package;
172         }       
173
174         my $job=pkgfile($package,"upstart");
175
176         if ($job ne '' && ! $dh{ONLYSCRIPTS}) {
177                 if (! -d "$tmp/etc/init") {
178                         doit("install","-d","$tmp/etc/init");
179                 }
180                 
181                 doit("install","-p","-m644",$job,"$tmp/etc/init/$jobfile.conf");
182         }
183
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");
188                 }
189                 doit("install","-p","-m644",$default,"$tmp/etc/default/$script");
190         }
191
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");
197                 }
198                 
199                 doit("install","-p","-m755",$init,"$tmp/etc/init.d/$script");
200         }
201
202         if ($dh{INIT_SCRIPT} && $job ne '' && $init ne '') {
203                 error("Can't use --init-script with an upstart job");
204         }
205
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".
210                 my $params='';
211                 if (defined($dh{U_PARAMS})) {
212                         $params=join(' ',@{$dh{U_PARAMS}});
213                 }       
214                 if ($params eq '') {
215                         $params="defaults";
216                 }
217                 
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}/");
225                                 }
226                                 else {
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}/");
230                                 }
231                         
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}/");
236                                 }
237                                 else {
238                                         # always stops script
239                                         autoscript($package,"prerm","prerm-init",
240                                                 "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/;s/#ERROR_HANDLER#/$dh{ERROR_HANDLER}/");
241                                 }
242                         }
243                         else {
244                                 # just update-rc.d
245                                 autoscript($package,"postinst", "postinst-init-nostart",
246                                         "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/;s/#ERROR_HANDLER#/$dh{ERROR_HANDLER}/");
247                         }
248
249                         # removes rc.d links
250                         autoscript($package,"postrm","postrm-init",
251                                 "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/;s/#ERROR_HANDLER#/$dh{ERROR_HANDLER}/");
252                 }
253         }
254 }
255
256 =head1 SEE ALSO
257
258 L<debhelper(7)>
259
260 This program is a part of debhelper.
261
262 =head1 AUTHORS
263
264 Joey Hess <joeyh@debian.org>
265
266 Steve Langasek <steve.langasek@canonical.com>
267
268 =cut