During window debugging, we can start multiple cmd windows to run the Erlang node. in the production environment, we need the Erlang service to run in the background on the centos server; in this case, you need to add the detached parameter at startup to exit the terminal:
-DetachedStarts the Erlang runtime system detached from the system console. Useful for running daemons and backgrounds processes. implies-noinput.
For our own services, even if we deploy them in the production environment, we must make sure that we are "Flying knives like magicians, but they have not been released ", you still need to enter the Erlang background process in some ways to do some work, such as viewing the runtime information (memory, number of processes, etc.) of an Erlang node, so that the service can exit gracefully rather than kill the process, or perform a hot update (see [Erlang 0010] Erlang hot update. Of course, reloader can be used for hot update. erl solution to simplify); At the beginning, there were fewer servers, and we used jcl to process them;
Erlang shell jcl
Jcl is a running mode of Erlang shell, namely job control mode (jcl, in which jobs can be started, killed, detached and connected). We start two nodes to complete this operation;
Add remarks on February 14,: The following experiment is completed under linux, and werl.exe is started on jcl.exe under windows.
Node_1Added the-detached option. After startup, it runs directly in the background and does not start the shell.
Erl-setcookie ABC-name node_1@192.168.1.123-detached
Node_2The same cookie as node_1 is used. After the cookie is started, the Erlang Shell Interface is displayed.
Erl-setcookie ABC-name node_2@192.168.1.123
Below we start to drill jcl in node_2@192.168.1.123:
Eshell v5.9 (abort with ^ g)
(Node_2@192.168.1.123) 1> node (). % current this is in node_2
'Node_2@192.168.1.123'
(Node_2@192.168.1.123) 2> % Ctrl + G into jcl Mode
User Switch command
--> H
C [NN]-connect to job
I [NN]-interrupt job
K [NN]-kill job
J-list all jobs
S [Shell]-start local shell
R [node [Shell]-start remote shell
Q-Quit Erlang
? | H-this message
--> R'node _ 1@192.168.1.123 '% try to connect to the node_1@192.168.1.123
--> J
1 {shell, start, [init]} % list all jobs
2*{'node_1@192.168.1.123 ', Shell, start, []}
--> C 2% here 2 is the job number, switch to job 2
Eshell v5.9 (abort with ^ g)
(Node_1@192.168.1.123) 1> node (). % note that the prompt is already in node_1
'Node_1@192.168.1.123'
(Node_1@192.168.1.123) 2> Erlang: Now ().
{1326,801888, 347570}
(Node_1@192.168.1.123) 3> % again Ctrl + G
User Switch command
--> J
1 {shell, start, [init]}
2*{'node_1@192.168.1.123 ', Shell, start, []}
--> Switch from C 1% to Job 1
(Node_2@192.168.1.123) 2> node (). % note the prompt, we have returned to node_2
'Node_2@192.168.1.123'
Node_2@192.168.1.123 3>
Is it a bit of a dream to switch back and forth in this way? Can it be simpler, for example, directly accessing node_1? With-RemshThe parameter can be
Let's see-the remsh description is exactly what we need:
If you want an Erlang node to have a remote job active from the start (rather than the default local job), you start Erlang with the-remsh flag. example: Erl-sname this_node-remsh other_node @ other_host
Try it out:
Erl-setcookie ABC-name node_3@192.168.1.123-remsh node_1@192.168.1.123 % so that the node_1 node is directly entered
Note::Directly go to node_1. After the operation is completed, what should I do if I want to exit?If you execute Q (). node_1 here, the node will die;
The correct method is to press Ctrl + G to enter jcl mode and run the Q command to exit. Run PS aux | grep node to check whether the process is still running.
This method is mentioned on the ejabberd website.
[1] attach an Erlang shell to an already running ejabberd process http://www.ejabberd.im/tricks
[2] interconnecting Erlang nodes http://www.ejabberd.im/interconnect-erl-nodes
Another practical method for accessing the Erlang Console
Address: http://mryufeng.iteye.com/blog/362394Powered by mryufeng
According to the mryufeng leader's method, the drill was successful. In the middle,/usr/local/lib/Erlang/bin/start failed to start, which is also a problem of missing directories and configuration files.
Mkdir/usr/local/lib/Erlang/log
Echo "[].">/usr/local/lib/Erlang/releases/r15b/sys. config
Stackoverflow problems: how to create deamon program with Erlang? Http://stackoverflow.com/questions/5972811/how-to-create-deamon-program-with-erlang
For details, see:
Erl_call as the number of servers increases, it is a little troublesome to log on to a server and then use jcl for hot updates, the alternative solution is to log on to each server through SSH and then send messages to the Erlang node on the server to execute hot updates (of course not limited to hot updates ); here is a very powerful tool that can be used: erl_call; The design goal of the erl_call module is to use Unix shell scripts to interact with distributed Erlang nodes, erl_call can start or connect to a distributed Erlang node for simple method calls or even execution of expression sequences. erl_call is built on erl_interface and interacts with Erlang's Rex server through standard RPC calls, no additional tools are required. note Erlang node RPC service when the registration name is Rex http://www.google.com/codesearch#dNzC48WMK6w/lib/kernel/src/rpc.erl&q=rpc%20lang:erlang&type=cs to see erl_call help, pay attention to Erlang versions of erl_call paths are also different:
Usage:/usr/local/lib/Erlang/lib/erl_interface-3.7.6/bin/erl_call [-[demqclr] [-C cookie] [-H hiddenname]
[-X erlscript] [-A [mod [fun [ARGs]
(-N node |-sname node |-Name node)
Where:-A apply (mod, fun, argS) (e. g-A 'erlang length [[a, B, c]'
-C cookie string; by default read from ~ /. Erlang. Cookie
-D direct Erlang output ~ /. Erl_call.out. <nodename>
-E evaluate contents of standard input (e. g echo "x = 1, y = 2, {x, y}." | erl_call-e ...)
-H specify a name for the erl_call client Node
-M read and compile Erlang module from stdin
-N name of Erlang node, same as-name
-Name of Erlang node, expanded to a fully qualified
-Sname name of Erlang node, short form will be used
-Q halt the Erlang node (overrides the-s switch)
-R use a random name for the erl_call client Node
-S start a new Erlang node if necessary
-V verbose mode, I. e print some information on stderr
-X use specified ERL start script, default is ERL
Simple translation:
-A executionErlang: Apply/3. You must provide M f a, m is required, F default value start, a default value []. Note that this flag only accepts one parameter, therefore, it is best to organize M f A by adding parentheses.
-C: Use the cookie value if it is not specified ~ /. Erlang. The cookie defined in the cookie file must have the same cookie for communications between Erlang nodes. -D debugging mode;All Io will be output ~ /. Erl_call.out.nodename file, where nodename is the name of the Erlang node to be processed;
-ERead a series of Erlang expressions and return the results of the last expression. These expressions are separated by commas ,'. 'End, this Erlang shell is consistent. CTRL + D is used to end the input. If the input is successful, {OK, result} is returned }.
-HHiddenname: hides the node represented by erl_call.
-MRead and compile a module
-N -Name -SnameSelect one of the three parameters. The meaning of name and N is the same for the sake of compatibility, and the short name of sname code
-QStop an Erlang Node
-RGenerate a random name for erl_call
-SIf necessary, start an Erlang distributed node, which means that the first call will start an Erlang node, and subsequent calls will be much faster.
-VPrint more redundant information
-X erlscript: Specify the Erlang STARTUP script. If not specified, use the Erl start-up script. For example, we want to get the memory information of node node_1/usr/local/lib/Erlang/lib/erl_interface-3.7.6/bin/erl_call. -S-A 'erlang memory '-name node_1@192.168.1.123-c abc practices encounter two problems:
Question 1: An error will be reported when the name contains an IP address. This Erlang Forum also mentioned: erl_call can now use an IP address for remote node name authentication remove get_hostent authentication;
Question 2: When the-e parameter is used, how to end the input and view the results is indeed quite a problem, because you did not carefully read the document, you need to use Ctrl + D at the end, http://www.erlang.org/doc/man/erl_call.html/usr/local/lib/Erlang/lib/erl_interface-3.7.6/bin/erl_call-e-name node_1@192.168.1.123-c abca = 1,
B = 2,
C = a + B.
% Ctrl + d
{OK, 3} with these methods, we can easily understand and control the running Erlang node, and feel happy! Happy spring festival !!!