UP | HOME

resty-cli

Table of Contents

1 概述

resty 命令行实用程序可像 lua 或 luajit 命令行实用程序一样,直接从命令行运行 OpenResty 的 Lua 脚本。它可以使用 OpenResty Lua 创建各种命令行实用程序。

该工具通过创建 head-less nginx 实例,禁用守护程序,master_process,access_log 以及其他不需要的东西来工作。没有配置 server {} ,因此根本不涉及侦听套接字。

Lua 代码由 init_worker_by_lua 指令启动,并在 ngx.timer 回调的上下文中运行。因此,在 ngx.timer 回调上下文中可用的所有 ngx_lua 的 Lua API 也可以在 resty 实用程序中使用。不过,我们将来可能会删除一些剩余的限制。

2 使用

2.1 --errlog-level LEVEL

Set nginx error_log level.Can be debug, info, notice, warn, error, crit, alert,or emerg.

执行:

./bin/resty --errlog-level=debug -e 'ngx.say("hello")'

2.2 --http-include PATH

nginx http 配置块中包含的文件,可以包含多个配置文件。

2.3 -I DIR

添加搜索 lua 库的目录。

./bin/resty -I /Users/lsl/.luarocks/share/lua/5.3/ resty-cli/lib.lua

2.4 --ns IP

指定名字服务地址。

2.5 --shdict 'NAME SIZE'

在 HTTP 代码块中创建内存字典,可以同时设置多个。

./bin/resty --shdict 'dogs 1m' resty-cli/shm.lua

2.6 --stap

使用 sysetmtap 运行底层 nginx C process.

2.7 --stap-opts OPTS

systemtap 命令行选项。

2.8 -V

打印版本号和 nginx 配置。

Author: liushangliang

Email: phenix3443+github@gmail.com

Created: 2020-04-26 日 10:52