[Erlang27]如何监控指定目录下的*.beam文件,如果有改动就更新到指定的节点?
在Erlang In Anger第二章中讲到使用rebar来创建一个Erlang项目(Application或Project)
但美中不足的只是给出了指引,但没有给出详细的步骤。
下面我们就使用rebar一步步来创建一个典型的Application。
但在此之前,最好先理解下Erlang In Anger中第二章节所讲关于application结构的部分:http://zhongwencool.gitbooks.io/erlang_in_anger/
$ git clone git://github.com/rebar/rebar.git
$ cd rebar
$ ./bootstrap
Recompile: src/getopt
...
Recompile: src/rebar_utils
==> rebar (compile)
Congratulations! You now have a self-contained script called "rebar" in
your current working directory. Place this script anywhere in your path
and you can use rebar to build OTP-compliant apps.
为了全局使用rebar,把你的路径加到PATH下:在~/.profile里面加入:
export PATH=$PATH:Your_Rebar_Path
然后重启你的shell或source ~/.profile使它生效
2.创建application:
./rebar create-app appid=autoload
==> rebar (create-app)
Writing src/autoload.app.src
Writing src/autoload_app.erl
Writing src/autoload_sup.erl
生成上面三个模板文件(也可以修改rebar配置自定义模板),
myapp.app.src- The OTP application specification用于rebar自动生成.app文件放到ebin/下。myapp_app.erl- An implementation of the OTP Application behaviour:实现你代码逻辑的地方。myapp_sup.erl- An implementation of the OTP Supervisor behaviour (top level supervisor of the application)此application最高等级的监控树。
{deps, [{inotify, ".*", {git,
"https://github.com/sheyll/inotify.git"}}]}.
{env, [{autoload_path,"./dev_patch/"}, {node_cookie,[{test1@localhost,best},{test2@localhost,best}]},
{log,"./log/console.log"}]}.
这样设置后就可以在代码里使用:
{ok,NodeCookies} = application:get_env(autoload,node_cookie).
这样的函数在全局中得到对应的值。
init([]) ->
{ok, { {one_for_one, 5, 10}, [?CHILD(autoload,worker)]} }.
4.3 在autoload.erl gen_server里面写逻辑:

其实关键在于如何高效地监控到目录下文件的变化,如果这个搞定啦,其它都是小case。
$rebar get-deps
$ rebar compile
erl -pa "./ebin" -pz "./dev_patch" -sname autoload -s autoload -detached
使用下面命令查看日志:tail ./log/console.log -f

[Erlang27]如何监控指定目录下的*.beam文件,如果有改动就更新到指定的节点?的更多相关文章
- [No000073]C#直接删除指定目录下的所有文件及文件夹(保留目录)
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- linux复制指定目录下的全部文件到另一个目录中
linux复制指定目录下的全部文件到另一个目录中复制指定目录下的全部文件到另一个目录中文件及目录的复制是经常要用到的.linux下进行复制的命令为cp.假设复制源目录 为 dir1 ,目标目录为dir ...
- c# 获取指定目录下的所有文件并显示在网页上
参考文献: FileInfo 的使用 https://msdn.microsoft.com/zh-cn/library/system.io.fileinfo_methods(v=vs.110).as ...
- php获取指定目录下的所有文件列表
在我们实际的开发需求中,经常用到操作文件,今天就讲一下关于获取指定目录下的所有文件的几种常用方法: 1.scandir()函数 scandir() 函数返回指定目录中的文件和目录的数组. scandi ...
- java压缩指定目录下的所有文件和文件夹的代码
将代码过程较好的代码段备份一下,下边资料是关于java压缩指定目录下的所有文件和文件夹的代码,希望对码农有帮助. String sourceDir="E:\test";int pa ...
- python之查询指定目录下的最新文件
使用os模块查询指定目录下的最新文件 import os # 输入目录路径,输出最新文件完整路径 def find_new_file(dir): '''查找目录下最新的文件''' file_lists ...
- 微软BI 之SSIS 系列 - 在 SSIS 中将指定目录下的所有文件分类输出到不同文件夹
开篇介绍 比如有这样的一个需求,旧的一个业务系统通常将产出的文件输出到同一个指定的目录下的不同子目录,输出的文件类型有 XML,EXCEL, TXT 这些不同后缀的文件.现在需要在 SSIS 中将它们 ...
- linux复制指定目录下的全部文件到另一个目录中,linux cp 文件夹
linux复制指定目录下的全部文件到另一个目录中复制指定目录下的全部文件到另一个目录中文件及目录的复制是经常要用到的.linux下进行复制的命令为cp.假设复制源目录 为 dir1 ,目标目录为dir ...
- C# 删除指定目录下的所有文件及文件夹
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Tex ...
随机推荐
- [Android] 开发第五天
布之前开发的 Android 电话拨号器 Android-Studio 已经带了发布菜单, Build -> Generate Signed APK 进入发布界面 我们新增一个证书,或者使用已有 ...
- Hive默认分割符
1.Hive默认的分隔符 Hive的表数据,不管导出到HDFS还是本地文件系统,如果用户在导出时没有指定分割符,那么Hive表的数据在写入文件时,会使用默认的分隔符作为列分隔符,该默认的分割是“CTR ...
- 给iOS开发新手送点福利,简述UIAlertView的属性和用法
UIAlertView 1.Title 获取或设置UIAlertView上的标题. 2.Message 获取或设置UIAlertView上的消息 UIAlertView *alertView = [[ ...
- 给iOS开发新手送点福利,简述UISwitch的属性和用法
UISwitch属性 1. onTintColor 处于on时switch 的颜色 switchImage.onTintColor = [UIColor grayColor]; 2.tintC ...
- T-SQL 总结
SP0_AddLinkedServer.sql [创建Linked SQL Server ] USE [master] GO ) drop procedure dbo.SP_Temp_AddLinke ...
- Linux常用命令之-grep
简介 grep全称Global Regular Expression Print是一种强大的文本搜索工具,它能使用给定的正则表达式按行搜索文本输出,文件,目录等,统计并输出匹配的信息,grep在文本查 ...
- 使用API调用外部程序并监控程序状态
Public Type SHELLEXECUTEINFO cbSize As Long fMask As Long hwnd As Long lpVerb As String ...
- UVALive-7297-Hounded by Indecision
OK, maybe stealing the Duchess’s favorite ruby necklace was not such a good idea. You were makingyou ...
- 【转】简述TCP的三次握手过程
TCP握手协议 在TCP/IP协议中,TCP协议提供可靠的连接服务,采用三次握手建立一个连接.第一次握手:建立连接时,客户端发送syn包(syn=j)到服务器,并进入SYN_SEND状态,等待服务器确 ...
- IronPython Architecture
[IronPython] IronPython is an implementation of the Python programming language written by the CLR t ...