157 lines
13 KiB
Markdown
157 lines
13 KiB
Markdown
# Current Configuration
|
|
|
|
## NodeJS
|
|
Use [NVM](https://github.com/coreybutler/nvm-windows) on Windows to set the available versions of NodeJS. By default they are stored in `C:\Users\<user>\AppData\Roaming\nvm`.
|
|
|
|
## Setup
|
|
|
|
See below for initial setup and updating instructions.
|
|
|
|
Currently we have three servers in two locations. Media and FS2 are computers residing on the 18501 property (big barn back top room, and Wynne/Sarah house), and FS1 is a computer residing in SF. All three are accessible via Putty (a windows SSH client - any SSH client will work) via the IP's 192.168.3.101 (Media), 192.168.2.239 (FS1), and 192.168.3.164 (FS2). Note that FS1 is in SF, but is accessible via the LAN because we have a VPN setup between our routers (192.168.3.1, and 192.168.2.1). The VPN makes them look like they are on the same network.
|
|
|
|
If you SSH (Putty) into each server you can update the server using APT (`sudo apt update`, followed by `update apt upgrade`), reboot `sudo shutdown -r now`, and perform other maintenance routines.
|
|
|
|
**Currently** Media is the primary server for the PTApp (the Meteor Petit Teton Webapp - versus the Petit Teton web site which is a customer focused informational web site). FS2 is the primary server for all other web sites and web apps and it clones its SSL certifications and www folders to the other two machines. Ultimately the PTApp will need to also be on FS2 primarily along with SSL certificates and an Nginx configuration that only allows certain access outside our LAN (for sales interaction at markets and Cam's home access). The database (MongoDB) is installed on all three machines, forming a cluster such that data written to any of the three is propagated to the other two automatically.
|
|
|
|
Database backups are not trivial due to the cluster system. Essentially we are doing a simple backup/restore and ignoring the possibility that the database we take from might not have all the latest updates. Doing this on our primary server (FS2) helps ensure that we don't have any problems. MongoDB being a very flexible database and our app not caring too much about data integrity helps as well.
|
|
|
|
TODO: Linux update procedure.
|
|
|
|
TODO: Backup procedure.
|
|
|
|
TODO: Mongo update procedure.
|
|
|
|
# Setup Petit Teton Data Management Application (PTApp)
|
|
|
|
This application is designed to track sales and production data.
|
|
|
|
In a development environment, the application will create the database if it doesn't exist, naming it "meteor" and will run the database on localhost:3001. The application's web interface will be accessible on localhost:3000.
|
|
These can be changed in development mode by setting environment variables.
|
|
|
|
At runtime (production environment), the application should be deployed on a linux machine.
|
|
Package this application by running 'npm run build' from the command line in the project base directory, or double click the npm "build" script in the development environment.
|
|
|
|
1. Install MongoDB on the linux machine.
|
|
2. `sudo apt-get update`
|
|
3. `sudo apt-get install -y mongodb` (installs 2.6.10 on Ubuntu LTS 16.04 - that is the minimum version of mongo required for Meteor 1.4 - you should install the latest mongo: 3.2 per the meteor install instructions)
|
|
|
|
**OR**
|
|
|
|
See [instructions](https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/) for installing newer versions of MongoDB (RECOMMENDED)
|
|
4. Get the version of the mongo command line tool: `sudo mongo --version`
|
|
5. Get the version of the mongo server: `sudo mongod --version`
|
|
6. Start/stop/restart the mongo service: `sudo service mongod stop/start/restart`
|
|
7. View logs: `/var/log/mongodb/mongod.log`
|
|
8. Edit config: `/etc/mongod.conf` (see [docs](https://docs.mongodb.com/manual/reference/configuration-options/))
|
|
9. Make the mongo service run all the time. (SystemCtl)
|
|
1. Edit the Mongo Service file: `sudo nano mongod.service` See docs for options.
|
|
2. Reload the SystemCtl daemon: `sudo systemctl daemon-reload`
|
|
3. Start the Mongod process: `sudo systemctl start mongod`
|
|
4. Modify the system to always start Mongod: `sudo systemctl enable mongod`
|
|
10. Run tools: (see [descriptions](https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/#packages))
|
|
- mongod (the mongo database server)
|
|
- mongo (command line shell for interacting with a running db)
|
|
- mongoimport (imports data from: Extended JSON, CSV, or TSV formats created by mongoexport or 3rd party tools)
|
|
- bsondump (converts bson file formats [binary] into human readable formats [JSON] - use with mongodump files)
|
|
- mongodump (produces binary output for backups - not for use with shared clusters and replica sets)
|
|
- mongoexport (produces JSON or CSV data)
|
|
- mongofiles (command line gridfs integration - for manipulating files)
|
|
- mongooplog (replication & polling - ?)
|
|
- mongoperf
|
|
- mongorestore
|
|
- mongostat
|
|
- mongotop (stats)
|
|
11. Install nodejs & npm
|
|
1. `sudo apt-get install nodejs`
|
|
2. `sudo apt-get install npm`
|
|
12. Install n
|
|
|
|
1. `sudo npm install -g n`
|
|
13. Update nodejs to 4.7.0 (for use with meteor 1.4 - may be another nodejs version for newer meteor versions): `n bin 4.7.0` (may need to first download 4.7.0 - see other docs on linux & nodejs)
|
|
1. `sudo n 4.7.0`
|
|
2. `sudo npm install -g npm` (updates npm?)
|
|
14. Install nginx on the linux machine.
|
|
15. Install samba on the linux machine. (`sudo nano /etc/samba/smb.conf` & `sudo service smbd restart`)
|
|
1. Share the /var/www directory using the www-data user.
|
|
2. Share the /etc/nginx directory using the root user (optional & security risk - makes configuring /etc/nginx/sites-available easier).
|
|
3. Share the nginx logs directory /var/logs/nginx using a standard user with read only access (maybe www-data?).
|
|
16. Install passenger which will glue the nginx web server to one or more instances of nodejs/meteor running on the machine. (See passenger site for updated install instructions - these are specific to Ubuntu)
|
|
1. `sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 561F9B9CAC40B2F7`
|
|
2. `sudo apt-get install -y apt-transport-https ca-certificates`
|
|
3. `sudo sh -c 'echo deb https://oss-binaries.phusionpassenger.com/apt/passenger xenial main > /etc/apt/sources.list.d/passenger.list'`
|
|
4. `sudo apt-get update`
|
|
5. `sudo apt-get install -y nginx-extras passenger`
|
|
6. Configure the nginx sites-available file ("PTapp") to link nginx to passenger, and provide passenger the settings to startup meteor. Example: (replace {{xxxx}} with your own content) (NOTE: setting the mail_url fails, I used a release.properties file in the app's private directory instead, with code to use the properties file first in the server.js file in meteor.)
|
|
```
|
|
server {
|
|
listen 80;
|
|
listen [::]:80;
|
|
server_name app.petitteton.com;
|
|
root /var/www/PTApp/bundle/public;
|
|
# Turn on Passenger
|
|
passenger_enabled on;
|
|
# Tell Passenger that your app is a Meteor app
|
|
passenger_app_type node;
|
|
passenger_startup_file main.js;
|
|
# Tell your app where MongoDB is
|
|
passenger_env_var MONGO_URL {{your mongodb address/port/dbname. Example: mongodb://localhost:27017/PTApp}};
|
|
# Tell your app what its root URL is
|
|
passenger_env_var ROOT_URL http://app.petitteton.com;
|
|
#passenger_env_var MAIL_URL smtp://{{your email. example: administrator%40declarativeengineering.com}}:{{smtp password here - don't use symbols like # or $ etc}}@{{your email server. Example: secure.emailsrvr.com}};
|
|
passenger_nodejs /usr/local/n/versions/node/4.7.0/bin/node;
|
|
}
|
|
```
|
|
1. Restart nginx: `sudo service nginx restart`
|
|
2. Get status with `sudo passenger-status`
|
|
3. Stop passenger & nginx: `sudo service nginx stop` (use start or restart or reload also)
|
|
17. Create an app folder in /var/www (example: PTApp)
|
|
18. Unpack the packaged application into this new folder (easily done via the samba share on the windows development machine by drag and dropping the contents of the archive created in step 1).
|
|
1. Install the app with npm (navigate to /var/www/PTApp/bundle/programs/server): `npm install --production`
|
|
2. **Restart the passenger app each time the application is updated**: `sudo passenger-config restart-app /var/www/PTApp`
|
|
19. Use RDP to connect to the GUI for the linux server
|
|
20. Install Mongo Chef (free version) to connect to the db on localhost:27017
|
|
1. Download the archive.
|
|
2. Move the unpacked archive into /opt
|
|
3. Modify the ~/.bashrc to include: `PATH=$PATH:/opt/mongochef-3.5.0-linux-x86-dist/bin` at the end (not sure if this is necessary).
|
|
4. Run Mongo Chef from the GUI environment (how? - probably use the start menu -> Run, then pass the path like above + the executable name)
|
|
|
|
NOTE: Use MongoBooster on a windows development machine to connect to the dev database (localhost:3001) and to export.
|
|
|
|
# Updating a Meteor Deployment (OLD)
|
|
|
|
1. Run the NPM script for building the app. This can be done either from Webstorm by viewing the NPM display (shows a list of scripts in the package.json file), or typing `npm run build` from the command line. Alternatively you can simply type the build command in the command line: `meteor build --server-only ../` to build it. The command should exit with code zero for success.
|
|
2. Find the archive file: it should be in the parent directory if you ran the above script exactly, otherwise it is where ever you specified (path at the end of the command). It should be called "PetitTetonMeteor.tar.gz" as of the writing of this documentation.
|
|
3. Copy the archive to the server (**currently** Media/www/PTApp). Use what ever tools you want for this, samba and drag and drop works great. Otherwise sftp, or other method also works.
|
|
4. Navigate to /var/www/PTApp (or what ever the folder is). `cd /var/www/PTApp`
|
|
5. Use `sudo tar -xvzf PetitTetonMeteor.tar.gz` to unpack it.
|
|
6. Delete the archive (optional): `sudo rm PetitTetonMeteor.tar.gz`
|
|
7. Modify the owner of the app: `sudo chown -R www-data bundle` Run this from inside the project directory /var/www/PTApp.
|
|
8. Modify the permissions of the app: `sudo chmod -R 777 bundle` Run this from inside the project directory /var/www/PTApp.
|
|
9. Optional: Run NPM's install to update the dependancies (if they changed): `cd /var/www/PTApp/bundle/programs/server && npm install && cd /var/www/PTApp`
|
|
10. Restart the meteor app: `sudo passenger-config restart-app /var/www/PTApp`
|
|
|
|
# Updating a Meteor Deployment (NEW)
|
|
|
|
1. Run the NPM script for building the app `npm run build` which will package the app for the selected platform (in the package.json definition for the build script). Can double click the build script in WebStorm's UI for NPM alternatively. Can also manually run the script: `npm install --product && meteor build --architecture os.linux.x86_64 --server-only ../`. This will generate an archive file for the project that is production ready.
|
|
2. Copy the archive to the deployment server (**currently** Media/www/PTApp). Can use Samba for this. I place it in the web folder for the app.
|
|
3. Run the deploy.sh script `sudo ./deploy.sh` which exists in the web directory for the app: `/var/www/PTApp`. This will unpack the archive, remove the archive, change file permissions, run NPM's install on the app, and restart the app in Phusion Passenger.
|
|
4. Look at the debug output by viewing the html files stored in `/tmp`. Use Samba to view them remotely.
|
|
5. Look at the Nginx logs (should be the same as the stuff in /tmp).
|
|
|
|
# Updating a Meteor Deployment *with* a NodeJS and Meteor version change.
|
|
Check which version of meteor you have on the development machine (meteor is not installed ever on the production machine). If the version has changed, it may require a newer version of NodeJS. You have to read the Meteor notes for your version (or older versions) to figure out which NodeJS is required.
|
|
|
|
1. Update the meteor app as normal (copy it to the /var/www/xxx directory as a build bundle, then run the script to unpack it).
|
|
2. Run `sudo n` to get the current version of NodeJS being used. Use `sudo n x.x.x` to download and change to the new version of NodeJS.
|
|
3. Edit the app's nginx file in /etc/nginx/sites-available/ to reference the new NodeJS install location. For example my current install location is specified as `server {... passenger_nodejs /usr/local/n/versions/node/8.9.3/bin/node ...}`}
|
|
4. Validate things are running fine by opening the webapp in a browser (**currently** `app.petitteton.com`)
|
|
|
|
## Running Server Side Code
|
|
|
|
This is useful for importing data or running scripts that might perform some one time task.
|
|
|
|
1. Open a console and enter the server shell for meteor.
|
|
|
|
## Server Error Handling
|
|
|
|
Errors are generated in meteor, but handled by passenger. Passenger will log the error on the client screen with a code, and will log the same message in the nginx error logs. The error will be findable in the tmp folder as an html file starting with passenger and ending with the code. This is the place to look for the real error output. |