How do I start a service on boot in debian?

So I created a service and made it executale in /etc/init.d Then I tried to make it start after boot with the following command:

update-rc.d <myService> defaults

But the output were warnings of other services (which work just fine by the way) and I don't want to touch those.

My next attempt to solve this was to add the following lines in the rc.local file:

do_start() {
        service <someOtherService> stop
        service <myService> stop
        sleep 5
        service <someOtherService> start
        service <myService> stop
        ........

As I said, I have some other service that works just fine, but my service which I am currently trying to add wont start after boot.

One more thing that I would like to add is when I manually enter:

service <myService> start/stop

then it works just fine


Solution 1:

To add a service at boot, you can add an Upstart job.

Create your conf file in /etc/init (e.g. /etc/init/myjob.conf)

with a content like this (Example)

description "My job"
start on startup
task
exec /path/to/script.sh

More informations here (Debian doc)

Info: you need the upstart package.

Solution 2:

The following works very well for me.

First determine if your system is running SysV init or systemd, for that use:

$ ps -p 1

If SysV init:

$ sudo update-rc.d <service_name> defaults 95 10

If systemd:

$ sudo /bin/systemctl daemon-reload
$ sudo /bin/systemctl enable <service_name>.service

I successfully used the last one on a ParrotSecurity OS that is based on Debian 5.