Created
September 17, 2019 18:27
-
-
Save richardjortega/a65565aa0e72d2a0aa6727ef19770c87 to your computer and use it in GitHub Desktop.
Install IoT Edge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set device connection string here | |
DEVICE_CONNECTION_STRING='' | |
echo "Checking if IoT Edge is setup on this Edge VM..." | |
if ! sudo systemctl is-active --quiet iotedge ; then | |
echo "IoT Edge is not active (or unknown), installation process starting..." | |
echo "Installing IoT Edge..." | |
echo "Installing Moby runtime..." | |
# Install repository configuration | |
curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list > ./microsoft-prod.list | |
sudo cp ./microsoft-prod.list /etc/apt/sources.list.d/ | |
# Install Microsoft GPG public key | |
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg | |
sudo cp ./microsoft.gpg /etc/apt/trusted.gpg.d/ | |
# Install the container runtime | |
sudo apt-get update -y | |
sudo sysctl -w vm.max_map_count=262144 | |
sudo apt-get install -y moby-engine | |
sudo apt-get install -y moby-cli | |
# Setup daemon. | |
cat > /etc/docker/daemon.json <<EOF | |
{ | |
"log-driver": "json-file", | |
"log-opts": { | |
"max-size": "100m" | |
} | |
} | |
EOF | |
# Restart Docker | |
sudo systemctl restart docker --wait | |
echo "Installed Moby runtime." | |
echo | |
echo "Installing IoT Edge..." | |
# Install Azure IoT Edge Security Daemon | |
sudo apt-get install -y iotedge | |
# Update /etc/iotedge/config.yaml with connection string | |
# File should be created by this time | |
sudo sed -i.bak "s:<ADD DEVICE CONNECTION STRING HERE>:$DEVICE_CONNECTION_STRING:"g /etc/iotedge/config.yaml | |
sudo cat /etc/iotedge/config.yaml | |
# Restart IoT Edge$ | |
sudo systemctl restart iotedge | |
echo "Sleeping for 60 seconds then checking IoT Edge status" | |
# Wait for iotedge to become operation and recheck status | |
sleep 60 | |
sudo systemctl status iotedge | |
echo "Installed IoT Edge." | |
echo | |
else | |
sudo systemctl status iotedge | |
echo " -> IoT Edge exists on this Edge VM; skipping" | |
echo | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment