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`.
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.
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)
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)
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.)
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)
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`
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.
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).
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 ...}`}
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.