Simulate Process Faults

This document describes how to use Chaosd to simulate process faults. The process faults use the Golang interface of the kill command to simulate the scenarios that the process is killed or stopped. You can create experiments either in the command-line mode or service mode.

Create experiments using the command-line mode

Before creating an experiment, you can run the following command to see the process fault types that are supported by Chaosd:

  1. chaosd attack process -h

The result is as follows:

  1. Process attack related commands
  2. Usage:
  3. chaosd attack process [command]
  4. Available Commands:
  5. kill kill process, default signal 9
  6. stop stop process, this action will stop the process with SIGSTOP
  7. Flags:
  8. -h, --help help for process
  9. Global Flags:
  10. --log-level string the log level of chaosd, the value can be 'debug', 'info', 'warn' and 'error'
  11. Use "chaosd attack process [command] --help" for more information about a command.

Currently, Chaosd supports simulating that a process is killed or stopped.

Killing a process using the command-line mode

Commands for killing a process

  1. chaosd attack process kill -h

The result is as follows:

  1. kill process, default signal 9
  2. Usage:
  3. chaosd attack process kill [flags]
  4. Flags:
  5. -h, --help help for kill
  6. -p, --process string The process name or the process ID
  7. -r, --recover-cmd string The command to be run when recovering experiment
  8. -s, --signal int The signal number to send (default 9)
  9. Global Flags:
  10. --log-level string the log level of chaosd. The value can be 'debug', 'info', 'warn' and 'error'
  11. --uid string the experiment ID

Configuration description for killing a process

Configuration itemAbbreviationDescriptionValue
processpThe name or the identifier of the process to be injected faultsstring; the default value is “”.
recover-cmdrThe command to be run when recovering experimentstring; the default value is “”.
signalsThe provided value of the process signalint; the default value is 9. Currently, only SIGKILL, SIGTERM, and SIGSTOP are supported.

Example for killing a process

  1. chaosd attack process kill -p python

The result is as follows:

  1. Attack process python successfully, uid: 10e633ac-0a37-41ba-8b4a-cd5ab92099f9

Simulate Process Faults - 图1note

Only the experiments whose signal is SIGSTOP can be recovered.

Stopping a process using the command-line mode

Command for stopping a process

  1. chaosd attack process stop -h

The result is as follows:

  1. stop process, this action will stop the process with SIGSTOP
  2. Usage:
  3. chaosd attack process stop [flags]
  4. Flags:
  5. -h, --help help for stop
  6. -p, --process string The process name or the process ID
  7. Global Flags:
  8. --log-level string the log level of chaosd, the value can be 'debug', 'info', 'warn' and 'error'

Configuration description of stopping a process

Configuration itemAbbreviationDescriptionValue
processpThe name or the identifier of the process to be stoppedstring; the default value is “”.

Example for stopping a process

  1. chaosd attack process stop -p python

The result is as follows:

  1. Attack process python successfully, uid: 9cb6b3be-4f5b-4ecb-ae05-51050fcd0010

Create experiments using the service mode

To create experiments using the service mode, follow the instructions below:

  1. Run Chaosd in the service mode:

    1. chaosd server --port 31767
  2. Send a POST HTTP request to the /api/attack/process path of the Chaosd service.

    1. curl -X POST 172.16.112.130:31767/api/attack/process -H "Content-Type:application/json" -d '{fault-configuration}'

    In the above command, you need to configure fault-configuration according to the fault types. For the corresponding parameters, refer to the parameters and examples of each fault type in the following sections.

Simulate Process Faults - 图2note

When running an experiment, remember to record the UID of the experiment. When you want to end the experiment corresponding to the UID, you need to send a DELETE HTTP request to the /api/attack/{uid} path of the Chaosd service.

Simulate process faults using the service mode

Parameters for simulating process faults

ParameterDescriptionValue
processThe name or the identifier of the process to be injected faultsstring; the default value is “”.
signalThe provided value of the process signalint; the default value is 9

Examples for simulating process faults using the service mode

Terminate a process
  1. curl -X POST 172.16.112.130:31767/api/attack/process -H "Content-Type:application/json" -d '{"process":"12345","signal":15}'

The result is as follows:

  1. {"status":200,"message":"attack successfully","uid":"c3c519bf-819a-4a7b-97fb-e3d0814481fa"}
Stop a process
  1. curl -X POST 172.16.112.130:31767/api/attack/process -H "Content-Type:application/json" -d '{"process":"12345","signal":19}'

The result is as follows:

  1. {"status":200,"message":"attack successfully","uid":"a00cca2b-eba7-4716-86b3-3e66f94880f7"}

Simulate Process Faults - 图3note

Only the experiments whose signal is SIGSTOP can be recovered.