5 dh_installinit - install 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<-d>] [S<B<--> I<params>>]
18 dh_installinit is a debhelper program that is responsible for installing
19 init scripts and associated defaults files into package build directories.
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
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
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
37 =item B<-n>, B<--noscripts>
39 Do not modify postinst/postrm/prerm scripts.
41 =item B<-r>, B<--no-restart-on-upgrade>
43 Do not restart init script on upgrade.
47 Do not start the init script on install or upgrade, or stop it on removal.
48 Only call update-rc.d. Useful for rcS scripts.
50 =item B<-d>, B<--remove-d>
52 Remove trailing "d" from the name of the package, and use the result for the
53 filename the init script is installed as in etc/init.d/ , and the default file
54 is installed as in etc/default/ . This may be useful for daemons with names
55 ending in "d". (Note: this takes precedence over the --init-script parameter
58 =item B<-u>I<params> B<--update-rcd-params=>I<params>
62 Pass "params" to L<update-rc.d(8)>. If not specified, "defaults" will be
63 passed to L<update-rc.d(8)>.
65 =item B<--name=>I<name>
67 Install the init script (and default file) using the filename I<name>
68 instead of the default filename, which is the package name. When this
69 parameter is used, dh_installinit looks for and installs files named
70 debian/package.name.init and debian/package.name.default, instead of the
71 usual debian/package.init and debian/package.default.
73 =item B<--init-script=>I<scriptname>
75 Use "scriptname" as the filename the init script is installed as in
76 etc/init.d/ (and also use it as the filename for the defaults file, if it
77 is installed). If you use this parameter, dh_installinit will look to see
78 if a file in the debian/ directory exists that looks like
79 "package.scriptname" and if so will install it as the init script in
80 preference to the files it normally installs.
82 This parameter is deprecated, use the --name parameter instead.
84 =item B<--error-handler=>I<function>
86 Call the named shell function if running the init script fails. The
87 function should be provided in the prerm and postinst scripts, before the
94 Note that this command is not idempotent. "dh_clean -k" should be called
95 between invocations of this command. Otherwise, it may cause multiple
96 instances of the same text to be added to maintainer scripts.
102 foreach my $package (@{$dh{DOPACKAGES}}) {
103 my $tmp=tmpdir($package);
105 # Figure out what filename to install it as.
107 if (defined $dh{NAME}) {
110 elsif ($dh{D_FLAG}) {
111 # -d on the command line sets D_FLAG. We will
112 # remove a trailing 'd' from the package name and
113 # use that as the name.
115 if ($script=~m/(.*)d$/) {
119 warning("\"$package\" has no final d' in its name, but -d was specified.");
122 elsif ($dh{INIT_SCRIPT}) {
123 $script=$dh{INIT_SCRIPT};
129 my $init=pkgfile($package,$script) || pkgfile($package,"init") ||
130 pkgfile($package,"init.d");
131 my $default=pkgfile($package,'default');
133 if ($default ne '') {
134 if (! -d "$tmp/etc/default") {
135 doit("install","-d","$tmp/etc/default");
137 doit("install","-p","-m644",$default,"$tmp/etc/default/$script");
141 if (! -d "$tmp/etc/init.d") {
142 doit("install","-d","$tmp/etc/init.d");
145 doit("install","-p","-m755",$init,"$tmp/etc/init.d/$script");
147 # This is set by the -u "foo" command line switch, it's
148 # the parameters to pass to update-rc.d. If not set,
149 # we have to say "defaults".
151 if (defined($dh{U_PARAMS})) {
152 $params=join(' ',@{$dh{U_PARAMS}});
158 if (! $dh{NOSCRIPTS}) {
159 if (! $dh{NO_START}) {
160 # update-rc.d, and start script
161 autoscript($package,"postinst", "postinst-init",
162 "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/;s/#ERROR_HANDLER#/$dh{ERROR_HANDLER}/");
165 # stops script only on remove
166 autoscript($package,"prerm","prerm-init-norestart",
167 "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/;s/#ERROR_HANDLER#/$dh{ERROR_HANDLER}/");
170 # always stops script
171 autoscript($package,"prerm","prerm-init",
172 "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/;s/#ERROR_HANDLER#/$dh{ERROR_HANDLER}/");
177 autoscript($package,"postinst", "postinst-init-nostart",
178 "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/;s/#ERROR_HANDLER#/$dh{ERROR_HANDLER}/");
182 autoscript($package,"postrm","postrm-init",
183 "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/;s/#ERROR_HANDLER#/$dh{ERROR_HANDLER}/");
192 This program is a part of debhelper.
196 Joey Hess <joeyh@debian.org>