View Source MuonTrap.Daemon (muontrap v1.2.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)
  • :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)

Link to this section 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.

Link to this section 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()

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.