I am creating a cluster with Erlang that has a leader/follower setup. I have 3 apps that I load in my rebar.config but I don’t start them if they are a follower. If a node starts up (or becomes the leader, it starts these loaded programs. If a node starts as a follower, the loaded apps are not started. If a node goes from a leader to a follower, it stops the loaded applications that are leader-only.
I noticed loaded applications do not appear with
application:which_applications/0. They do appear with
application:loaded_applications/0. If I the application is running and I run
application:stop(app_name). it returns:
If I do
app_name_app:start(ok,ok) for an app that starts when I start my Erlang program, the application runs as expected.
So, starting/stopping the application via
app_name_app:stop(ok). is useless then, and likewise I get the not_started when using the
application module. So what then is the best way to start/stop unloaded apps? This is leaving processes continuing to run when I intend to stop them. Should I change my loaded apps to be more aware of their state? Or is there a better solution for stopping my apps when a node moves from a leader to a follower?