title: Starting an app using supervisor in Elixir which would automatically restart on error
body: <p>I am able to run an app on elixir but if an error occurs, everything exists. I just want that my app restarts in this case. I am using supervisor but don't even know if it's working. Following is my code:-</p>
  
  <p>mix.exs:-</p>
  
  <pre><code>def application do
  [ 
    applications: [:httpotion, :zookeeper, :parallel, :poison],
    mod: {ServiceMonitor, []}
  ]
  end
  </code></pre>
  
  <p>service_monitor.ex</p>
  
  <pre><code>defmodule ServiceMonitor do
    use Application
  
    def start(_type, _args) do
      import Supervisor.Spec, warn: false
  
      children = [
          worker(ServiceMonitor.Registry.setup, []),
      ]
  
      supervise(children, strategy: :one_for_one)
    end
  end
  </code></pre>
  
  <p>registry.ex</p>
  
  <pre><code>defmodule ServiceMonitor.Registry do
  
    def setup do
      zk = get_zk
      start(zk)
    end
  
    def start(zk) do
      #main code
    end
  end
  </code></pre>
  
  <p>Now i am running my app using the command:-</p>
  
  <pre><code>MIX_ENV=test mix run
  </code></pre>
  
  <p>It all runs well until i receive an error in my main code. Application exists and never restarts. Error i receive is:-</p>
  
  <pre><code>** (Mix) Could not start application service_monitor: exited in: ServiceMonitor.start(:normal, [])
  ** (EXIT) exited in: Task.await(%Task{owner: #PID&lt;0.164.0&gt;, pid: #PID&lt;0.169.0&gt;, ref: #Reference&lt;0.0.2.1026&gt;}, 3600000)
      ** (EXIT) an exception was raised:
          ** (MatchError) no match of right hand side value: {:error, :no_node}
              (service_monitor) lib/service_monitor/registry.ex:121: anonymous fn/3 in ServiceMonitor.Registry.remove_available_if_not_registered/3
              (elixir) lib/task/supervised.ex:89: Task.Supervised.do_apply/2
              (elixir) lib/task/supervised.ex:40: Task.Supervised.reply/5
              (stdlib) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
  </code></pre>
  
  <p>Kindly help as to where i am going wrong. My requirement is that app should automatically restart as soon as error is received.</p>