Windows PROD

Run Automail on a Windows server for PROD and UAT usage.

Good to know: on Windows, the Automail web application runs on IIS and the workflows as scheduled tasks in the Task Scheduler.

Prerequisites

Install the following software on the server:

  • Python 3.9 or later (official 64-bit version installed in C:\Program Files\Python).

  • Notepad++ for editing settings.py.

  • Git and GitHub Desktop.

  • MySQL Community Server (version 8.0) and MySQL Workbench.

  • on the server with the CGI feature activated. The IIS installation is done via the Server Manager.

Installation

The below installation is done in the C drive. If the server has a separate drive for storing the data use that drive instead.

Automail Web App

Base

The following steps are the same as for the local DEV installation:

  1. Create a Lineverge folder in C:\Lineverge\Automail Forks\[forked repo name], with the sub-folders ve, repo, backup, and staging

  2. Navigate to ve and create a virtual environment with virtualenv automail

  3. Activate the ve with automail\Scripts\activate.bat

  4. Navigate to repo and clone the forked repo with git clone https://github.com/Lineverge/[forked repo name].git . (don't forget the dot!)

  5. Navigate to C:\Lineverge\Automail Forks\[forked repo name]\software and run pip install -r requirements.txt

  6. Create a backup of your local database and restore it in MySQL Workbench

  7. Navigate to C:\Lineverge\Automail Forks\[forked repo name]\software\project

  8. Create settings.py in the project folder and adjust the paths and database constants to match the server.

  9. Run python automail.py runserver to test that the installation was successful.

IIS

The following steps are IIS-specific:

  1. Run python automail.py collectstatic --noinputto move all static files in a folder that will be used by IIS to server static content to the users (HTML, CSS, JS, images, etc.).

  2. Run pip install wfastcgi and move the wfastcgi.py file from site-packages in the ve to C:\Lineverge\Automail Forks\[forked repo name]\staging\server.

  3. Open the IIS Manager.

  4. Access the FastCGI Settings.

  5. Click Add Application and set the Full Path, Arguments, and Environment Variables.

    Full Path: C:\Lineverge\Automail Forks\[forked repo name]\ve\Scripts\python.exe Arguments: C:\Lineverge\Automail Forks\[forked repo name]\staging\server\wfastcgi.py

    Collection: DJANGO_SETTINGS_MODULE: project.settings PYTHONPATH: C:\Lineverge\Automail Forks\[forked repo name]\repo\software WSGI_HANDLER: django.core.wsgi.get_wsgi_application()

  6. Go to Sites and Add Website.

    Site name: [forked repo name] Physical path: C:\Lineverge\Automail Forks[forked repo name]\repo\software Host name: [Automail instance domain] (e.g. test.lineverge.com)

  7. Click on the newly created site, then double-click on Handler Mappings, then Add Module Mapping... under Actions.

  8. Input all parameters.

    Request path: * Module: FastCgiModule Executable: "C:\Lineverge\Automail Forks[forked repo name]\ve\Scripts\python.exe"|"C:\Lineverge\Automail Forks[forked repo name]\staging\server\wfastcgi.py" Name: [forked repo name] Requests Restrictions: Uncheck Invoke handler only if request is mapped to: checkbox and click OK

  9. Click OK, then No in the popup.

  10. Right-click on the site, then Add Virtual Directory...

  11. Set the parameters for a virtual directory and click OK.

    Alias: static Physical path: C:\Lineverge\Automail Forks[forked repo name]\repo\software\static

  12. Unfold the site, click on the static folder, then double-click on Handler Mapping.

  13. Select View Ordered List...

  14. Then move StaticFile to the top using the Move Up button under Actions.

  15. Go to C:\Lineverge\Automail Forks\[forked repo name]\repo\software and make a copy of the web.config file.

  16. Replace the current web.config file with the web.config in C:\Lineverge\Automail Forks\[forked repo name]\repo\deployment\iis\web.config.

  17. Click on the site. Then Start under Manage Website.

Automail will now be accessible at online under hostname defined above [Automail instance domain] (e.g. test.lineverge.com).

Any change in the source code of the fork needs to be pulled on the server using git pull. If the change involves new migration files, then these need to be migrated to the production database by running python automail.py migrate from the project folder.

If the change involves new or changed static files, then these need to be moved to the production static folder by running python automail.py collectstatic --noinput from the project folder.

Scheduled Tasks

Background jobs are scheduled through the Task Scheduler in Windows. Scheduled tasks can be created programmatically from the CMD using the schtasks command.

schtasks /create /tn "Automail-LV-Test\automail_test" /sc WEEKLY /d MON /st 09:00 /tr "C:\Lineverge\Automail Forks\[forked repo name]\ve\Scripts\python.exe C:\Lineverge\Automail Forks[forked repo name]\repo\software\project\automail_test.py" /RU automail /RP password

In this example schtasks command, the parameters are as follows:

  • /create: Creates a new scheduled task.

  • /tn "Automail-LV-Test\automail_test": Sets the task name to "Automail-LV-Test\automail_test".

  • /sc WEEKLY: Sets the schedule type to WEEKLY.

  • /d MON: Sets the day of the week when the task runs to Monday.

  • /st 09:00: Sets the start time of the task to 9:00 AM.

  • /tr "C:\Lineverge\Automail Forks\[forked repo name]\ve\Scripts\python.exe C:\Lineverge\Automail Forks[forked repo name]\repo\software\project\automail_test.py": Sets the command to execute for the task, which runs a Python script using a specified Python interpreter.

  • /RU automail: Specifies the user account under which the task runs as "automail".

  • /RP password: Specifies the password for the "automail" user account.

Other available parameters to customize a scheduled task programmatically include:

  • /sd: Specifies the start date for the task.

  • /ed: Specifies the end date for the task.

  • /ri: Specifies the repetition interval in minutes for the task.

  • /du: Specifies the duration for which the task should repeat, in the format HH:mm.

  • /k: Indicates that the task should stop when the repetition duration is reached.

  • /it: Allows the task to run interactively only if the user is logged on.

  • /np: Disables printing of the scheduler status messages.

  • /z: Marks the task for deletion after it runs.

  • /f: Forces the task to be created, even if the specified task name already exists.

  • /xml: Specifies the XML file containing the task definition.

For a complete list of parameters, refer to the official Microsoft documentation.

Last updated