0

I've made a *.deb with a service:

[Unit]
Description=Hello example service
Wants=nginx

[Service]
Type=simple
ExecStart=/usr/local/bin/hello

TimeoutStopSec=15
Restart=always

postinst script (doesn't affect anything except giving some error during the installation if used: update-rc.d: error: initscript does not exist: /etc/init.d/hello):

update-rc.d hello defaults
invoke-rc.d nginx reload

prerm debian script for it is:

invoke-rc.d hello stop

This script doesn't stop the service. It doesn't work even if launched manually. Returns 102 every time.

systemctl stop works fine for my service.

Somehow the invoke-rc.d works for the web server:

sudo invoke-rc.d nginx stop

What is going on?

1 Answer 1

2

The invoke-rc.d command is for sysv init scripts (as its manpage says), not Upstart or systemd. Nginx still has a sysv init script (look for init.d in the filelist), which is probably why invoke-rc.d works for it (or seems to, anyway).

Even though the Debian guides use invoke-rc.d, on Ubuntu, prefer using the service command. It is a wrapper script that can handle sysv init, Upstart and systemd files.

The systemd documentation recommends using service too:

If your distribution removes SysV init scripts in favor of systemd unit files typing /etc/init.d/foobar start to start a service will not work, since the script will not be available. Use the more correct /sbin/service foobar start instead, and your command will be forwarded to systemd. Note that invoking the init script directly has always been suboptimal since too much of the caller's execution context (environment block, umask, resource limits, audit trails, ...) ended up being inherited by the service, and invocation via /sbin/service used to clean this up at least partially. Invocation via /sbin/service works on both SysV and systemd systems. Also, LSB only standardizes invocation via /sbin/service anyway. (Note that some distributions ship both systemd unit files and SysV scripts for the services. For these invoking the init scripts will work as expected and the request be forwarded to systemd in any case.)

Of course, for Ubuntu, service is located at /usr/sbin/service.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .