User:Amanharitsh123

From Sugar Labs
Jump to navigation Jump to search

Project Description

Sugarizer School Box Project is project under GSoC 2018. Mainly the project comprises of two parts :

1) Creating a Sugarizer Ready Rpi Image

2) Making one click deploy scripts to deploy sugarizer on popular VPS providers like Heroku , AWS ,GCP etc.

Sugarizer Rpi Image

Intoduction

Sugarizer Rpi Image is a Raspbian Stretch Image for RPi 2/3. The image is altered in such a way to always deploy/run sugarizer on the pi after the boot headlessly.The Pi creates a hotspot so that the user can connect and access the sugarizer via any device like SmartPhones , PCs etc.

Sugarizer Installation

The project's github repository is a fork of [1] . This gen script has been modified accordingly to deploy sugarizer. Firstly the script /run.sh clones [2] and place scripts from /custom_scripts to /build/custom.d and packages from /packages to /build/packages.

Docker Installation

First step towards the deployment is making a docker ready image first and deploying sugarizer then. To install docker ,a docker arm deb package has been attached to the gen script. The docker package is in /packages directory and is copied to /build/packages directory after cloning [3] in /build directory. The package then get automatically installed during the image compilation.

Docker Compose is installed simply by adding "docker-compose" in the /templates/rpi3stretch-sugarizer, in APT_INCLUDE parameter.

Placing Sugarizer and Sugarizer-Server

In the main repo , there are two folders i.e custom_scripts and image_scripts.

custom_scripts folder contain the scripts which are directly placed into build/custom.d folder by run.sh. These scripts are used to make modification before the image is formed.

image_scripts folder contains the scripts which are placed into the image and will be used after the image boots in Rpi.

So , to place the sugarizer in the image . A sugarizer.sh script is used, which is placed in /custom_scripts. This script clones the sugarizer and sugarizer-server repository and place them in /home/pi/ in the rpi image.

Offline Docker MongoDB and Node Image Loading

Docker Images has already been hosted on DropBox. /run.sh script downloads and places them in /docker-images folder. Now sugarizer.sh places them in /home/pi in rpi image.

FirstBoot Actions

Firstboot actions are performed by rc.local and script.sh in /image_scripts. These scripts are placed at their appropriate location by sugarizer.sh script.

script.sh is callled by rc.local at the boot , It then loads the docker images and make sugarizer_server and sugarizer_mongodb containers and run them . Once all the commands run successfully , script.sh will delete its calling command from rc.local script . If anything goes wrong or the Rpi is interrupted before the deployment , script.sh will be called again after the next boot.

Note: Boot the pi , After 30-35mins pi will reboot automatically.After the successful first boot , sugarizer server will be active in a minute or two after booting.

Wifi Hotspot

To make the task easy , we have used a project [4] already available on github to setup hotspot and bridging ethernet on rpi.The wifi now works perfectly for the first run but stops throwing an IP after a reboot , its a known issue dhcpcd and hostapd . To overcome this all we need to do is restart services , so we have added a command to rc.local to restart all the required services at boot. A more deatiled explanation is as follows , we now clones the project in to /home/pi/RPI3_HOTSPOT . After the boot , a script finds the ethernet device name of the pi and replace every occurence of eth0 in the cloned project with that device name to make sure that brdiging is done correctly. At the end , script runs the ap command and we have hotspot up and working.

Local DNS

We have modified the existing wifi ap scripts to change subnet of IPs assigned to 10.x.x.x , to handle DNS requests for "server.sugarizer.org","try.sugarizer.org" and "sugarizer.org" locally. We have used dnsmasq to implement this.

Exposing Port 80 using Nginx

We have used Nginx as reverse proxy server to forward incoming requests of port 80 to 8080.

SD card corruption Prevention

To prevent sd card corruption we tried reducing the disk writes.The main cause of frequent disk writes is system logging , we have mounted /var/log as tmpfs which reduces writes to disks .

Building and Flashing the RPi Image

It is advisable to build image on Debian or any Debian based distribution to avoid dependency issues.

You can build the image using the scirpt. Please follow the instructions here https://github.com/amanharitsh123/sugarizer-school-box.

Read the Instructions carefully.

Deploy Sugarizer to GCP and AWS

To provide one click deploy solutions , we have made one packer script to create custom sugarizer ami and bash script to deploy sugarizer on GCP along with the required documentation.

GCP : [5]

AWS : [6]