The server code of a MEAN app skeleton, by Nathan Schuetz. For bootstrappig web app projects.
- Download & install Virtual Box
- Download & install Vagrant (see below for some commands)
- Clone the git repository to some directory
- use
vagrant ssh
when within the directory in your terminal to enter the vm - the project directory is mounted at
/vagrant
cd scripts/init_machine
- execute the init_machine script
- if necessary, run
npm install
- it may be necessary to disable ufw if running locally:
ufw disable
- Set up ssh config file
Host my-server HostName <ip address> User ubuntu Port 22 IdentityFile "~/.ssh/<file containing your ssh key>" LocalForward 37017 127.0.0.1:27017 AddressFamily inet
- notes
- addressfamily inet prevents ipv6, which messes up port forwarding
- localforward is for mongo
- ubuntu is default username for an ubuntu EC2 instance
- you can now connect via 'ssh my-server'
- IdentityFile may be unnecessary if you get your usual public key into the authorized keys section of the server
- you can call Host whatever you want, its just a name for your own use
- notes
- install & configure robo3T
sudo snap install robo3t-snap
- create a connection called 'my-computer' with address
localhost:27017
. This is for connecting to the db on your own machine. - create a connection called 'my-server' with address
localhost:37017
This is for connecting to the database on the server.
- create ec2 instance (t2 micro or other cheap type)
- security groups:
- allow http/https from everywhere
- allow ssh from anywhere (for now)
- allow icmp for echo requests (just so that ping works during testing)
- ebs
- mount an 8GB gp2 for root device
- mount the database ebs, or make a new one for the db[1]
- vpc
- use the default one (for now)
- use rsync to transfer the code over
rsync -avzhe ssh node-skeleton-app/ my-server:~/node-skeleton-app
- todo: use some CI tool to stash this code on s3 and use the cli to grab it
- todo: use more appropriate directory in /opt for the code
- start mongo (instructions above)
1.5. go to init machine directory, THEN execute init machine.sh
[1] make new database ebs (if necessary)
- create 8GB encrypted ebs
- todo: decide if a non-default key is better
- attach to an instance
- note: the instance seems to be able to auto-decrypt it
- format it to an ext4 filesystem
- mount in '~/data' directory
- todo: change this to /data
- note: leave owner as 'root'
- todo: create a mongodb user instead?
- config mongo to use this storage device
- make sure the script at scripts/mongo_up.sh is executable
- seed the db with some dummy data (for now)
node scripts/seed_database.js
- this script is not idempotent and should not be run more than once
- todo - this script is out of date currently (jan 2019)
Start the server in server mode: npm run serve
- you can ctrl-c out of this a few seconds later since its using a module
called 'forever' to run
Start the server in local dev mode (use this except for prod server)
- npm start
mongo
- start: sudo scripts/mongo_up.sh
- stop: find the pid and kill it
vagrant up
- start a vm
vagrant halt
- force stop vm without deleting it
vagrant suspend
- like halt, but graceful and not forced
vagrant ssh
- ssh into a vm
vagrant destroy
- delete a vm
vagrant status
-get status of vms