]> git.donarmstrong.com Git - debhelper.git/blob - dh_installinit
r542: * dh_installinit: Always start daemon on upgraded even if
[debhelper.git] / dh_installinit
1 #!/usr/bin/perl -w
2
3 =head1 NAME
4
5 dh_installinit - install 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<--init-script=>I<scriptname>] [B<-n>] [B<-r>] [B<-d>] [S<B<--> I<params>>]
15
16 =head1 DESCRIPTION
17
18 dh_installinit is a debhelper program that is responsible for installing
19 init scripts and associated defaults files into package build directories.
20
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
23 scripts.
24
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
27 by the package name.
28
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
31 by the package name.
32
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).
38
39 =head1 OPTIONS
40
41 =over 4
42
43 =item B<-n>, B<--noscripts>
44
45 Do not modify postinst/postrm/prerm scripts.
46
47 =item B<-r>, B<--no-restart-on-upgrade>
48
49 Do not restart daemon on upgrade.
50
51 =item B<-d>, B<--remove-d>
52
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
57 described below.)
58
59 =item B<-u>I<params> B<--update-rcd-params=>I<params>
60
61 =item B<--> I<params>
62
63 Pass "params" to L<update-rc.d(8)>. If not specified, "defaults" will be
64 passed to L<update-rc.d(8)>.
65
66 =item B<--init-script=>I<scriptname>
67
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.
76
77 =back
78
79 =head1 NOTES
80
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.
84
85 =cut
86
87 init();
88
89 foreach my $package (@{$dh{DOPACKAGES}}) {
90         my $tmp=tmpdir($package);
91
92         # Figure out what filename to install it as.
93         my $script;
94         if ($dh{D_FLAG}) {
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.
98                 $script=$package;
99                 if ($script=~m/(.*)d$/) {
100                         $script=$1;
101                 }
102                 else {
103                         warning("\"$package\" has no final d' in its name, but -d was specified.");
104                 }
105         }       
106         elsif ($dh{INIT_SCRIPT}) {
107                 $script=$dh{INIT_SCRIPT};
108         }
109         else {
110                 $script=$package;
111         }       
112
113         my $init=pkgfile($package,$script) || pkgfile($package,"init") ||
114               pkgfile($package,"init.d");
115         my $default=pkgfile($package,'default');
116
117         if ($default ne '') {
118                 if (! -d "$tmp/etc/default") {
119                         doit("install","-d","$tmp/etc/default");
120                 }
121                 doit("install","-p","-m644",$default,"$tmp/etc/default/$script");
122         }
123
124         if ($init ne '') {
125                 if (! -d "$tmp/etc/init.d") {
126                         doit("install","-d","$tmp/etc/init.d");
127                 }
128
129                 doit("install","-p","-m755",$init,"$tmp/etc/init.d/$script");
130
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".
134                 my $params='';
135                 if (defined($dh{U_PARAMS})) {
136                         $params=join(' ',@{$dh{U_PARAMS}});
137                 }       
138                 if ($params eq '') {
139                         $params="defaults";
140                 }
141
142                 my $substvaradded=0;
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.
147                         my $tailstr="";
148                         if (! compat(3)) {
149                                 $tailstr="-invoke";
150                                 addsubstvar($package, "misc:Depends", "sysvinit", ">= 2.80-1");
151                                 $substvaradded=1;
152                         }
153                         autoscript($package,"postinst", "postinst-init$tailstr",
154                                 "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/");
155                         # -r on the command line sets R_FLAG. If it's set,
156                         # there  is no restart on upgrade, so don't stop
157                         # daemon. (It's ok that it's always started.)
158                         if ($dh{R_FLAG}) {
159                                 autoscript($package,"prerm","prerm-init-norestart$tailstr",
160                                         "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/");
161                         }
162                         else {
163                                 autoscript($package,"prerm","prerm-init$tailstr",
164                                         "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/");
165                         }
166                         # This script just removes the links, so it's the
167                         # same for all varients.
168                         autoscript($package,"postrm","postrm-init",
169                                 "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/");
170                 }
171
172                 if (! $substvaradded) {
173                         # Remove it, for idemotency's sake.
174                         addsubstvar($package, "misc:Depends", "sysvinit", ">= 2.80-1", 1);
175                 }
176         }
177 }
178
179 =head1 SEE ALSO
180
181 L<debhelper(1)>
182
183 This program is a part of debhelper.
184
185 =head1 AUTHOR
186
187 Joey Hess <joeyh@debian.org>
188
189 =cut