一種以standalone方式啟動erlang應用的方法

來源:互聯網
上載者:User

轉載:http://cryolite.iteye.com/blog/383927

 

就像普通java應用一樣啟動一個erlang虛擬機器,程式在虛擬機器上運行,沒有互動介面。

一個辦法是啟動時帶 -detached參數,這樣erlang虛擬機器就進入了所謂的detached模式,在detached模式中,erlang靜悄悄的在背後運行,沒有常見的那個互動終端介面。

例子:以detached模式啟動一個my_app應用

Shell代碼  
  1. erl -detached -name foo@192.168.1.103 -setcookie abc -s my_app  
erl -detached -name foo@192.168.1.103 -setcookie abc -s my_app

my_app就像普通的daemon應用一樣在背後運行了

但是當要控制detached模式啟動的erlang虛擬機器時怎麼辦,比如退出應用,或者查看erlang應用狀態等。

串連detached模式的erlang節點的方法就我所知有兩種:

1。 通過遠程shell JCL登入,在Programming Erlang的6.7.3節介紹了這個,簡單的說就是ctrl+g後的那個shell介面。具體方法是:
i) 啟動一個erlang節點:

Shell代碼  
  1. erl -name bar@192.168.1.103 -setcookie abc  
erl -name bar@192.168.1.103 -setcookie abc

ii) ctrl+g進入shell JCL,然後遠端連線detached模式的erlang:

Erlang shell代碼  
  1. --> r 'foo@192.168.1.103'  
  2. --> c   
  3. Eshell V5.7.1  (abort with ^G)   
  4. (foo@192.168.1.103)1>   
--> r 'foo@192.168.1.103'--> cEshell V5.7.1  (abort with ^G)(foo@192.168.1.103)1> 

就可以控制detached模式的erlang了

2。使用erl的-remsh參數

Shell代碼  
  1. erl -name bar@192.168.1.103 -remsh foo@192.168.1.103 -setcookie abc  
erl -name bar@192.168.1.103 -remsh foo@192.168.1.103 -setcookie abc

但這樣attach上後不知道怎麼恢複到原來的detached模式

個人覺得shell JCL的方式比較好,如果有多個detached模式的Erlang節點(不管是不是遠端),都可以用一個Erlang shell進行控制,有點screen的感覺了,呵呵。

detached模式比較符合我們常用的erlang啟動方法。在mryufeng的另一種實用的接入erlang控制台的方法中提到的方法也蠻好的說,但不知道可不可以遠程接入。

嗯,先記下

註:
帶-detached參數的啟動可能等效於同時帶-noshell和-noinput參數的啟動,用

Linux shell代碼  
  1. ps -ef|grep beam  
ps -ef|grep beam

查看-detached啟動的erlang進程時就會發現包含了-noshell -noinput這倆參數。

參考資料
1. Detached mode
2.erl
3. How to start an erlang applications from the command line non-interactively?

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.