diff options
author | Logan Hunt <loganhunt@simponic.xyz> | 2022-12-29 18:37:51 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-29 18:37:51 -0700 |
commit | c143bb549c53f2737c41cdfce6cc2598c5489bdc (patch) | |
tree | 33853e2a9c30ff7c670aa4ff5b73df005d6e6fec /lib/chessh/application.ex | |
parent | f7c2ccbe26dc808e4a7eae9a378e6c382220961a (diff) | |
parent | 479ca815e3a1760c71e8977674434b15f94ae833 (diff) | |
download | chessh-c143bb549c53f2737c41cdfce6cc2598c5489bdc.tar.gz chessh-c143bb549c53f2737c41cdfce6cc2598c5489bdc.zip |
Merge pull request #1 from Simponic/erlang_ssh_server
Diffstat (limited to 'lib/chessh/application.ex')
-rw-r--r-- | lib/chessh/application.ex | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/chessh/application.ex b/lib/chessh/application.ex index c760532..4692489 100644 --- a/lib/chessh/application.ex +++ b/lib/chessh/application.ex @@ -1,9 +1,23 @@ defmodule Chessh.Application do + alias Chessh.{PlayerSession, Node} use Application + def initialize_player_sessions_on_node() do + # If we have more than one node running the ssh daemon, we'd want to ensure + # this is restarting after every potential crash. Otherwise the player sessions + # on the node would hang. + node_id = System.fetch_env!("NODE_ID") + Node.boot(node_id) + PlayerSession.delete_all_on_node(node_id) + end + def start(_, _) do - children = [Chessh.Repo] + children = [Chessh.Repo, Chessh.SSH.Daemon] opts = [strategy: :one_for_one, name: Chessh.Supervisor] - Supervisor.start_link(children, opts) + + with {:ok, pid} <- Supervisor.start_link(children, opts) do + initialize_player_sessions_on_node() + {:ok, pid} + end end end |