Last active
April 24, 2017 01:36
-
-
Save Faolain/9312eb507d19c6992d5055ab3296e677 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Docker Container Logs | |
4/23/2017 9:29:13 PM Node 'hello@10.42.69.252' not responding to pings. | |
4/23/2017 9:29:14 PM Node 'hello@10.42.69.252' not responding to pings. | |
4/23/2017 9:29:14 PM Node 'hello@10.42.69.252' not responding to pings. | |
4/23/2017 9:29:15 PM Node 'hello@10.42.69.252' not responding to pings. | |
4/23/2017 9:29:16 PM 01:29:16.104 [info] Running Hello.Endpoint with Cowboy using http://localhost:8080 | |
4/23/2017 9:29:16 PM Connecting to phoenix: [{10, 42, 69, 252}] | |
4/23/2017 9:29:16 PM pong | |
4/23/2017 9:29:16 PM Application is up! | |
4/23/2017 9:29:16 PM Running migrations | |
4/23/2017 9:29:16 PM RPC to 'hello@10.42.69.252' failed: {'EXIT', | |
4/23/2017 9:29:16 PM {undef, | |
4/23/2017 9:29:16 PM [{'Elixir.Release.Tasks',migrate,[],[]}, | |
4/23/2017 9:29:16 PM {rpc,'-handle_call_call/6-fun-0-',5, | |
4/23/2017 9:29:16 PM [{file,"rpc.erl"},{line,187}]}]}} | |
4/23/2017 9:29:16 PM | |
4/23/2017 9:29:16 PM Shutting down.. | |
4/23/2017 9:29:17 PM ok | |
4/23/2017 3:22:24 PM Node is not running! | |
which is triggered when running a post_start hook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lib/hello/rancher | |
defmodule Hello.Rancher do | |
use GenServer | |
@connect_interval 5000 # try to connect every 5 seconds | |
def start_link do | |
GenServer.start_link __MODULE__, [], name: __MODULE__ | |
end | |
def init([]) do | |
name = Application.fetch_env!(:hello, :rancher_service_name) | |
send self, :connect | |
{:ok, to_char_list(name)} | |
end | |
def handle_info(:connect, name) do | |
case :inet_tcp.getaddrs(name) do | |
{:ok, ips} -> | |
IO.puts "Connecting to #{name}: #{inspect ips}" | |
for {a,b,c,d} <- ips do | |
Node.connect :"hello@#{a}.#{b}.#{c}.#{d}" | |
end | |
{:error, reason} -> | |
IO.puts "Error resolving #{inspect name}: #{inspect reason}" | |
end | |
IO.puts "Nodes: #{inspect Node.list}" | |
Process.send_after(self, :connect, @connect_interval) | |
{:noreply, name} | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lib/hello.ex | |
.... | |
# Setting PROD on Rancher ENV Variable | |
if System.get_env("PROD") do | |
children = children ++ [worker(Hello.Rancher, [])] | |
end | |
..... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# relhooks/post_start | |
set +e | |
while true; do | |
nodetool ping | |
EXIT_CODE=$? | |
if [ $EXIT_CODE -eq 0 ]; then | |
echo "Application is up!" | |
break | |
fi | |
done | |
set -e | |
echo "Running migrations" | |
bin/hello rpc Elixir.Release.Tasks migrate | |
echo "Migrations run successfully" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
#rel/rancher_boot.sh | |
set -e | |
export RANCHER_IP=$(wget -qO- http://rancher-metadata.rancher.internal/latest/self/container/primary_ip) | |
export RANCHER_SERVICE_NAME=$(wget -qO- http://rancher-metadata.rancher.internal/latest/self/service/name) | |
/opt/app/bin/hello $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lib/release.ex | |
defmodule Release.Tasks do | |
def migrate do | |
{:ok, _} = Application.ensure_all_started(:hello) | |
path = Application.app_dir(:hello, "priv/repo/migrations") | |
Ecto.Migrator.run(Hello.Repo, path, :up, all: true) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# rel/vm.args | |
## Name of the node - this is the only change | |
-name hello@${RANCHER_IP} | |
## Cookie for distributed erlang | |
-setcookie insertsecrethereee | |
## Heartbeat management; auto-restarts VM if it dies or becomes unresponsive | |
## (Disabled by default..use with caution!) | |
##-heart | |
## Enable kernel poll and a few async threads | |
##+K true | |
##+A 5 | |
## Increase number of concurrent ports/sockets | |
##-env ERL_MAX_PORTS 4096 | |
## Tweak GC to run more often | |
##-env ERL_FULLSWEEP_AFTER 10 | |
# Enable SMP automatically based on availability | |
-smp auto |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment