NaviServer Command Mode

https://web.archive.org/web/20161211211830/naviserver.sourceforge.net/ns_logobig.gif

MainSource Code Downloads API Documentation Mailing Lists Bugs Developers


Usually when you start the NaviServer it forks into the background and logs messages to the error log. You may use the -f option to start the server in the foreground and have log messages sent to stdout (your screen, perhaps).

Now you can also start the server in command mode with the -c option, in which case after the initial log messages are printed to your screen, a prompt will appear. You can use this exactly as you would a tclsh prompt -- type in Tcl commands and the result is printed back. All of the NaviServer commands are available, but unlike simply loading libnsd.so into a tclsh, you have a fully-fledged running server which is listening on ports and serving web requests.

A quick example. The server is started and two commands are issued: [ns_info threads] and [ns_info requestprocs].

  buckel@tulpe:/usr/local/ns/bin> ./nsd -c -u nsadmin -g www -t ../sample-config.tcl

  [-main-] Notice: nsmain: NaviServer/4.99.1 starting
  [-main-] Notice: nsmain: security info: uid=500, euid=500, gid=100, egid=100
  [-main-] Notice: nsmain: max files: FD_SETSIZE = 1024, rl_cur = 1024, rl_max = 1024
  [-main-] Notice: adp[server1]: mapped {GET HEAD POST} /*.adp
  [-main-] Notice: adp[server1]: mapped {GET HEAD POST} /*.u_adp
  [-main-] Notice: adp[server1]: mapped {GET HEAD POST} /*.gb_adp
  [-main-] Notice: adp[server1]: mapped {GET HEAD POST} /*.sjis_adp
  [-main-] Notice: modload: loading '/usr/local/ns/bin/nssock.so'
  [-main-] Notice: modload: loading '/usr/local/ns/bin/nslog.so'
  [-main-] Notice: nslog: opened '/usr/local/ns/servers/server1/modules/nslog/access.log'
  [-main-] Notice: conf: [ns/server/server1]enabletclpages = 0
  [-main-] Notice: nsmain: NaviServer/4.99.1 running
  [-main-] Notice: nsmain: security info: uid=500, euid=500, gid=100, egid=100
  [-sched-] Notice: sched: starting
  [-main-] Notice: nssock: listening on 10.0.0.100:8000
  [-driver-] Notice: starting
  [-driver-] Notice: driver: accepting connections

  % join [ns_info threads] \n
  -driver- -main- 1084140464 0 1119862183 p:0x40037cfb a:0x0
  -sched- -main- 1082039216 0 1119862183 p:0x4004a09a a:0x0
  -main- {} 1076887680 1 1119862183 p:0x0 a:0x0

  % join [ns_info requestprocs] \n
  server1 GET / *.u_adp inherit ns:adppage 0:0 {} {}
  server1 HEAD / *.u_adp inherit ns:adppage 0:0 {} {}
  server1 POST / *.u_adp inherit ns:adppage 0:0 {} {} 
  server1 GET / *.sjis_adp inherit ns:adppage 0:0 {} {}
  server1 HEAD / *.sjis_adp inherit ns:adppage 0:0 {} {}
  server1 POST / *.sjis_adp inherit ns:adppage 0:0 {} {}
  server1 GET / *.gb_adp inherit na:adppage 0:0 {} {}
  server1 HEAD / *.gb_adp inherit ns:adppage 0:0 {} {}
  server1 POST / *.gb_adp inherit ns:adppage 0:0 {} {}
  server1 GET / *.adp inherit ns:adppage 0:0 {} {}
  server1 HEAD / *.adp inherit ns:adppage 0:0 {} {}
  server1 POST / *.adp inherit ns:adppage 0:0 {} {}
  server1 GET / * inherit ns:fastget a:(nil)
  server1 HEAD / * inherit ns:fastget a:(nil)
  server1 POST / * inherit ns:fastget a:(nil)

  %

NB: Command Mode is great for testing and exploration. If you need to explore or control a running server in production then the control port[L1 ], which presents a shell prompt over a telnet interface, is what you are looking for.