0
votes

I am new to Erlang.

Currently, I create a module that help me to forward the user request to an apns library.

I create a gen_server module and add it to a supervisor.

Today, when I start my module with erl -sname apns_server.

Everything work fine. But dues to I suspend the terminal for a while, the connection was closed by server.

Then the problem happened. I can's start a new erl -sname apns_server after a new connection to server.

The error message said there is already an apns_server exist. And I did see the server name in epmd -names.

The node did alive because I can send request by rpc:call to run the request. But I don't know how to stop it!!

Dues to the module is still under developing, I need update some codes then restart it. How can I do this? Dues to there are other Erlang service running on the same machine, I can't reboot the system. Are there other way to stop my module's Erlang node? Thank you~~

Eric

1

1 Answers

2
votes

To connect to your existing node:

  1. ssh to your server.
  2. Start a new Erlang node + shell session with a new name but the same cookie as the node you want to contact (erl -name some_name -cookie some_cookie).
  3. From the new Erlang shell press ^G (that is, CTRL+G) to open the terminal command interface.
  4. Enter the command string r [email protected] to connect to the other node remotely.
  5. Press j to list the current jobs. The new shell spawned on the node you are trying to contact will be listed.
  6. Enter c [the remote shell's job number] to connect to the new shell on the node you want to use.

Here is my first node, called '[email protected]':

ceverett@changa:~$ erl -name foo -cookie bar
Erlang/OTP 20 [RELEASE CANDIDATE 2] [erts-9.0] [source] [64-bit] [smp:2:2] [ds:2:2:10] [async-threads:10] [hipe] [kernel-poll:false]

Eshell V9.0  (abort with ^G)
([email protected])1>

Here is my second node, called '[email protected]' that I will use to start a remote shell connection to the other. Note that I have started this erl session with the same cookie (the option -cookie bar) as above:

ceverett@changa:~$ erl -name baz -cookie bar
Erlang/OTP 20 [RELEASE CANDIDATE 2] [erts-9.0] [source] [64-bit] [smp:2:2] [ds:2:2:10] [async-threads:10] [hipe] [kernel-poll:false]

Eshell V9.0  (abort with ^G)
([email protected])1>
User switch command
 --> ?
  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 '[email protected]'
 --> j
   1  {shell,start,[init]}
   2* {'[email protected]',shell,start,[]}
 --> c 2
Eshell V9.0  (abort with ^G)
([email protected])1>

Notice how my prompt changed at the bottom? That's all there is to it.

This works between any Erlang nodes that are connected in a cluster, and with EPMD running using long node names remote nodes will try to connect to one another if they are able to see each other on the network. In this case both nodes are running on the same host, but as long as hosts can see each other on the network it works the same way.