#命令行 #REST #定时 #执行器 #执行命令 #状态命令

应用 scheduledexec

REST服务,用于在特定时间点执行一系列命令行

1个不稳定版本

0.1.0 2024年2月7日

#294HTTP服务器

MIT/Apache

20KB
362

scheduleexec

REST服务,使用POST请求在适当的时间点执行命令行,并监控这些命令的状态。

功能

  • 在场景中指定的相对时间点执行REST客户端提供的命令行
  • 收集并报告命令的输出和计时
  • 可以在命令行数组前添加程序名称(以避免访问整个shell)
  • 灵活的服务器套接字监听选项(例如UNIX套接字或systemd套接字初始化)

限制

  • 不支持非UTF-8命令行片段或输出
  • 失败的命令会终止场景
  • 如果命令执行时间过长,scheduledexec错过了下一个命令,则场景也会因错误而终止

文档

以下是一个端点简要列表

/start - begin executing a scenario
/abort - abort currenty executed scenario
/status - query information
/monitor - subscribe to events     
/getscenario - get current or last scenario
/report - download final scenario report

您可以使用OpenAPI编辑器,如Swagger,配合预构建的openapi.json文件来查看文档。

示例

$ cargo run  -- 127.0.0.1:1234
$ curl http://127.0.0.1:1234/status; echo
{"status":"Idle"}
$ curl -H 'Content-Type: application/json' -d @scenario_sample.json -s http://127.0.0.1:1234/start
$ curl http://127.0.0.1:1234/status; echo
{"status":"Completed"}
$ curl http://127.0.0.1:1234/report; echo
{"error":false,"aborted":false,"entries":[{"out":"Wed Feb  7 22:44:24 CET 2024\n","err":"","exitcode":0,"timespan_ms":3},...]}

安装

Github发行版下载预构建的可执行文件,或使用源代码安装,方法为:cargo install --path .cargo install scheduledexec

CLI选项

scheduledexec --help 输出
REST service to execute series of command lines at specific moments of time

Usage: 

Arguments:
  <LISTEN_ADDRESS>
          Socket address to listen for incoming connections.
          
          Various types of addresses are supported:
          
          * TCP socket address and port, like 127.0.0.1:8080 or [::]:80
          
          * UNIX socket path like /tmp/mysock or Linux abstract address like @abstract
          
          * Special keyword "inetd" for serving one connection from stdin/stdout
          
          * Special keyword "sd-listen" or "sd-listen-unix" to accept connections from file descriptor 3 (e.g. systemd socket activation)

  [PREFIX]
          Prepend this command to all executed chunks

Options:
      --unix-listen-unlink
          remove UNIX socket prior to binding to it

      --unix-listen-chmod <UNIX_LISTEN_CHMOD>
          change filesystem mode of the newly bound UNIX socket to `owner`, `group` or `everybody`

      --unix-listen-uid <UNIX_LISTEN_UID>
          change owner user of the newly bound UNIX socket to this numeric uid

      --unix-listen-gid <UNIX_LISTEN_GID>
          change owner group of the newly bound UNIX socket to this numeric uid

      --sd-accept-ignore-environment
          ignore environment variables like LISTEN_PID or LISTEN_FDS and unconditionally use file descritor `3` as a socket in sd-listen or sd-listen-unix modes

      --tcp-keepalive <TCP_KEEPALIVE>
          set SO_KEEPALIVE settings for each accepted TCP connection.
          
          Value is a colon-separated triplet of time_ms:count:interval_ms, each of which is optional.

      --tcp-reuse-port
          Try to set SO_REUSEPORT, so that multiple processes can accept connections from the same port in a round-robin fashion

      --recv-buffer-size <RECV_BUFFER_SIZE>
          Set socket's SO_RCVBUF value

      --send-buffer-size <SEND_BUFFER_SIZE>
          Set socket's SO_SNDBUF value

      --tcp-only-v6
          Set socket's IPV6_V6ONLY to true, to avoid receiving IPv4 connections on IPv6 socket

      --tcp-listen-backlog <TCP_LISTEN_BACKLOG>
          Maximum number of pending unaccepted connections

  -h, --help
          Print help (see a summary with '-h')

依赖项

~8–18MB
~240K SLoC