How to change the order of execution of services at startup?

19,609

Solution 1

You can do it by update-rc.d 'service' defaults number where the number is an integer and the lesser the sequence number, the higher the service in the queue i.e it will be executed before other services with a greater sequence number.

The above command will give the same priority for starting as well as killing the service. You can fine tune it further.

So if you have a service which has a lot of dependencies, you can give it a large sequence number to ensure that all of its dependiencies have booted up before it starts itself.

Solution 2

update-rc.d(8) enables or disables services, while the ordering of services is handled by insserv(8), and can be customized by editing the LSB header of the service and setting/adding:

Required-Start: $all

In oldest versions, i can do something like this to determine the order:

update-rc.d myservice start 95 2 3 4 5 . stop 70 0 1 6 .

But after Ubuntu 14, i tried this Ubuntu 16.04 (4.4.0-31-generic):

update-rc.d myservice defaults 95 70

And doesn't work, always creates the order defined in the header:

 sudo find /etc/ -name ???myservice | sort
/etc/rc0.d/K01myservice
/etc/rc1.d/K01myservice
/etc/rc2.d/S03myservice
/etc/rc3.d/S03myservice
/etc/rc4.d/S03myservice
/etc/rc5.d/S03myservice
/etc/rc6.d/K01myservice

Also al try:

update-rc.d myservice defaults any_text_wath_you_want lalala

Ands seems like ignores all the text after "defaults". I don´t know wath it do when my installation order, I do not think that orders previously installed services.

Share:
19,609

Related videos on Youtube

Punit Naik
Author by

Punit Naik

I write code for building tech infra using Clojure(script). I have more than 3 years of experience in the tech industry and have worked in the field of Data Engineering, Back-end, DevOps, Front-end, etc. I also try to commit code to open-source in my free time.

Updated on September 18, 2022

Comments

  • Punit Naik
    Punit Naik over 1 year

    I have some services in my init.d folder for e.g. hdfs, zookeeper, elasticsearch, hbase and so on.

    Now, I have added all those services to startup by doing the update-rc.d 'service' defaults command. As we know, hbase can't run if hdfs and zookeeper are not started. So I want to start hdfs first, then zookeeper and then finally hbase.

    how do I do this?