Command line options

It is possible to skip the GUI and start web2py directly from the command line by typing something like:

  1. python web2py.py -a 'your password' -i 127.0.0.1 -p 8000

When web2py starts, it creates a file called “parameters_8000.py” where it stores the hashed password. If you use ““ as the password, web2py prompts you for it.

For additional security, you can start web2py with:

  1. python web2py.py -a '<recycle>' -i 127.0.0.1 -p 8000

In this case web2py reuses the previously stored hashed password. If no password is provided, or if the “parameters_8000.py” file is deleted, the web-based administrative interface is disabled.

On some Unix/Linux systems, if the password is

  1. <pam_user:some_user>

web2py uses the PAM password of the Operating System account of some_user to authenticate the administrator, unless blocked by the PAM configuration.

web2py normally runs with CPython (the C implementation of the Python interpreter created by Guido van Rossum), but it can also run with PyPy and Jython. The latter possibility allows the use of web2py in the context of a Java EE infrastructure. To use Jython, simply replace “python web2py.py …” with “jython web2py.py …”.

The “web2py.py” script can take many command-line arguments specifying the maximum number of threads, enabling of SSL, etc. For a complete list type:

  1. >>> python web2py.py -h
  2. Usage: python web2py.py
  3. web2py Web Framework startup script. ATTENTION: unless a password
  4. is specified (-a 'passwd'), web2py will attempt to run a GUI.
  5. In this case command line options are ignored.
  6. Options:
  7. --version show program's version number and exit
  8. -h, --help show this help message and exit
  9. -i IP, --ip=IP IP address of the server (e.g., 127.0.0.1 or ::1);
  10. Note: This value is ignored when using the
  11. 'interfaces' option.
  12. -p PORT, --port=PORT port of server (8000)
  13. -a PASSWORD, --password=PASSWORD
  14. password to be used for administration (use -a
  15. "<recycle>" to reuse the last password))
  16. -c SSL_CERTIFICATE, --ssl_certificate=SSL_CERTIFICATE
  17. file that contains ssl certificate
  18. -k SSL_PRIVATE_KEY, --ssl_private_key=SSL_PRIVATE_KEY
  19. file that contains ssl private key
  20. --ca-cert=SSL_CA_CERTIFICATE
  21. Use this file containing the CA certificate to
  22. validate X509 certificates from clients
  23. -d PID_FILENAME, --pid_filename=PID_FILENAME
  24. file to store the pid of the server
  25. -l LOG_FILENAME, --log_filename=LOG_FILENAME
  26. file to log connections
  27. -n NUMTHREADS, --numthreads=NUMTHREADS
  28. number of threads (deprecated)
  29. --minthreads=MINTHREADS
  30. minimum number of server threads
  31. --maxthreads=MAXTHREADS
  32. maximum number of server threads
  33. -s SERVER_NAME, --server_name=SERVER_NAME
  34. server name for the web server
  35. -q REQUEST_QUEUE_SIZE, --request_queue_size=REQUEST_QUEUE_SIZE
  36. max number of queued requests when server unavailable
  37. -o TIMEOUT, --timeout=TIMEOUT
  38. timeout for individual request (10 seconds)
  39. -z SHUTDOWN_TIMEOUT, --shutdown_timeout=SHUTDOWN_TIMEOUT
  40. timeout on shutdown of server (5 seconds)
  41. --socket-timeout=SOCKET_TIMEOUT
  42. timeout for socket (5 second)
  43. -f FOLDER, --folder=FOLDER
  44. location of the applications folder (also known as directory)
  45. -v, --verbose increase --test verbosity
  46. -Q, --quiet disable all output
  47. -D DEBUGLEVEL, --debug=DEBUGLEVEL
  48. set debug output level (0-100, 0 means all, 100 means
  49. none; default is 30)
  50. -S APPNAME, --shell=APPNAME
  51. run web2py in interactive shell or IPython (if
  52. installed) with specified appname (if app does not
  53. exist it will be created). APPNAME like a/c/f (c,f
  54. optional)
  55. -B, --bpython run web2py in interactive shell or bpython (if
  56. installed) with specified appname (if app does not
  57. exist it will be created). Use combined with --shell
  58. -P, --plain only use plain python shell; should be used with
  59. --shell option
  60. -M, --import_models auto import model files; default is False; should be
  61. used with --shell option
  62. -R PYTHON_FILE, --run=PYTHON_FILE
  63. run PYTHON_FILE in web2py environment; should be used
  64. with --shell option
  65. -K SCHEDULER, --scheduler=SCHEDULER
  66. run scheduled tasks for the specified apps: expects a
  67. list of app names as -K app1,app2,app3 or a list of
  68. app:groups as -K app1:group1:group2,app2:group1 to
  69. override specific group_names. (only strings, no
  70. spaces allowed. Requires a scheduler defined in the
  71. models
  72. -X, --with-scheduler run schedulers alongside webserver
  73. -T TEST_PATH, --test=TEST_PATH
  74. run doctests in web2py environment; TEST_PATH like
  75. a/c/f (c,f optional)
  76. -C, --cron trigger a cron run manually; usually invoked from a
  77. system crontab
  78. --softcron triggers the use of softcron
  79. -Y, --run-cron start the background cron process
  80. -J, --cronjob identify cron-initiated command
  81. -L CONFIG, --config=CONFIG
  82. config file
  83. -F PROFILER_DIR, --profiler=PROFILER_DIR
  84. profiler dir
  85. -t, --taskbar use web2py gui and run in taskbar (system tray)
  86. --nogui text-only, no GUI
  87. -A ARGS, --args=ARGS should be followed by a list of arguments to be passed
  88. to script, to be used with -S, -A must be the last
  89. option
  90. --no-banner Do not print header banner
  91. --interfaces=INTERFACES
  92. listen on multiple addresses: "ip1:port1:key1:cert1:ca
  93. _cert1;ip2:port2:key2:cert2:ca_cert2;..."
  94. (:key:cert:ca_cert optional; no spaces; IPv6 addresses
  95. must be in square [] brackets)
  96. --run_system_tests runs web2py tests

Please note:

  • The option -W, used to install a Windows service, has been removed. Please see nssm in Chapter 13.
  • Profiler output can be analyzed using runsnakerun tool.

Lower-case options are used to configure the web server. The -L option tells web2py to read configuration options from a file, while -S, -P and -M options start an interactive Python shell. The -T option finds and runs controller doctests in a web2py execution environment. For example, the following example runs doctests from all controllers in the “welcome” application:

  1. python web2py.py -vT welcome