Running the app in production - HubSpot/python-app-google-groups GitHub Wiki

Once you have all the values set in the config.json you are ready to run it in production! It's recommended to use a SystemD service to run the app, as this will cover automatically running the migrations before running the app, creating the necessary state folders, and setting the correct permissions.

Installation

You should create a service account on the target machine which the bot will run under, in the below example it is called app-ggroups.

Via pip

Build the wheel from the repo and copy it to the target host. Then:

cd /opt
virtualenv -p python3 app_google_groups
source app_google_groups/bin/activate
pip install /path/to/app_google_groups.pip

Via pex

Simply build the pex package and copy it to the target host. It can be executed like a regular Python script.

Configuration

Copy your new config.json to /etc/app_google_groups, and make sure this folder and file are owned by your service account user.

Example SystemD service

Note the use of nginx in this example. If you are using Apache HTTPD, change the respective values.

[Unit]
Description=Google Groups Slack App
After=network.target
Before=nginx.service

[Service]
User=app-ggroups
Group=nginx
WorkingDirectory=/run/app_google_groups
RuntimeDirectory=app_google_groups
RuntimeDirectoryMode=775
UMask=0002
Environment="PYTHONUNBUFFERED=1"
ExecStartPre=/opt/app_google_groups/bin/python3 -m app_google_groups -c /etc/app_google_groups/config.json migrate
ExecStart=/opt/app_google_groups/bin/python3 -m app_google_groups -c /etc/app_google_groups/config.json run
# Using pex:
#ExecStartPre=/usr/bin/python3 /opt/app_google_groups-1.6.15.pex -c /etc/app_google_groups/config.json migrate
#ExecStart=/usr/bin/python3 /opt/app_google_groups-1.6.15.pex -c /etc/app_google_groups/config.json run

[Install]
WantedBy=multi-user.target