Packages
nerves_runtime
0.11.10
0.13.13
0.13.12
0.13.11
retired
0.13.10
0.13.9
0.13.8
0.13.7
0.13.6
0.13.5
0.13.4
0.13.3
0.13.2
0.13.1
0.13.0
0.12.0
0.11.10
0.11.9
0.11.8
0.11.7
0.11.6
0.11.5
0.11.4
0.11.3
0.11.2
0.11.1
0.11.0
0.10.3
0.10.2
0.10.1
0.10.0
retired
0.9.5
0.9.4
0.9.3
0.9.2
0.9.1
0.9.0
0.8.0
0.7.0
0.6.5
0.6.4
0.6.3
0.6.2
0.6.1
0.6.0
0.5.3
0.5.2
0.5.1
0.5.0
0.4.4
0.4.3
0.4.2
0.4.1
0.4.0
0.3.1
0.3.0
0.2.0
0.1.2
0.1.1
0.1.0
Small, general runtime utilities for Nerves devices
Current section
Files
Jump to
Current section
Files
lib/nerves_runtime/application.ex
defmodule Nerves.Runtime.Application do
@moduledoc false
use Application
require Logger
alias Nerves.Runtime.{Init, Kernel, KV}
alias Nerves.Runtime.Log.{KmsgTailer, SyslogTailer}
@impl Application
def start(_type, _args) do
target = Nerves.Runtime.target()
load_services(target)
children = [KV | target_children(target)]
opts = [strategy: :one_for_one, name: Nerves.Runtime.Supervisor]
Supervisor.start_link(children, opts)
end
defp target_children("host") do
[]
end
defp target_children(_target) do
kernel_opts = Application.get_env(:nerves_runtime, :kernel, [])
[
KmsgTailer,
SyslogTailer,
{Kernel.UEvent, kernel_opts},
Init
]
end
defp load_services("host"), do: :ok
defp load_services(_target) do
# On systems with hardware random number generation, it is important that
# "rngd" gets started as soon as possible to start adding entropy to the
# system. So much code directly or indirectly uses random numbers that it's
# very easy to block on the random number generator or get low entropy
# numbers.
# On systems with no hardware random number generation, or where rngd is
# not installed, haveged is tried as an alternative.
try_entropy_generator("rngd") || try_entropy_generator("haveged")
_ = try_load_sysctl_conf()
:ok
end
defp try_entropy_generator(name) do
path = "/usr/sbin/#{name}"
if File.exists?(path) do
# Launch rngd/haveged. They daemonize themselves so this should return quickly.
case System.cmd(path, []) do
{_, 0} ->
true
{reason, _non_zero_exit} ->
Logger.warn("Failed to start #{name}: #{inspect(reason)}")
false
end
else
false
end
end
defp try_load_sysctl_conf() do
conf_path = "/etc/sysctl.conf"
if File.exists?(conf_path) do
case System.cmd("/sbin/sysctl", ["-p", conf_path]) do
{_, 0} ->
:ok
{reason, _non_zero_exit} ->
Logger.warn("Failed to run sysctl on #{conf_path}: #{inspect(reason)}")
{:error, reason}
end
else
{:error, :not_found}
end
end
end