-
Notifications
You must be signed in to change notification settings - Fork 3
How to Setup umati data logger
##Requirements *Ruby on Rails *PostgreSQL
##Setting Up Host Computer With Ruby On Rails Follow this link to guide you on how to setup Ruby on Rails. https://gorails.com/setup/ubuntu/14.04
Clone source code from Github from this Make a projects directory (mkdir projects) Change directory into the newly created directory (cd projects) Clone the source code to that directory: git clone git@github.com:iHub/udl.git
Deploy the project to a VM Open config/deploy.rb and change this line server '178.62.232.159', :web, :app, :db, primary: true to match the IP of the VM you are deploying or pushing the application to. ssh into your VM (ssh user@IP) and follow this link to install Ruby + all Ruby dependencies https://gorails.com/setup/ubuntu/14.04 Ensure you are in the projects directory then change directory to the project i.e cd udl
Once in the project directory run this commands.
bundle install [installs any dependency on your host computer] bundle exec deploy:install [installs dependencies required on the VM] (to avoid entering passwords now and again ensure you’ve configured your SSH keys well github key and VM key) this is not mandatory but if not configured you’ll have to enter the passwords a couple of times bundle exec deploy:setup [This configures your VM depending on the dependencies installed] bundle exec deploy:cold bundle exec deploy [This now pushes the code to the VM and starts all the required services the smooth running of the system]
##Database Since UDL uses a remote database here is how to set that up SSH into the database VM and run the following commands in it. (ssh user@IP) Installing PostgreSQL aptitude install postgresql-9.3 postgresql-common libpq-dev Configuring PostgreSQL In order to work with the database, we need to change the default password. Run the following command to initiate the process: sudo -u postgres psql postgres
Once you see the prompt similar to postgres=#, type the following: \password postgres Create a database create database [DATABASE NAME]; Enter your password, re-enter again to verify and press CTRL+Z or type \q to exit.
##Enabling Remote Connections Since we need PostgreSQL server to be accessible from remote computers running the Rails application, the configuration file must be modified. Run the following command to edit the PostgreSQL configuration postgresql.conf using the nano text editor: nano /etc/postgresql/9.3/main/postgresql.conf
We would like to tell PostgreSQL to listen to connections from the IP address assigned to our VM. Scroll down the file and find the following line: #listen_addresses = 'localhost'
Change it to: listen_addresses = '*'
And save and exit by pressing CTRL+X and confirming with Y. Next, we need to tell PostgreSQL the specific connections we would like it to accept, similarly to how firewalls work. Run the following command to edit the PostgreSQL hba file pg_hba.conf using the nano text editor: nano /etc/postgresql/9.3/main/pg_hba.conf
After the comment block, append the following line:
host all all 0.0.0.0/0 md5
And again, save and exit by pressing CTRL+X and confirming with Y. Restart the PostgreSQL daemon with the following command: service postgresql restart
Configuring Rails Application In this section, we will modify the Rails application servers so that they start working with the database server we have just set up. Configuring database.yml for Rails
Database settings for Rails applications are kept inside the database.yml file in /config directory
Once you open up this file (config/database.yml), you will see database settings divided by environment names. Since an application needs to run using the production environment, let's edit the configuration for that. Replace the production: YML code block with the following, changing the necessary bits to suit your own set-up configuration, e.g. the IP address etc. *Example: *production: *adapter: postgresql *encoding: utf8 *database: [database name] *username: [user name] *password: [password] *host: [server IP address] *port: [port number] *pool: [connection pool] production: adapter: postgresql encoding: utf8 database: rails_myapp (database name, the name given above while configuring) username: rails_myapp_user (username set while configuring PostgreSQL on the database VM) password: pwd (password set while configuring PostgreSQL on the database VM) host: 128.199.233.36 (UDL IP) port: 5432 pool: 10
NOTE: The pool argument contains the number of maximum simultaneous database connection slots (i.e. pool) available. You need to assess your needs and set a number accordingly. Once you are done with configuring the database, run this command on your local machine. bundle exec deploy:migrations this creates the database and makes it ready to be accessed and used by the main application