What is "Bang" method?

Here we introduce the "bang()" method present in SLAP API.


When run, slapgrid daemon only modifies needed instances. For example, let's say we have a given instance, which is stopped, and user requests on Master to start it, it will be processed by slapgrid and change status from "stopped" to "started". Once started, it will be ignored by slapgrid until another action is requested by the user. In summary, slapgrid only processes instances where an action is required.

This optimization allows slapgrid to process very quickly all the instances of a computer, because in fact only a small portion of the instances are processed. But it has some drawbacks too. What happens if the server where your instance is crashes and reboots? What if some instances of your dependency tree are not stable?

Answer is simple : slapgrid does… Nothing, and your service won't work anymore. In the case of server reboot (after a electricity outage for example), because slapgrid is stateless, none of the not-changed-instances will be processed to be started again, because they already are considered as started.

This is why we introduced the bang method. It basically allows the SlapOS master to recalculate state of all your instances and forces slapgrid to process them.

Bang method comes in two flavours : instance based bang, and computer based bang.

Instance based bang

instance.bang() will cause SlapOS Master to recalculate ALL instances of your instance tree.

Imagine that your service has a frontend instance (say apache), and a database instance (say MariaDB). If the computer hosting your MariaDB instance goes offline, all your service is doomed. But if one instance detects this bad state and triggers "bang()" method, all the instances, including the bad MariaDB, will be recalculated and can be reallocated somewhere else if something is wrong. This way, the MariaDB instance gets reallocated elsewhere (with all data, thanks to pseudo-replication) and service can work again after being unavailable only a couple of minutes.

Computer based bang

Computer.bang() is a wrapper calling instance.bang() for all instances present on this computer, and thus will cause slapgrid to process trees of all those instances to bring instances in this computer back online.

Bang is typically used after server reboot to tell the SlapOS Master that we have to relaunch all services.

All servers using SlapOS should add a crontab entry, as shown in the configuration tutorial, to trigger this method at boot time, so that even not-changed-instances will be processed by slapgrid daemon.

Bottom Gadget
Right Gadget