Home > Erlang探索, 网络编程 > init_debug查看系统boot过程

init_debug查看系统boot过程

June 24th, 2013

原创文章,转载请注明: 转载自系统技术非业余研究

本文链接地址: init_debug查看系统boot过程

erl启动的时候有个参数 -init_debug 作用是

Makes init write some debug information while interpreting the boot script.

参见erlang system_principles的1.3节:Boot Scripts, 我们可以知道,每个erlang vm启动的时候,init进程都会去读取boot文件,来获取系统要启动那些服务。

如果我们不输入任何参数的话,,默认是其他start_clean.boot文件, 其内容如下:

$ cat ~/otp/erts/start_scripts/start_clean.script
%% script generated at {2012,12,26} {16,12,32}
{script,
    {"OTP  APN 181 01","R15B03"},
    [{preLoaded,
         [erl_prim_loader,erlang,init,otp_ring0,prim_file,prim_inet,prim_zip,
          zlib]},
     {progress,preloaded},
     {path,["$ROOT/lib/kernel-2.15.3/ebin","$ROOT/lib/stdlib-1.18.3/ebin"]},
     {primLoad,[error_handler]},
     {kernel_load_completed},
     {progress,kernel_load_completed},
     {path,["$ROOT/lib/kernel-2.15.3/ebin"]},
     {primLoad,
         [application,application_controller,application_master,
          application_starter,auth,code,code_server,disk_log,disk_log_1,
          disk_log_server,disk_log_sup,dist_ac,dist_util,erl_boot_server,
          erl_ddll,erl_distribution,erl_epmd,erl_reply,error_logger,
          erts_debug,file,file_io_server,file_server,gen_sctp,gen_tcp,gen_udp,
          global,global_group,global_search,group,heart,hipe_unified_loader,
          inet,inet6_sctp,inet6_tcp,inet6_tcp_dist,inet6_udp,inet_config,
          inet_db,inet_dns,inet_gethost_native,inet_hosts,inet_parse,inet_res,
          inet_sctp,inet_tcp,inet_tcp_dist,inet_udp,kernel,kernel_config,net,
          net_adm,net_kernel,os,packages,pg2,ram_file,rpc,seq_trace,
          standard_error,user,user_drv,user_sup,wrap_log_reader]},
     {path,["$ROOT/lib/stdlib-1.18.3/ebin"]},
     {primLoad,
         [array,base64,beam_lib,binary,c,calendar,dets,dets_server,dets_sup,
          dets_utils,dets_v8,dets_v9,dict,digraph,digraph_utils,edlin,
          edlin_expand,epp,erl_bits,erl_compile,erl_eval,erl_expand_records,
          erl_internal,erl_lint,erl_parse,erl_posix_msg,erl_pp,erl_scan,
          erl_tar,error_logger_file_h,error_logger_tty_h,escript,ets,
          eval_bits,file_sorter,filelib,filename,gb_sets,gb_trees,gen,
          gen_event,gen_fsm,gen_server,io,io_lib,io_lib_format,io_lib_fread,
          io_lib_pretty,lib,lists,log_mf_h,math,ms_transform,orddict,ordsets,
          otp_internal,pg,pool,proc_lib,proplists,qlc,qlc_pt,queue,random,re,
          sets,shell,shell_default,slave,sofs,string,supervisor,
          supervisor_bridge,sys,timer,unicode,win32reg,zip]},
     {progress,modules_loaded},
     {path,["$ROOT/lib/kernel-2.15.3/ebin","$ROOT/lib/stdlib-1.18.3/ebin"]},
     {kernelProcess,heart,{heart,start,[]}},
     {kernelProcess,error_logger,{error_logger,start_link,[]}},
     {kernelProcess,application_controller,
         {application_controller,start,
             [{application,kernel,
                  [{description,"ERTS  CXC 138 10"},
                   {vsn,"2.15.3"},
                   {id,[]},
                   {modules,
                       [application,application_controller,application_master,
                        application_starter,auth,code,packages,code_server,
                        dist_util,erl_boot_server,erl_distribution,erl_reply,
                        error_handler,error_logger,file,file_server,
                        file_io_server,global,global_group,global_search,
                        group,heart,hipe_unified_loader,inet6_tcp,
                        inet6_tcp_dist,inet6_udp,inet6_sctp,inet_config,
                        inet_hosts,inet_gethost_native,inet_tcp_dist,kernel,
                        kernel_config,net,net_adm,net_kernel,os,ram_file,rpc,
                        user,user_drv,user_sup,disk_log,disk_log_1,
                        disk_log_server,disk_log_sup,dist_ac,erl_ddll,
                        erl_epmd,erts_debug,gen_tcp,gen_udp,gen_sctp,inet,
                        inet_db,inet_dns,inet_parse,inet_res,inet_tcp,
                        inet_udp,inet_sctp,pg2,seq_trace,standard_error,
                        wrap_log_reader]},
                   {registered,
                       [application_controller,erl_reply,auth,boot_server,
                        code_server,disk_log_server,disk_log_sup,
                        erl_prim_loader,error_logger,file_server_2,
                        fixtable_server,global_group,global_name_server,heart,
                        init,kernel_config,kernel_sup,net_kernel,net_sup,rex,
                        user,os_server,ddll_server,erl_epmd,inet_db,pg2]},
                   {applications,[]},
                   {included_applications,[]},
                   {env,[{error_logger,tty}]},
                   {maxT,infinity},
                   {maxP,infinity},
                   {mod,{kernel,[]}}]}]}},
     {progress,init_kernel_started},
     {apply,
         {application,load,
             [{application,stdlib,
                  [{description,"ERTS  CXC 138 10"},
                   {vsn,"1.18.3"},
                   {id,[]},
                   {modules,
                       [array,base64,beam_lib,binary,c,calendar,dets,
                        dets_server,dets_sup,dets_utils,dets_v8,dets_v9,dict,
                        digraph,digraph_utils,edlin,edlin_expand,epp,
                        eval_bits,erl_bits,erl_compile,erl_eval,
                        erl_expand_records,erl_internal,erl_lint,erl_parse,
                        erl_posix_msg,erl_pp,erl_scan,erl_tar,
                        error_logger_file_h,error_logger_tty_h,escript,ets,
                        file_sorter,filelib,filename,gb_trees,gb_sets,gen,
                        gen_event,gen_fsm,gen_server,io,io_lib,io_lib_format,
                        io_lib_fread,io_lib_pretty,lib,lists,log_mf_h,math,
                        ms_transform,orddict,ordsets,otp_internal,pg,pool,
                        proc_lib,proplists,qlc,qlc_pt,queue,random,re,sets,
                        shell,shell_default,slave,sofs,string,supervisor,
                        supervisor_bridge,sys,timer,unicode,win32reg,zip]},
                   {registered,
                       [timer_server,rsh_starter,take_over_monitor,
                        pool_master,dets]},
                   {applications,[kernel]},
                   {included_applications,[]},
                   {env,[]},
                   {maxT,infinity},
                   {maxP,infinity}]}]}},
     {progress,applications_loaded},
     {apply,{application,start_boot,[kernel,permanent]}},
     {apply,{application,start_boot,[stdlib,permanent]}},
     {apply,{c,erlangrc,[]}},
     {progress,started}]}.

而boot文件是script文件的term_to_binary版本,演示下init加载过程:

$ erl -init_debug
{progress,preloaded}
{progress,kernel_load_completed}
{progress,modules_loaded}
{start,heart}
{start,error_logger}
{start,application_controller}
{progress,init_kernel_started}
{apply,{application,load,[{application,stdlib,[{description,"ERTS  CXC 138 10"},{vsn,"1.19.1"},{id,[]},{modules,[array,base64,beam_lib,binary,c,calendar,dets,dets_server,dets_sup,dets_utils,dets_v8,dets_v9,dict,digraph,digraph_utils,edlin,edlin_expand,epp,eval_bits,erl_bits,erl_compile,erl_eval,erl_expand_records,erl_internal,erl_lint,erl_parse,erl_posix_msg,erl_pp,erl_scan,erl_tar,error_logger_file_h,error_logger_tty_h,escript,ets,file_sorter,filelib,filename,gb_trees,gb_sets,gen,gen_event,gen_fsm,gen_server,io,io_lib,io_lib_format,io_lib_fread,io_lib_pretty,lib,lists,log_mf_h,math,ms_transform,orddict,ordsets,otp_internal,pg,pool,proc_lib,proplists,qlc,qlc_pt,queue,random,re,sets,shell,shell_default,slave,sofs,string,supervisor,supervisor_bridge,sys,timer,unicode,win32reg,zip]},{registered,[timer_server,rsh_starter,take_over_monitor,pool_master,dets]},{applications,[kernel]},{included_applications,[]},{env,[]},{maxT,infinity},{maxP,infinity}]}]}}
{progress,applications_loaded}
{apply,{application,start_boot,[kernel,permanent]}}
Erlang R16B (erts-5.10.1) [source] [64-bit] [smp:16:16] [async-threads:10] [hipe] [kernel-poll:false]

{apply,{application,start_boot,[stdlib,permanent]}}
{apply,{c,erlangrc,[]}}
{progress,started}
Eshell V5.10.1  (abort with ^G)
1> 

当然如果只是简单的boot不会有什么问题,但是真实地情况是reltool在打包的时候,会把 xxx.app 文件里面,依赖的application都打进去,顺便启动起来。
比如:

{applications,[kernel,stdlib,sasl,os_mon,mnesia,ump_lib,ump_log,
ump_zk,ump_mq]}]}.

我们在填写.app文件的时候,可能会漏掉几个,结果发现系统不正常运作,这时候init_debug就能帮上大忙。
摘抄一段诊断:

{running_on_load_handler,ump_la_nifs}
ump_la_nifs on load result: ok
{on_load_handler_returned_ok,ump_la_nifs}
{running_on_load_handler,dyntrace}
{on_load_handler_returned_ok,dyntrace}
{running_on_load_handler,erlsha2}
{on_load_handler_returned_ok,erlsha2}
{running_on_load_handler,crypto}
{on_load_handler_returned_ok,crypto}
{running_on_load_handler,asn1rt_nif}
{on_load_handler_returned_ok,asn1rt_nif}
{apply,{application,start_boot,[stdlib,permanent]}}
{apply,{application,start_boot,[sasl,permanent]}}
{apply,{application,start_boot,[os_mon,permanent]}}
{apply,{application,start_boot,[mnesia,permanent]}}

=INFO REPORT==== 24-Jun-2013::17:24:34 ===
alarm_handler: {set,{{disk_almost_full,”/usr”},[]}}

=ERROR REPORT==== 24-Jun-2013::17:24:34 ===
Mnesia(‘rds2tae@10.232.64.75’): ** ERROR ** mnesia_event got {inconsistent_database, starting_partitioned_network, ‘rds2tae@10.232.64.74’}

=ERROR REPORT==== 24-Jun-2013::17:24:34 ===
Mnesia(‘rds2tae@10.232.64.75’): ** ERROR ** mnesia_event got {inconsistent_database, starting_partitioned_network, ‘rds2tae@10.232.64.76’}
{apply,{application,start_boot,[ump_lib,permanent]}}
{apply,{application,start_boot,[lager,permanent]}}
{apply,{application,start_boot,[syslog,permanent]}}
{apply,{application,start_boot,[ump_log,permanent]}}
17:24:34.755 [info] Application lager started on node ‘rds2tae@10.232.64.75’
{apply,{application,start_boot,[erlzk,permanent]}}
{apply,{application,start_boot,[ump_zk,permanent]}}

我们很清楚的看到,这些依赖的application是如何启动的,按照什么样的顺序。问题马上就能定位出来。

祝玩的开心。

Post Footer automatically generated by wp-posturl plugin for wordpress.

Categories: Erlang探索, 网络编程 Tags:
Comments are closed.