realbook v0.2.0 Realbook.Commands View Source
Command macros that are helper functions for common tasks.
imported into your Realbook scripts by default.
Link to this section Summary
Functions
appends binary content to the target file.
finds a file at the path (relative to the application env
variable :realbook
, :asset_dir
), opens it, and returns the binary.
extracts the specified keys out of the realbook dictionary and
wraps them into a map. Useful for when an EEx template is generated
from an assigns
variable.
raises Realbook.ExecutionError
automatically with the issued comment.
gets a value from the Realbook key/value store. Registers the key as required prior to running the script.
gets a value from the Realbook key/value store, providing a default value if the key has not been set yet.
sends a log message with canonical realbook metadata and desired message.
runs a command on the remote host.
runs a command on the remote host.
sends binary content to the target.
sets key/value pairs into the Realbook key/value store. Registers the keys as provided by the script.
pauses for time
milliseconds
like append!/3
but useful for files which are owned by superuser.
like run/2
, except with the command run as superuser
like run!/2
, except with the command run as superuser
like send/3
but changes posession of the file to superuser after
transmission.
performs the remote command and repeats it if the command raises or
returns false. Useful for events which may take action after the command
is issued, such as systemctl
actions.
Link to this section Functions
appends binary content to the target file.
returns ok if successful and raises on either a connection error or a sending error.
finds a file at the path (relative to the application env
variable :realbook
, :asset_dir
), opens it, and returns the binary.
raises if :asset_dir
is not set or if there is a problem with the file.
extracts the specified keys out of the realbook dictionary and
wraps them into a map. Useful for when an EEx template is generated
from an assigns
variable.
raises Realbook.ExecutionError
automatically with the issued comment.
gets a value from the Realbook key/value store. Registers the key as required prior to running the script.
gets a value from the Realbook key/value store, providing a default value if the key has not been set yet.
Important
This will not set the value if it has not been set yet.
sends a log message with canonical realbook metadata and desired message.
runs a command on the remote host.
For options, consult your adapter module.
raises Realbook.ExecutionError if there is a connection error.
if the command is executed, returns:
{:ok, stdout}
if the command has zero return code.{:error, error, retcode}
if the command has nonzero return code.
Note
the stdout term in run
may have trailing spaces or carriage returns
depending on the command being executed; run!/2
will trim this for you.
runs a command on the remote host.
For options, consult your adapter module.
raises Realbook.ExecutionError if there is a connection error OR if the executed command returns a nonzero return code.
if the command returns a zero return code, this macro returns the standard output of the command.
Note
run!
peforms a String.trim/1
operation on the output,
and run/2
does not.
sends binary content to the target.
returns ok if successful and raises on either a connection error or a sending error.
sets key/value pairs into the Realbook key/value store. Registers the keys as provided by the script.
pauses for time
milliseconds
like append!/3
but useful for files which are owned by superuser.
like run/2
, except with the command run as superuser
like run!/2
, except with the command run as superuser
like send/3
but changes posession of the file to superuser after
transmission.
performs the remote command and repeats it if the command raises or
returns false. Useful for events which may take action after the command
is issued, such as systemctl
actions.
Options
:count
(integer) how many times we should try. Defaults to 10.:wait
(integer) how many millseconds we should. Defaults to 1000.:callback
an arity-1 lambda that will be passed the options map list each time the system fails. This map has the following fields::count
how many times are left:wait
how many milliseconds will be waited the next round:backoff
exponential factor for the next wait, must be > 1 the result of the callback should be updated options; you may also save metadata here, if desired; but do not delete the:count
or:wait
keys.
:backoff
(float)
Example
wait_till count: 50 do
run! "systemctl is-active --quiet my_service"
end
wait_till count: 10, do
run! "some-command"
end