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 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)

  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) - 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

  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. 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).
  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 #2

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

#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.

Description
No description provided
Readme MIT 1.3 MiB
Languages
JavaScript 72%
CSS 20.3%
HTML 7.2%
Stylus 0.5%