diff --git a/.gitignore b/.gitignore index 53486c1..4f91133 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ site.retry .vagrant .idea +config.py ### Python ### # Byte-compiled / optimized / DLL files diff --git a/.travis.yml b/.travis.yml index b3b4431..531c362 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ language: python python: - "2.7" install: + - cp config.default.py config.py - pip install -r requirements.txt before_script: - ./pylint-check.py diff --git a/Dockerfile b/Dockerfile index 950e704..ba18d45 100644 --- a/Dockerfile +++ b/Dockerfile @@ -33,6 +33,7 @@ RUN virtualenv -p /usr/bin/python2.7 /opt/postmaster/env WORKDIR /opt/postmaster/git RUN /opt/postmaster/env/bin/pip install -r requirements.txt +RUN cp -pn /opt/postmaster/git/config.default.py /opt/postmaster/git/config.py RUN source /opt/postmaster/env/bin/activate && python manage.py clean RUN chown -R www-data:www-data /opt/postmaster RUN chmod +x /opt/postmaster/git/ops/docker.sh diff --git a/config.py b/config.default.py similarity index 100% rename from config.py rename to config.default.py diff --git a/docs/ChangeLog.md b/docs/ChangeLog.md index aec7433..8272ee7 100644 --- a/docs/ChangeLog.md +++ b/docs/ChangeLog.md @@ -23,10 +23,13 @@ Improvements: * Cleaned up JavaScript event listeners [GH-120] * Vagrant now uses Ansible for configuration instead of a bash script [GH-111] * Updated the Python packages to the latest versions [GH-135] +* Apache logs for PostMaster now default to /opt/postmaster/logs Bug Fixes: * Fixed an issue where error logs were attempting to be written before the log file path was defined [GH-109] +* The configuration file, config.py, is now named as config.default.py in the repository. During installation, the administrator must now copy or rename config.default.py to config.py. +This is so that config.py is not overwritten during package upgrades. ### v1.0.0 - Abbey Road diff --git a/docs/Installation/Ubuntu1404.md b/docs/Installation/Ubuntu1404.md index 49c0017..5e86c47 100644 --- a/docs/Installation/Ubuntu1404.md +++ b/docs/Installation/Ubuntu1404.md @@ -117,56 +117,55 @@ This allows you to separate the system installed python packages from PostMaster cd /opt/postmaster/git pip install -r requirements.txt -13. PostMaster needs to be configured to connect to the MySQL database using the MySQL user created in step 2 of MySQL Preparation. +13. Create the PostMaster configuration file from using the sample file that was included: + + cp -pn /opt/postmaster/git/config.default.py /opt/postmaster/git/config.py + +14. PostMaster needs to be configured to connect to the MySQL database using the MySQL user created in step 2 of MySQL Preparation. Make sure to replace "password_changeme" with the actual password supplied in step 2 of MySQL Preparation, and if needed, replace '127.0.0.1' with the IP address or DNS specified in step 2 of MySQL Preparation: cd /opt/postmaster/git python manage.py setdburi 'mysql://postmasteruser:password_changeme@127.0.0.1:3306/servermail' -14. PostMaster needs to create a few tables under the servermail database. This is done via a database migration, +15. PostMaster needs to create a few tables under the servermail database. This is done via a database migration, which means that only the necessary changes to the database are made, and these changes are reversible if something went wrong. To start the migration, run the following command: python manage.py upgradedb -15. PostMaster uses a secret key for certain cryptographic functions. To generate a random key, run the following command: +16. PostMaster uses a secret key for certain cryptographic functions. To generate a random key, run the following command: python manage.py generatekey -16. You may now exit from the python virtual environment: +17. You may now exit from the python virtual environment: deactivate -17. Provide the proper permissions on the PostMaster files: +18. Provide the proper permissions on the PostMaster files: chown -R www-data:www-data /opt/postmaster chmod -R 550 /opt/postmaster chmod 770 /opt/postmaster/logs -18. Disable the default Apache site: +19. Disable the default Apache site: a2dissite 000-default.conf -19. Copy the default PostMaster Apache site configuration and give it the appropriate permissions. +20. Copy the default PostMaster Apache site configuration and give it the appropriate permissions. It is highly recommended that you implement SSL before using PostMaster in production: cp /opt/postmaster/git/ops/apache.conf /etc/apache2/sites-available/postmaster.conf chmod 644 /etc/apache2/sites-available/postmaster.conf chown root:root /etc/apache2/sites-available/postmaster.conf -20. Enable the PostMaster Apache site: +21. Enable the PostMaster Apache site: a2ensite postmaster.conf -21. Restart Apache for the changes to take effect: +22. Restart Apache for the changes to take effect: service apache2 restart -22. PostMaster should now be running. Simply use the username "admin" and the password "PostMaster" to login. +23. PostMaster should now be running. Simply use the username "admin" and the password "PostMaster" to login. You can change your username and password from Manage -> Administrators. - -23. Please keep in mind that the /opt/postmaster/git/db/migrations folder should be backed up after installation/updates. -This is because PostMaster uses database migrations to safely upgrade the database schema, -and this folder contains auto-generated database migration scripts that allow you to revert back if a database migration ever failed. -If this folder is missing, PostMaster can't tell what state your database is in, and therefore, cannot revert back. diff --git a/docs/Installation/WindowsServer2012R2.md b/docs/Installation/WindowsServer2012R2.md index 4404bfb..708706d 100644 --- a/docs/Installation/WindowsServer2012R2.md +++ b/docs/Installation/WindowsServer2012R2.md @@ -129,17 +129,21 @@ This is done with the following command: pip install -r "$env:SystemDrive\PostMaster\git\requirements.txt" -26. Copy wfastcgi.py, created by Microsoft Web Platform Installer earlier, to C:\PostMaster\git: +26. Create the PostMaster configuration file from using the sample file that was included: - Copy-Item -Path "$env:SystemDrive\Python27\Scripts\wfastcgi.py" "$env:SystemDrive\PostMaster\git" + Copy-Item "$env:SystemDrive\PostMaster\git\config.default.py "$env:SystemDrive\PostMaster\git\config.py" -27. At this point, PostMaster requires an IIS site. You can either use the "Default Web Site" and change the virtual directory to C:\PostMaster\git, +27. Copy wfastcgi.py, created by Microsoft Web Platform Installer earlier, to C:\PostMaster\git: + + Copy-Item "$env:SystemDrive\Python27\Scripts\wfastcgi.py" "$env:SystemDrive\PostMaster\git" + +28. At this point, PostMaster requires an IIS site. You can either use the "Default Web Site" and change the virtual directory to C:\PostMaster\git, or create a new site that points to that directory. This tutorial will use the Default Web Site. To change the virtual directory, use the following commands: Import-Module WebAdministration Set-ItemProperty 'IIS:\Sites\Default Web Site\' -Name physicalPath -Value "$env:SystemDrive\PostMaster\git" -28. Now, IIS needs to know how to run PostMaster. The following commands configure FastCGI to be able to use the Python virtual environment created earlier and run PostMaster +29. Now, IIS needs to know how to run PostMaster. The following commands configure FastCGI to be able to use the Python virtual environment created earlier and run PostMaster (If you are using a site other than "Default Web Site", change that value in the commands below): Import-Module WebAdministration @@ -149,41 +153,36 @@ or create a new site that points to that directory. This tutorial will use the D Add-WebConfiguration -Filter "/system.webServer/fastCgi/application[@fullPath='$env:SystemDrive\PostMaster\env\Scripts\python.exe' and @arguments='$env:SystemDrive\PostMaster\git\wfastcgi.py']/environmentVariables" -Value @{name='PYTHONPATH'; value="$env:SystemDrive\PostMaster\git"} -AtIndex 0 Add-WebConfiguration -Filter "/system.webServer/fastCgi/application[@fullPath='$env:SystemDrive\PostMaster\env\Scripts\python.exe' and @arguments='$env:SystemDrive\PostMaster\git\wfastcgi.py']/environmentVariables" -Value @{name='WSGI_HANDLER'; value='app.app'} -AtIndex 1 -29. PostMaster needs to be configured to connect to the MySQL database using the MySQL user created in step 2 of MySQL Preparation. +30. PostMaster needs to be configured to connect to the MySQL database using the MySQL user created in step 2 of MySQL Preparation. Make sure to replace "password_changeme" and "127.0.0.1' with the actual values supplied in step 2 of MySQL Preparation, and if needed, replace '127.0.0.1' with the IP address or DNS specified in step 2 of MySQL Preparation: cd C:\Postmaster\git python manage.py setdburi 'mysql://postmasteruser:password_changeme@127.0.0.1:3306/servermail' -30. PostMaster needs to create a few tables under the servermail database. This is done via a database migration, +31. PostMaster needs to create a few tables under the servermail database. This is done via a database migration, which means that only the necessary changes to the database are made, and these changes are reversible if something went wrong. To start the migration, run the following command: python manage.py upgradedb -31. PostMaster uses a secret key for certain cryptographic functions. To generate a random key, run the following command: +32. PostMaster uses a secret key for certain cryptographic functions. To generate a random key, run the following command: python manage.py generatekey -32. By deafult, PostMaster logs to a Linux based path, run the following command to change the log to the text file created in step 11: +33. By deafult, PostMaster logs to a Linux based path, run the following command to change the log to the text file created in step 11: python manage.py setlogfile "$env:SystemDrive\PostMaster\logs\postmaster.log" -33. You may now exit the Python virtual environment: +34. You may now exit the Python virtual environment: deactivate -34. Restart IIS to make sure all the changes take effect: +35. Restart IIS to make sure all the changes take effect: iisreset -35. At this point it is highly recommended that you implement SSL before using PostMaster in production. +36. At this point it is highly recommended that you implement SSL before using PostMaster in production. -36. PostMaster should now be running. Simply use the username "admin" and the password "PostMaster" to login. +37. PostMaster should now be running. Simply use the username "admin" and the password "PostMaster" to login. You can change your username and password from Manage -> Administrators. - -37. Please keep in mind that the C:\PostMaster\git\db\migrations folder should be backed up after installation/updates. -This is because PostMaster uses database migrations to safely upgrade the database schema, -and this folder contains auto-generated database migration scripts that allow you to revert back if a database migration ever failed. -If this folder is missing, PostMaster can't tell what state your database is in, and therefore, cannot revert back. diff --git a/ops/ansible/roles/postmaster_deploy/tasks/main.yml b/ops/ansible/roles/postmaster_deploy/tasks/main.yml index 8017397..40b27e9 100644 --- a/ops/ansible/roles/postmaster_deploy/tasks/main.yml +++ b/ops/ansible/roles/postmaster_deploy/tasks/main.yml @@ -29,7 +29,16 @@ file: path=/opt/postmaster/logs state=directory owner={{remote_user}} group=www-data mode=0775 recurse=yes become: yes -- pip: requirements=/opt/postmaster/git/requirements.txt virtualenv=/opt/postmaster/env +- name: Install python dependencies + pip: requirements=/opt/postmaster/git/requirements.txt virtualenv=/opt/postmaster/env + +- name: Checking if config.py exists + stat: path=/opt/postmaster/git/config.py + register: config_file + +- name: Copying config.default.py to config.py + copy: src=/opt/postmaster/git/config.default.py dest=/opt/postmaster/git/config.py remote_src=True + when: config_file.stat.exists == False - include: mysql.yml when: provision_type == "dev"