Skip to content

Instantly share code, notes, and snippets.

@withinboredom
Last active July 19, 2016 13:52
Show Gist options
  • Save withinboredom/953723ed797a84388e4ff17d51fb6775 to your computer and use it in GitHub Desktop.
Save withinboredom/953723ed797a84388e4ff17d51fb6775 to your computer and use it in GitHub Desktop.
Pi baker

Pi Baker

This script gets a pi up and running for production using hypriot images.

What it does

  1. prompts to change the default password
  2. removes the built in docker
  3. updates the os
  4. sets up nfs and mounts the nfs share
  5. creates, mounts, and updates fstab with swap space
  6. sets up kernel parameters to avoid swap as much as possible
  7. installs custom built docker
  8. joins the swarm
  9. reconnects to network if the network connection is lost
  10. sets up docker-gc to run hourly
  11. reboots the machine
#!/usr/bin/env bash
sudo passwd pirate
sudo apt-get remove -y docker-hypriot docker-compose hypriot-cluster-lab
sudo apt-get update && sudo apt-get upgrade -y
sudo apt-get install -y nfs-client make
echo "10.0.0.4:/var/nfs /var/nfs nfs auto,noatime,nolock,bg,nfsvers=4 0 0" | sudo tee -a /etc/fstab
sudo mkdir /var/nfs
sudo mount -a
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
sudo sysctl vm.swappiness=10
echo "vm.swappiness=10" | sudo tee -a /etc/sysctl.conf
sudo sysctl vm.vfs_cache_pressure=50
echo "vm.vfs_cache_pressure=50" | sudo tee -a /etc/sysctl.conf
sudo dpkg -i /var/nfs/docker-dist/docker-engine_1.12.0~rc4-0~jessie_armhf.deb
docker swarm join --secret shadow --manager 10.0.0.6
echo "ping -c4 10.0.0.1 > /dev/null
if [ $? != 0 ]
then
echo 'No network connection, restarting wlan0'
/sbin/ifdown 'wlan0'
sleep 5
/sbin/ifup --force 'wlan0'
fi" | sudo tee /usr/local/bin/checkwifi.sh
sudo chmod 775 /usr/local/bin/checkwifi.sh
(sudo crontab -l ; echo "*/5 * * * * /usr/bin/sudo -H /usr/local/bin/checkwifi.sh >> /dev/null 2>&1") | sudo crontab -
(sudo crontab -l ; echo "0 * * * * docker run -e FORCE_IMAGE_REMOVAL=1 -e FORCE_CONTAINER_REMOVAL=1 -v /var/run/docker.sock:/var/run/docker.sock --rm eripa/docker-gc-arm") | sudo crontab -
sudo reboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment