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 "<ask>" 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.

WEB2PY: Enterprise Web Framework /2nd Ed.. By Massimo Di Pierro 93

Copyright © 2009

web2py normally runs with CPython (the C implementation of the Python interpreter created by Guido van Rossum), but it can also run with Jython (the Ja va implementation of the interpreter). The latter possibility allows the use of web2py in the context of a J2EE infrastructure. To use Jython, simply replace "python web2py.py... "with "jython web2py.py". Details about installing Jython, zxJDBC modules required to access the databases can be found in Chapter 12.

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:

2 Usage: python web2py.py

4 web2py Web Framework startup script. ATTENTION: unless a password

5 is specified (-a 'passwd'), web2py will attempt to run a GUI.

6 In this case command line options are ignored.

8 Options:

9 --version show program's version number and exit

10 -h, --help show this help message and exit

11 -i IP, --ip=IP ip address of the server (127.0.0.1)

13 -a PASSWORD, --password=PASSWORD

14 password to be used for administration

15 use -a "<recycle>" to reuse the last

16 password

17 -u UPGRADE, --upgrade = UPGRADE

18 -u yes: upgrade applications and exit

19 -c SSL_CERTIFICATE, --ssl_certificate=SSL_CERTIFICATE

20 file that contains ssl certificate

21 -k SSL_PRIVATE_KEY, - -ssl_private_key=SSL_PRIVATE_KEY

22 file that contains ssl private key

23 -d PID_FILENAME, - -pid_filename=PID_FILENAME

24 file to store the pid of the server

25 -1 LOG_FILENAME, - -log_filename=LOG_FILENAME

26 file to log connections

27 -n NUMTHREADS, --numthreads=NUMTHREADS

28 number of threads

29 -s SERVER_NAME, - -server_name=SERVER_NAME

30 server name for the web server

31 -q REQUEST_QUEUE_SIZE, --request_queue_size=REQUEST_QUEUE_SIZE

32 max number of queued requests when server unavailable

33 -o TIMEOUT, --timeout = TIMEOUT

34 timeout for individual request (10 seconds)

35 -z SHUTDOWN_TIMEOUT, - -shutdown_timeout=SHUTDOWN_TIMEOUT

36 timeout on shutdown of server (5 seconds)

38 folder from which to run web2py

39 -v, --verbose increase --test verbosity

40 -Q, --quiet disable all output

COMMAND LINE OPTIONS 95

-D DEBUGLEVEL, - -debug=DEBUGLEVEL

set debug output level (0-100, 0 means all, 100 means none; default is 30) -S APPNAME, - - shell =APPNAME

run web2py in interactive shell or IPython (if installed) with specified appname -P, --plain only use plain python shell; should be used with --shell option -M, --import_models auto import model files; default is False;

should be used with --shell option -R PYTHON_FILE, - -run=PYTHON_FILE

run PYTHON_FILE in web2py environment; should be used with --shell option -T TEST_PATH, - -test=TEST_PATH

run doctests in web2py environment; TEST_PATH like a/c/f (c,f optional) -W WINSERVICE, - -winservice = WINSERVICE

-W install\start\stop as Windows service -C, --cron trigger a cron run manually; usually invoked from a system crontab -N, --no-cron do not start cron automatically

config file

-F PROFILER_FILENAME, - -prof iler=PROFILER_FILENAME

profiler filename -t, --taskbar use web2py gui and run in taskbar

(system tray)

Lower-case options are used to configure the web server. The -l option tells web2py to read configuration options from a file, -w installs web2py as a windows service, 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

In the web2py folder there is a sample "options_std.py" configuration file for the internal web server:

1 import socket, os

4 password = '<recycle>' ### <recycle> means use the previous password

5 pid_filename = 'httpserver.pid'

6 log_filename = 'httpserver.log'

7 ssl_certificate = ' ' ### path to certificate file

8 ssl_private_key = '' ### path to private key file

9 numthreads = 10

10 server_name = socket.gethostname()

11 request_queue_size = 5

12 timeout = 10

13 shutdown_timeout = 5

60 61 62

66 67

This file contains the web2py defaults. If you edit this file, you need to import it explicitly with the -l command-line option.

Was this article helpful?

+1 0

Responses

  • p
    How to change request_queue_size python?
    8 years ago
  • mathias
    How to pass additional parameters to web2py server?
    8 years ago

Post a comment