Quick start with snapcraft
This guide shows you how to get started with Pelion Edge and snapcraft packaging. At the end of this tutorial, you will have built and installed Pelion Edge and viewed its logs.
Prerequisites
Install Kubectl.
User account prerequisites:
- A Pelion Cloud account.
- Access to the
snap-pelion-edge
GitHub repository.
Build Pelion Edge
-
Clone the
snap-pelion-edge
repository:git clone https://github.com/PelionIoT/snap-pelion-edge cd snap-pelion-edge
-
Decide whether you will use production or developer mode when building your snap. You can find documentation on the choices for certificate configuration modes at Configuring Edge Build.
-
[Developer Mode] Generate a device certificate from the Device Management Portal:
-
Change the definitions of
DEVELOPER_MODE
andFACTORY_MODE
insnap/snapcraft.yaml
toDEVELOPER_MODE=ON
andFACTORY_MODE=OFF
-
Log in to the Device Management Portal, and select Device identity > Certificates.
-
If you don't have a certificate, select New certificate > Create a developer certificate.
-
When you have a certificate, open its panel.
-
On this panel, click Download Developer C file to receive
mbed_cloud_dev_credentials.c
. -
Copy
mbed_cloud_dev_crendentials.c
to/path/to/snap-pelion-edge/
:cp /path/to/mbed_cloud_dev_credentials.c /path/to/snap-pelion-edge/
-
-
[Production Mode] Do not use the device certificate from the Device Management Portal. Turn off by:
- Change the definitions of
DEVELOPER_MODE
andFACTORY_MODE
insnap/snapcraft.yaml
toDEVELOPER_MODE=OFF
andFACTORY_MODE=ON
- Change the definitions of
-
-
Generate additional certificates using the manifest-tool.
-
Install the manifest-tool:
pip install manifest-tool==1.5.2
-
Obtain an access key from the Pelion Edge Access Management Portal.
-
Run the manifest-tool:
manifest-tool init -a <access-key> --vendor-id 42fa7b48-1a65-43aa-890f-8c704daade54 --class-id 42fa7b48-1a65-43aa-890f-8c704daade54 --force
This step creates several files, including
.manifest_tool.json
andupdate_default_resources.c
. -
Copy the
update_default_resources.c
file to/path/to/snap-pelion-edge/
.
Note: This step is only for use in developer mode. Production mode does not require the
update_default_resources.c
file. -
-
Make sure your
~/.ssh/id_rsa.pub
key is registered withgithub.com
andgitlab.com
and that they both exist inknown_hosts
(for example, by runningssh -T [email protected]
andssh -T [email protected]
). -
Build with the snapcraft Docker image:
docker build --no-cache -f Dockerfile --label snapcore/snapcraft --tag ${USER}/snapcraft:latest . docker run --rm -v "$PWD":/build -w /build -v ${HOME}/.ssh:/root/.ssh -v ${HOME}/.gitconfig:/root/.gitconfig ${USER}/snapcraft:latest bash -c "sudo apt-get update && snapcraft --debug"
Note: Running the build in Docker may contaminate your project folders with files owned by root and causes a permission denied error when you run the build outside of Docker. Run
sudo chown --changes --recursive $USER:$USER _project_folder_
to fix it.
Using port 443
To use port 443 for the for Pelion-Cloud connection:
- Open
snap/snapcraft.yaml
, and set COAP_PORT_OVERRIDE_443 to "true" in the Edge Core part. - Do a clean build following the instruction above.
Install Pelion Edge
-
Copy the
pelion-edge_<version>_<arch>.snap
package to the device. -
Use the
snap
utility to install the snap package:$ sudo snap install --dangerous pelion-edge_<version>_<arch>.snap
-
Disable devicedb:
sudo systemctl stop snap.pelion-edge.devicedb.service sudo systemctl disable snap.pelion-edge.devicedb.service
-
When installing on Ubuntu 18.04, run:
sudo snap install network-manager sudo snap install modem-manager
-
Hook up these connections:
sudo snap connect pelion-edge:snapd-control :snapd-control sudo snap connect pelion-edge:modem-manager modem-manager:service sudo snap connect pelion-edge:network-manager network-manager:service sudo snap connect pelion-edge:network-control :network-control sudo snap connect pelion-edge:privileged :docker-support sudo snap connect pelion-edge:support :docker-support sudo snap connect pelion-edge:firewall-control :firewall-control sudo snap connect pelion-edge:docker-cli pelion-edge:docker-daemon sudo snap connect pelion-edge:log-observe :log-observe sudo snap connect pelion-edge:system-files-logs :system-files sudo snap connect pelion-edge:kernel-module-observe :kernel-module-observe sudo snap connect pelion-edge:system-trace :system-trace sudo snap connect pelion-edge:system-observe :system-observe sudo snap connect pelion-edge:account-control :account-control sudo snap connect pelion-edge:bluetooth-control :bluetooth-control sudo snap connect pelion-edge:hardware-observe :hardware-observe sudo snap connect pelion-edge:kubernetes-support :kubernetes-support sudo snap connect pelion-edge:mount-observe :mount-observe sudo snap connect pelion-edge:netlink-audit :netlink-audit sudo snap connect pelion-edge:netlink-connector :netlink-connector sudo snap connect pelion-edge:network-observe :network-observe sudo snap connect pelion-edge:process-control :process-control sudo snap connect pelion-edge:shutdown :shutdown
-
Reboot the device:
sudo reboot
Run Pelion Edge
After the snap is installed, Pelion Edge starts automatically. To view its status, run:
$ systemctl status snap.pelion-edge.edge-core
-
If Pelion Edge does not run automatically, use one of these commands to manually start Pelion Edge:
$ snap start pelion-edge
or
$ systemctl start snap.pelion-edge.edge-core
-
Use one of the following commands to stop Pelion Edge:
$ snap stop pelion-edge
or
$ systemctl stop snap.pelion-edge.edge-core
These are just convenient snap commands that run the binaries. The actual binaries are at /snap/pelion-edge/current/
.
View Pelion Edge logs
Log files are captured by snap and are available with the following commands:
(Do not copy and paste the line. It will likely not work)
-
To dump the whole log:
$ snap logs -n=all pelion-edge.edge-core
-
To follow the log (print new lines as they come in):
$ snap logs -f pelion-edge.edge-core
Alternatively, you can use
journalctl
. -
To dump the whole log:
$ journalctl -u snap.pelion-edge.edge-core -a
-
To follow the log (print new lines as they come in):
$ journalctl -u snap.pelion-edge.edge-core -f
Update Pelion Edge
See the snap update guide for information about updating the Pelion Edge snap.
Known issues and troubleshooting
Edge service errors
If you see this error:
2018-09-13 18:14:13.771 tid: 6932 [ERR ][esfs]: esfs_create() - pal_fsFopen() for working dir file failed
2018-09-13 18:14:13.772 tid: 6932 [ERR ][fcc ]: storage.c:283:storage_file_create:File already exist in ESFS (esfs_status 5)
2018-09-13 18:14:13.773 tid: 6932 [ERR ][fcc ]: storage.c:131:storage_file_write:<=== Failed to create new file
2018-09-13 18:14:13.774 tid: 6932 [ERR ][fcc ]: key_config_manager.c:206:kcm_item_store:Failed writing file to storage
2018-09-13 18:14:13.775 tid: 6932 [ERR ][fcc ]: fcc_dev_flow.c:96:fcc_developer_flow:<=== Store status: 8, Failed to store mbed.UseBootstrap
2018-09-13 18:14:13.958 tid: 6932 [ERR ][esfs]: esfs_close() failed with bad parameters
2018-09-13 18:14:13.961 tid: 6932 [ERR ][fcc ]: storage.c:366:storage_file_close:<=== Failed closing file (esfs_status 1)
2018-09-13 18:14:14.002 tid: 6932 [ERR ][fcc ]: storage.c:434:storage_file_read_with_ctx:<=== Buffer too small
2018-09-13 18:14:14.003 tid: 6932 [ERR ][fcc ]: key_config_manager.c:309:kcm_item_get_data:Failed reading file from storage (3)
Please reset your credentials and restart pelion-edge:
$ sudo rm -rf /var/snap/pelion-edge/current/userdata/mbed/mcc_config
$ sudo rm -rf /var/snap/pelion-edge/current/userdata/edge_gw_identity
$ sudo snap restart pelion-edge
Edge startup errors
If you see the following error when starting Edge core, you are probably attempting to start Edge core while running on a LiveUSB or LiveCD Ubuntu system:
/snap/core/current/usr/lib/snapd/snap-confine: error while loading shared libraries:
libudev.so.1: cannot open shared object file: No such file or directory
This is known to not work. The remedy is to install Ubuntu onto the system or use a virtual machine.
kubelet not displaying ID
-
Check that
kubelet
is running:$ sudo systemctl status snap.pelion-edge.kubelet.service
-
Check
kubelet
logs:$ sudo journalctl –u snap.pelion-edge.kubelet -f
Note: Attempting to register node ... indicates you can't connect.
-
Check fp-edge:
$ sudo journalctl –u snap.pelion-edge.fp-edge –f
Most likely, the hosts file on the gateway is not populated. To fix this, revisit the Install Pelion Edge section.
Further reading
To verify the gateway is now available in Pelion Portal, please see our device onboarding documentation.