openresty 使用lua-resty-shell 执行shell 脚本
lua-resty-shell 是一个很不错的项目,让我们可以无阻塞的执行shell命令,之间的通信
是通过socket (一般是unix socket)
环境准备
- docker-compose 文件
version: "3"
services:
app:
build: ./
ports:
- "8080:80"
volumes:
- "./app/:/opt/app/"
- "./nginx.conf:/usr/local/openresty/nginx/conf/nginx.conf"
- dockerfile
FROM openresty/openresty:alpine-fat
LABEL author="1141591465@qq.com"
WORKDIR /sockproc
COPY ./sockproc/ /sockproc/
RUN make sockproc
COPY entrypoint.sh /entrypoint.sh
COPY sockproc.sh /sockproc.sh
COPY shell.lua /usr/local/openresty/lualib/resty/shell.lua
ENTRYPOINT [ "/entrypoint.sh" ]
- dockerfile 说明
dockerfile 同时进行了socket 服务的构建以及shell lua 封装的copy,entrypoint 进行服务的启动
entrypoint.sh:
#!/bin/sh
sh /sockproc.sh
exec /usr/local/openresty/bin/openresty -g "daemon off;"
sockproc.sh:
#!/bin/sh
/sockproc/sockproc /tmp/shell.sock
openresty 集成测试
- lua 调用代码
app/app.lua
local shell = require("resty.shell")
local args = {
socket = "unix:/tmp/shell.sock",
}
function call()
local status, out, err = shell.execute("cat /proc/sys/kernel/random/uuid", args)
ngx.say(out)
end
return call
- openresty content_by_Lua 阶段调用lua shell 封装
+ user root;
http {
+ lua_package_path '/opt/app/?.lua;;';
+ location /test {
+ content_by_lua_block {
+ require("app")()
+ }
- 测试效果

参考资料
https://github.com/juce/lua-resty-shell
https://github.com/rongfengliang/lua-resty-shell-docker-running
openresty 使用lua-resty-shell 执行shell 脚本的更多相关文章
- Shell执行将脚本里的变量打印到指定日志文件
首先需要定位获取任务的运行日志或者报错信息,才能定位问题. 通过shell调用有些脚本的话,日志信息会打印在shell里.不过也有用户在shell里调用正常,但是到crontab调用的时候就出错并且没 ...
- linux shell执行SQL脚本
#!/bin/sh user="user" pass="pass" sqlplus -S $user/$pass select 1 from dual; exi ...
- Linux远程执行Shell命令或脚本
## 远程执行shell命令 ssh [user]@[server] '[command]' # eg. ssh root@192.168.1.1 'uptime' ## 远程执行本地shell脚本 ...
- 【转】linux 定时执行shell脚本
在oracle 中可以利用dbms_job包定时执行pl/sql.sql过程,在像备份等需要在操作系统级定时任务只能采用crontab来完成 本文讲述crontab具体用法,以供备忘. 在oracle ...
- 【Telnet】使用Telnet协议连接到远程Shell执行脚本
介绍 本文介绍如何通过Telnet协议连接到远程Shell,执行脚本,并获取执行结果: 相关文章: <[Jsch]使用SSH协议连接到远程Shell执行脚本>http://www.cnbl ...
- 【Jsch】使用SSH协议连接到远程Shell执行脚本
如果大家熟悉Linux的话,一定对ssh,sftp,scp等命令非常熟悉,ssh是一个安全协议,用来在不同系统或者服务器之间进行安全连接,SSH 在连接和传送的过程中会加密所有的数据. 但是SSH一般 ...
- Linux中执行shell脚本的4种方法总结
bash shell 脚本的方法有多种,现在作个小结.假设我们编写好的shell脚本的文件名为hello.sh,文件位置在/data/shell目录中并已有执行权限. 方法一:切换到shell脚本所在 ...
- Linux中执行shell脚本的4种方法
bash shell 脚本的方法有多种,现在作个小结.假设我们编写好的shell脚本的文件名为hello.sh,文件位置在/data/shell目录中并已有执行权限. 方法一:切换到shell脚本所在 ...
- 执行shell脚本的几种方法及区别
执行shell脚本的几种方法及区别 http://blog.csdn.net/lanxinju/article/details/6032368 (认真看) 注意:如果涉及到脚本之间的调用一定要用 . ...
随机推荐
- do文件的编写(转)
以前在使用ModelSim进行仿真的时候,一直是使用其GUI进行操作的,但是这样很繁琐也很费时.故希望学习其自动化仿真do文件,下面是学习的一些总结. 一.编写基本的do文件 下面按照实际仿真的步骤来 ...
- Android开发---如何操作资源目录中的资源文件4 ---访问xml的配置资源文件的内容
Android开发---如何操作资源目录中的资源文件4 XML,位于res/xml/,这些静态的XML文件用于保存程序的数据和结构. XmlPullParser可以用于解释xml文件 效果图: 描述: ...
- 四川省赛 SCU - 4438
Censor frog is now a editor to censor so-called sensitive words (敏感词). She has a long text pp. Her j ...
- oracle插入数据问题
这个是我的表结构:desc T_STUDENT;Name Type Nullable Default Comments ------------ ----------- ...
- win7 java环境变量配置
进行win7下Java环境变量配置 在"系统变量"下进行如下配置: (1)新建->变量名:JAVA_HOME变量值 C:\Program Files\Java\jd ...
- selenium 自动化安装火狐谷歌插件
谷歌插件下载地址 https://npm.taobao.org/mirrors/chromedriver selenium下载地址 https://pypi.org/simple/selenium/ ...
- 某些浏览器没有canvas.toBlob 方法的解决方案
var dataURLtoBlob = require('blueimp-canvas-to-blob'); // 80x60px GIF image (color black, base64 dat ...
- vue 路由跳转,路由传参的几种方式
1. router-link <router-link :to="{ path: 'yourPath', params: { name: 'name', dataObj: data } ...
- java数组排序(插入排序、冒泡排序、选择排序)与递归 代码示例
import java.util.Scanner; public class OrderBy { public static void main(String[] args) { // Scanner ...
- 常用文本编辑器 editor 的常用插件 —— CopyEdit
1. CopyEdit http://www.conyedit.com/, 跨平台的文本编辑器插件: 监控粘贴板以及支持命令解析 其官网上有其动图演示: