Processes and Commands ====================== There are two main restraint processes. The first is the restraint server named `restraintd` which processes tasks. The second process supports restraint standalone. This process is the restraint client named `restraint` which starts `restraintd`, provides the job.xml information to the server, and collects logs and results from the server. .. _restraintd_intro: restraintd ---------- `restraintd` is the daemon which executes the tasks. Both a SysV init script and a systemd unit file are provided. The included spec file will use the correct one when built on RHEL/Fedora based systems. Logging messages from restraintd are printed to stderr and all output from command execution is printed to stdout. stderr is redirected to /dev/console to help debug when things go wrong. The SysV init script redirects both stdout and stderr to /var/log/restraintd.log. For systemd, use the following `journalctl` command to view restraint logs:: journalctl --unit restraintd -- Logs begin at Thu 2020-03-12 11:45:05 EDT, end at Thu 2020-03-12 12:10:47 EDT. -- Mar 12 11:45:26 virt-test systemd[1]: Starting The restraint harness.... Mar 12 11:45:26 virt-test systemd[1]: Started The restraint harness.. Mar 12 11:45:26 virt-test restraintd[1135]: recipe: * Fetching recipe: http://lc.example.net:8000//recipes/30220/ Mar 12 11:45:26 virt-test restraintd[1135]: Listening on http://localhost:8081 Mar 12 11:45:26 virt-test restraintd[1135]: recipe: * Parsing recipe Mar 12 11:45:26 virt-test restraintd[1135]: recipe: * Running recipe Mar 12 11:45:26 virt-test restraintd[1135]: ** Fetching task: 183853 [/mnt/tests/distribution/check-install] Mar 12 11:45:26 virt-test restraintd[1135]: use_pty:FALSE rstrnt-package reinstall beaker-core-tasks-distribution-check-install Mar 12 11:45:32 virt-test yum[1194]: Installed: beaker-core-tasks-distribution-check-install-1.0-2.noarch Mar 12 11:45:33 virt-test restraintd[1135]: ** Preparing metadata Mar 12 11:45:33 virt-test restraintd[1135]: ** Refreshing peer role hostnames: Retries 0 Mar 12 11:45:33 virt-test restraintd[1135]: ** Updating env vars Mar 12 11:45:33 virt-test restraintd[1135]: ** Updating external watchdog: 2400 seconds Mar 12 11:45:33 virt-test restraintd[1135]: ** Installing dependencies Mar 12 11:45:33 virt-test restraintd[1135]: ** Running task: 183853 [/distribution/check-install] ... Mar 12 11:45:43 virt-test restraintd[1135]: ** Completed Task : 183853 When `restraintd` runs as a system service by SysV init or systemd, it listens on the port 8081. `restraintd` can also be paired with the restraint client at which case it does not run as a service. More details on `Standalone` can be found at :ref:`restraint_client`. In this case, any `restraintd` stdout/stderr output is directed to the `restraint` client output. The scripts and programs associated with the `restraintd` server can be run within the context of a job as well outside a job execution. .. _common-cmd-args: Command Usage ~~~~~~~~~~~~~ Restraint commands are communicated to the running `restraintd` service by providing a URL that `restraintd` is listening to. When the command is run within a job, the needed information is available by way of environment variables set by `restraintd` for each task. When the command is executed outside a job, you can provide the information by one of three options. One option relies on setting of environment variables. Second is the server option which requires you gather restraint server port, recipe number, and task number for constructing the command URL. Lastly is a local option which relies on an environment file created by `restraintd`. **Environment Variables Option** Most often, many of restraint commands are executed in tasks included in your 'job.xml'. As a result, commands look for specific environment variables to be set by restraintd. The variables are as follows with data such as port, recipe, and task id which is unique for each job:: HARNESS_PREFIX=RSTRNT_ RSTRNT_URL=http://localhost: RSTRNT_RECIPE_URL=http://localhost:/recipes/ RSTRNT_TASKID= .. note:: is a numeric value representing the port used to communicate with `restraintd`. and are the numeric values assigned to your running jobs recipe and task. To utilize the environment variables option when executing a command outside your job, the command software will default to look for environment variables when other `Server` and `Local` options are not set. These environment variables must be set by the user before executing the command. **Server Option** The server option of calling these commands without exporting environment variables is to provide the argument:: -s, --server The format of the is one of the following depending on the command:: # for rstrnt-abort http://localhost:/recipes//status/ # for rstrnt-adjust-watchdog http://localhost:/recipes//watchdog/ # for rstrnt-report-results http://localhost:/recipes//tasks//results/ # for rstrnt-report-log. The string /logs/$file is appended by the command for you. http://localhost:/recipes//tasks/ **Local Option** A simpler option is to run the command locally on the host running `restraintd` by specifying the following argument:: --port This option can be used on the same host running `restraintd` since the information is derived from the local file `/var/lib/restraint/rstrnt-commands-env-<$port>.sh` (where `$port` is the port number restraintd listens on). As the server progresses through a job, it defines this file based on the current task. As a result, the user does not need to gather recipe number and task number and construct a URL for a command as this will be generated for you. The port number must be provided by the user. For `restraintd` service, the default port of 8081 can be used. When running with `restraint` client, the port number can be found in `restraint` client log output since `restraintd` output is redirected to the client. Log locations for service and non-service `restraintd` can be found in the section :ref:`restraintd_intro`. The following log entry is the one which contains the port number of interest:: Listening on http://localhost: This `--port` option has similar effect to doing the following prior to executing the command:: export $(cat /var/lib/restraint/rstrnt-commands-env-$port.sh) In conclusion, one of three methods must be used to execute your command. The following are examples of each method using the command `rstrnt-abort` as an example:: rstrnt-abort # Environment Variables method rstrnt-abort -s http://localhost:/recipes//tasks//status/ # Legacy Method rstrnt-abort --port # Local Method .. note:: 1. Replace , , with your restraint port number, recipe id, task id. 2. Given these fields change as the job progresses and if you are running the command outside the job, the window of opportunity to target the current running task is reduced when using the --port option. rstrnt-abort ~~~~~~~~~~~~ Running this command sets a recipe to `Aborted` status. As a result, the current task as well as subsequent tasks in the recipe will be marked as `aborted` and the job is discontinued. Arguments for this command are as follows:: rstrnt-abort [ --port ] \ -s, --server ] Where: .. option:: --port :noindex: Refer to :ref:`common-cmd-args` for details. .. option:: -s, --server :noindex: Refer to :ref:`common-cmd-args` for details. Where is as follows:: http://localhost:/recipes//status/ rstrnt-adjust-watchdog ~~~~~~~~~~~~~~~~~~~~~~ This command allows you to adjust both the external watchdog and the local watchdog. The arguments for this command is as follows:: rstrnt-adjust-watchdog [ --port ] \ -s, --server ]