Pyramid

Pyramid is an open source web application framework for Python.

Deploying an Existing Pyramid Project

To deploy a Pyramid project that has been developed outside of the WebFaction environment:

  1. Create a Pyramid application.

    1. Log in to the control panel.
    2. Click Domains / websites ‣ Applications. The list of applications appears.
    3. Click the Add new application button. The Create a new application form appears.
    4. In the Name field, enter a name for the application.
    5. In the App category menu, click to select Pyramid.
    6. In the App type menu, click to select the version of Pyramid to use.
    7. If applicable, in the Machine menu, click to select a web server.
    8. Click the Save button. The application is installed and appears in the list of applications.
    9. Make a note of the port number for the application. This number is required later in the installation process. The application’s port number appears next to the application’s type.
  2. Install the project.

    1. Open an SSH session to your account.
    2. Switch to the application directory. Enter cd $HOME/webapps/application and press Enter.
    3. Activate the Pyramid application’s environment. Enter source bin/activate and press Enter.
    4. Install the project. Enter easy_install -U myproject, where myproject is the name of the project package, and press Enter.
    5. Deactivate the Pyramid application’s environment. Enter deactivate and press Enter.
  3. Update development.ini.

    1. Open $HOME/webapps/application/project/development.ini in a text editor.

    2. In the [server:main] section, replace the line starting with port = with port = number where number is the port number provided for the application in the WebFaction control panel.

    3. Save and close the file.

    4. Switch to the application directory. Enter cd $HOME/webapps/application and press Enter.

    5. Create a symlink to development.ini. Enter ln -fs ./project/development.ini and press Enter.

      See also

      If you’re deploying an app to a non-root URL path (like example.com/myapp), see Serving Pyramid with a URL Prefix.

  4. Restart the Pyramid application.

To make the Pyramid application available on the Web, add the Pyramid application to a website record.

Serving Pyramid with a URL Prefix

To serve a Pyramid application at a non-root URL path:

  1. Open $HOME/webapps/application/myapp/development.ini (or production.ini, if your application uses it) in a text editor, where application is the name of the Pyramid application.

  2. At the end of the [app:main] section (by default, immediately before the [server:main] section), insert the following lines:

    filter-with = urlprefix
    
    [filter:urlprefix]
    use = egg:PasteDeploy#prefix
    prefix = URL_PATH
    

    where URL_PATH is the URL path where the application is to be served.

    For example, to serve the application at the /myapp URL path, insert the following lines:

    filter-with = urlprefix
    
    [filter:urlprefix]
    use = egg:PasteDeploy#prefix
    prefix = /myapp
    
  3. Save and close the file.

  4. Restart the Pyramid application.

Starting, Stopping, and Restarting Pyramid

Pyramid applications include a script to start, stop, and restart the application.

Starting

If a Pyramid application is not already running, it is automatically started by a cron job every 20 minutes. To manually start the application:

  1. Open an SSH session to your account.
  2. Enter $HOME/webapps/application/bin/start, where application is the name of the application as it appears on the control panel, and press Enter.

Stopping

To stop a Pyramid application:

  1. Open an SSH session to your account.
  2. Enter $HOME/webapps/application/bin/stop, where application is the name of the application as it appears on the control panel, and press Enter.

Note

When the Pyramid application was installed, a cron job was also created to automatically start the application—if it’s not already running—every 20 minutes. If you wish to prevent the application from being started automatically, this cron job must be removed. Please see Scheduling Tasks with Cron for details on modifying your cron jobs.

Restarting

To restart a Pyramid application:

  1. Open an SSH session to your account.
  2. Enter $HOME/webapps/application/bin/restart, where application is the name of the application as it appears on the control panel, and press Enter.