View Source MuonTrap.Daemon (muontrap v1.5.0)

Wrap an OS process in a GenServer so that it can be supervised.

For example, in your children list add MuonTrap.Daemon like this:

children = [
  {MuonTrap.Daemon, ["my_server", ["--options", "foo"]], [cd: "/some_directory"]]}
]

opts = [strategy: :one_for_one, name: MyApplication.Supervisor]
Supervisor.start_link(children, opts)

In the child_spec tuple, the second element is a list that corresponds to the MuonTrap.cmd/3 parameters. I.e., The first item in the list is the program to run, the second is a list of commandline arguments, and the third is a list of options. The same options as MuonTrap.cmd/3 are available with the following additions:

  • :name - Name the Daemon GenServer
  • :log_output - When set, send output from the command to the Logger. Specify the log level (e.g., :debug)
  • :log_prefix - Prefix each log message with this string (defaults to the program's path)
  • :log_transform - Pass a function that takes a string and returns a string to format output from the command. Defaults to String.replace_invalid/1 on Elixir 1.16+ to avoid crashing the logger on non-UTF8 output.
  • :logger_metadata - A keyword list to merge into the process's logger metadata. The :muontrap_cmd and :muontrap_args keys are automatically added and cannot be overridden.
  • :stderr_to_stdout - When set to true, redirect stderr to stdout. Defaults to false.
  • :exit_status_to_reason - Optional function to convert the exit status (a number) to stop reason for the Daemon GenServer. Use if error exit codes carry information or aren't errors.

If you want to run multiple MuonTrap.Daemons under one supervisor, they'll all need unique IDs. Use Supervisor.child_spec/2 like this:

Supervisor.child_spec({MuonTrap.Daemon, ["my_server", []]}, id: :server1)

Summary

Functions

Get the value of the specified cgroup variable.

Returns a specification to start this module under a supervisor.

Return the OS pid to the muontrap executable.

Start/link a deamon GenServer for the specified command.

Return statistics about the daemon

Functions

Link to this function

cgget(server, controller, variable_name)

View Source
@spec cgget(GenServer.server(), binary(), binary()) ::
  {:ok, String.t()} | {:error, File.posix()}

Get the value of the specified cgroup variable.

Link to this function

cgset(server, controller, variable_name, value)

View Source
@spec cgset(GenServer.server(), binary(), binary(), binary()) ::
  :ok | {:error, File.posix()}

Modify a cgroup variable.

@spec child_spec(keyword()) :: Supervisor.child_spec()

Returns a specification to start this module under a supervisor.

See Supervisor.

@spec os_pid(GenServer.server()) :: non_neg_integer() | :error

Return the OS pid to the muontrap executable.

Link to this function

start_link(command, args, opts \\ [])

View Source
@spec start_link(binary(), [binary()], keyword()) :: GenServer.on_start()

Start/link a deamon GenServer for the specified command.

@spec statistics(GenServer.server()) :: %{output_byte_count: non_neg_integer()}

Return statistics about the daemon

Statistics:

  • :output_byte_count - bytes output by the process being run