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 (认真看) 注意:如果涉及到脚本之间的调用一定要用 . ...
随机推荐
- html、xhtml、html5的区别
1.HTML:HyperText Mark-up Language(超文本标记语言)构成网页的主要语言 常指:HTML 4.012.XHTLM:EXtensible HyperText Mark-u ...
- 开窗函数 函数() OVER()
-- 初始化 CREATE TABLE T_Person (FName VARCHAR2(20), FCity VARCHAR2(20), FAge INT, FSalary INT); INSERT ...
- POJ - 1845 G - Sumdiv (唯一分解定理)
Consider two natural numbers A and B. Let S be the sum of all natural divisors of A^B. Determine S m ...
- 数据结构~trie树(字典树)
1.概述 Trie树,又称字典树,单词查找树或者前缀树,是一种用于快速检索的多叉树结构,如英文字母的字典树是一个26叉树,数字的字典树是一个10叉树. 我理解字典树是看了这位大佬博客.还不了解字典树的 ...
- 2019-02-25 EST 科技文翻译
The Definition of Theme and Rheme The point of departure is equally presented to the speaker and to ...
- django面试三
1.Django. Flask.Tornado框架的比较? Django: 对于django,大而全的框架它的内部组件比较多,内部提供:ORM.Admin.中间件.Form.ModelForm.Ses ...
- jQuery中extend()实现原理
jQuery.extend使用的几种方式 1.jQuery.extend(源对象) jQuery源代码: if(length == i){ target = this; --i; } 示例1: var ...
- For all entries in
Today I read about a blog explaining very detailedly on how to correctly use the key words FOR ALL E ...
- busybox 安装问题解决
直接编译错误 1.loginutils/passwd.c:93:16: error: storage size of ‘rlimit_fsize’ isn’t known 解决方法:在busybox根 ...
- Python学习笔记第五周
目录 一.基础概念 1.模块定义 2.包的定义 3.导入包的本质 4.导入模块的本质 5.导入方法 6.import的本质 7.导入优化 8.模块分类 9.标准库介绍 1.time与datetime ...