转载:http://www.iteye.com/topic/362394
能对运行中的erl系统进行控制是非常重要的一个福利,但是假如你的erl系统是后台运行的, 根本就没有shell可以让你输入。
如果你的节点有name 那么可以用JCL 或者-remsh 接入. 否则的话 你就得用如下方法:
请先参考 Embedded Systems User's Guide. 这种方式的好处是你的所有输入输出都记录在log文件里面 方便你日后查阅。
先运行
[root@localhost R13A]# which erl
/usr/local/bin/erl
确认下你的erl系统安装在那个路径。
[root@localhost bin]# /usr/local/lib/erlang/bin/start
但是我用的R12B5或者R13A发行版这样有点小问题 start没有运行起来, 我调查了半天发现有2个问题:
1. run_erl的log是设定在/usr/local/lib/erlang/log但是没有这个目录, 通过运行mkdir /usr/local/lib/erlang/log搞定
2. /usr/local/lib/erlang/releases/R13A/sys.config文件没有.
其中 R13A可能是R12B5.
通过运行echo "[]." > /usr/local/lib/erlang/releases/R13A/sys.config搞定
做了以上的步骤,现在运行
[root@localhost ~]# ps -ef|grep beam
root 19947 19946 0 03:35 pts/3 00:00:00 /usr/local/lib/erlang/erts-5.7/bin/beam.smp -- -root /usr/local/lib/erlang -progname start_erl -- -home /root -boot /usr/local/lib/erlang/releases/R13A/start -config /usr/local/lib/erlang/releases/R13A/sys
确认beam已经运行, 同时/tmp/目录下有erlang.pipe.1.r erlang.pipe.1.w 的pipe.
如果还没有运行起来 那么就看下 tail /var/log/syslog 查明出错原因
收获的时候到了
[root@localhost bin]# to_erl
Attaching to /tmp/erlang.pipe.3 (^D to exit)
1>
1>
1>
看到熟悉的shell提示符号了。退出的时候记得用^D, 而不是^C.
/*
* Module: run_erl.c
*
* This module implements a reader/writer process that opens two specified
* FIFOs, one for reading and one for writing; reads from the read FIFO
* and writes to stdout and the write FIFO.
*
________ _________
| |--<-- pipe.r (fifo1) --<--| |
| to_erl | | run_erl | (parent)
|________|-->-- pipe.w (fifo2) -->--|_________|
^ master pty
|
| slave pty
____V____
| |
| "erl" | (child)
|_________|
run_erl和to_erl是通用的pipe封装器 我们也可以这样用:
/usr/local/lib/erlang/bin/run_erl -daemon /tmp/ /tmp/log "exec lua"
to_erl
这时候我们看到的是 lua的shell
本文详细介绍了如何在后台运行的Erlang系统中进行控制操作,包括使用JCL或-remsh接入节点,以及解决启动过程中遇到的问题。提供了从检查erl系统安装路径到启动beam进程的完整流程,并附上了使用run_erl和to_erl命令的实例。
4916

被折叠的 条评论
为什么被折叠?



