Snappy Ubuntu Core 是Ubuntu的定位于物联网(IOT)互联网一个新的演绎。Snappy Ubuntu Core典型地运行于一个无屏幕的诸如家庭网关,机器人,开发板或一个VM。这个设备被称为目标。这是你想要编写的应用程序和部署应用程序的设备。用于编写和构建代码的计算机被称为开发主机.
$ sudo add-apt-repository ppa:snappy-dev/tools $ sudo apt-get update $ sudo apt-get upgrade $ sudo apt-get install snappy-tools bzr snapcraft
$ sudo apt-get install qemu-kvm ...say yes and install the packages...
$ kvm-ok INFO: /dev/kvm exists KVM acceleration can be used
$ wget http://releases.ubuntu.com/15.04/ubuntu-15.04-snappy-amd64-generic.img.xz $ unxz ubuntu-15.04-snappy-amd64-generic.img.xz
$kvm -m 512 -redir :8090::80 -redir :8022::22 -redir :4200::4200 ubuntu-15.04-snappy-amd64-generic.img
$ ssh -p 8022 ubuntu@localhost
$ ssh -p 8022 [email protected]
$ snappy info release: ubuntu-core/15.04/stable architecture: armhf frameworks: apps:
$ apt-get update Ubuntu Core does not use apt-get, see 'snappy --help' $ sudo apt-get install docker Ubuntu Core does not use apt-get, see 'snappy --help'
$ sudo snappy install fizzler Installing fizzler fizzler failed to install: snappy package not found
$ snappy search "" | grep "docker"
$ snappy search docker Name Version Summary docker 1.6.0.002 Docker
$ sudo snappy install docker Installing docker Starting download of docker 8.36 MB / 8.36 MB [===========================================================] 100.00 % 419.70 KB/s Done Name Date Version Developer ubuntu-core 2015-06-11 3 ubuntu docker 2015-06-11 1.6.1.002 beagleblack 2015-06-11 1.7.1
$ snappy list Name Date Version Developer ubuntu-core 2015-06-11 3 ubuntu docker 2015-06-11 1.6.1.002
$ sudo snappy install hello-world Installing hello-world.canonical Starting download of hello-world.canonical 32.73 KB / 32.73 KB [=========================================================] 100.00 % 617.46 KB/s Done Name Date Version Developer ubuntu-core 2015-06-11 3 ubuntu docker 2015-06-11 1.6.1.002 hello-world 2015-06-11 1.0.17 canonical
$ snappy info release: ubuntu-core/15.04/stable architecture: armhf frameworks: docker apps: hello-world
$ snappy search webserver Name Version Summary go-example-webserver 1.0.7 go-example-webserver xkcd-webserver 0.5 xkcd-webserver
$ sudo snappy update ubuntu-core Installing ubuntu-core (4) Syncing boot files Starting download of ubuntu-core 8.81 KB / 8.81 KB [==========================================] 100.00 % 463 B/s Apply done Updating boot files 8.81 KB / 8.81 KB [==========================================] 100.00 % 412 B/s Done Name Date Version Developer ubuntu-core 2015-06-11 4 ubuntu! Reboot to use the new ubuntu-core.
$ snappy list -v Name Date Version Developer ubuntu-core 2015-06-11 3 ubuntu* ubuntu-core 2015-06-11 4 ubuntu! docker 2015-06-11 1.6.1.002 * hello-world 2015-06-11 1.0.17 canonical* Reboot to use the new ubuntu-core.
$ sudo reboot
$ snappy list -v Name Date Version Developer ubuntu-core 2015-06-11 4 ubuntu* ubuntu-core 2015-06-11 3 ubuntu docker 2015-06-11 1.6.1.002 * hello-world 2015-06-11 1.0.17 canonical*
$ sudo snappy rollback ubuntu-core Setting ubuntu-core to version 3 Name Date Version Developer ubuntu-core 2015-06-11 2 ubuntu! Reboot to use the new ubuntu-core.
$ snappy list -v Name Date Version Developer ubuntu-core 2015-06-11 4 ubuntu* ubuntu-core 2015-06-11 3 ubuntu! docker 2015-06-11 1.6.1.002 * hello-world 2015-06-11 1.0.17 canonical* beagleblack 2015-06-11 1.7.1 * Reboot to use ubuntu-core version 3 .
$ sudo reboot
$snappy --help或者:
$snappy rollback -h
(amd64)ubuntu@localhost:~$ snappy list -v Name Date Version Developer ubuntu-core 2015-11-13 10 ubuntu* ubuntu-core 2015-10-23 9 ubuntu hello-world 2015-11-03 IEYVCgYIIDJe sideload hello-world 2015-11-03 IEYVDLXLHXJD sideload* hello-xiaoguo 2015-11-05 IEeNDQQRGSGL sideload hello-xiaoguo 2015-11-05 IEeNEfBRVYGe sideload* pastebinit 2015-11-02 1.4.0.0.2 mvo* webcam 2015-11-14 IFUaQLgTUKSU sideload* webdm 2015-10-23 0.9.2 canonical* generic-amd64 2015-10-23 1.4 canonical*
(amd64)ubuntu@localhost:~$ sudo snappy rollback hello-world IEYVCgYIIDJe Setting hello-world to version IEYVCgYIIDJe Name Date Version Developer hello-world 2015-11-03 IEYVCgYIIDJe sideload* (amd64)ubuntu@localhost:~$ snappy list -v Name Date Version Developer ubuntu-core 2015-11-13 10 ubuntu* ubuntu-core 2015-10-23 9 ubuntu hello-world 2015-11-03 IEYVCgYIIDJe sideload* hello-world 2015-11-03 IEYVDLXLHXJD sideload hello-xiaoguo 2015-11-05 IEeNDQQRGSGL sideload hello-xiaoguo 2015-11-05 IEeNEfBRVYGe sideload* pastebinit 2015-11-02 1.4.0.0.2 mvo* webcam 2015-11-14 IFUaQLgTUKSU sideload* webdm 2015-10-23 0.9.2 canonical* generic-amd64 2015-10-23 1.4 canonical*通过上面我们可以看到,我们已经把hello-world应用rollback到我们想要的版本"IEYVCgYIIDJe"了.
$sudo grub-editenv list snappy-mode=regular snappy_ab=b
$snappy install pastebinit.mvo
cat /boot/grub/grub.cfg|pastebinit.pastebinit
$ ssh -p 8022 ubuntu@localhost
$ snappy service status Snap Service State glowapi2 glowapi2 enabled; loaded; active (running) port-listener port-listener enabled; loaded; active (running) webdm snappyd ; not-found; inactive (dead) webdm snappyd enabled; loaded; active (running)
# Show status of all services for a particular snap $ snappy service status SNAPNAME ... # Show status of a given service for a particular snap $ snappy service status SNAPNAME SERVICENAME
$snappy service status Snap Service State glowapi2 glowapi2 enabled; loaded; active (running) port-listener port-listener enabled; loaded; active (running) webdm snappyd ; not-found; inactive (dead) webdm snappyd enabled; loaded; active (running) $ sudo snappy service port-listener stop Waiting for glowapi_glowapi_0.1.2.service to stop. Waiting for glowapi2_glowapi2_IETOPLPFaBXK.service to stop. Waiting for port-listener_port-listener_IERSNIVOKWSF.service to stop. unable to stop webdm's service snappyd: [stop webdm_snappyd_0.9.3.service] failed with exit status 5: Failed to stop webdm_snappyd_0.9.3.service: Unit webdm_snappyd_0.9.3.service not loaded. snappy service status Snap Service State glowapi2 glowapi2 enabled; loaded; failed (failed) port-listener port-listener enabled; loaded; failed (failed) webdm snappyd ; not-found; inactive (dead) webdm snappyd enabled; loaded; active (running)
(RaspberryPi2)ubuntu@localhost:~$ sudo snappy service logs | grep "Starting" 2015-11-01T02:31:18.017158Z systemd Starting The docker app deployment mechanism... 2015-11-01T02:31:18.061493Z systemd Starting Snappy WebDM... 2015-11-01T02:31:18.099741Z systemd Starting template Go snappy project... 2015-11-01T02:31:18.124886Z systemd Starting API for piglow as a service... 2015-11-01T02:31:18.150106Z systemd Starting Go websever... 2015-11-01T02:31:18.174013Z systemd Starting template Go snappy project... 2015-11-12T01:44:49.276470Z ubuntu-core-launcher 2015/11/12 01:44:49 Starting webserver on :8081 2015-11-12T01:44:49.331184Z ubuntu-core-launcher 2015/11/12 01:44:49 Starting webserver on :8082
(RaspberryPi2)ubuntu@localhost:~$ sudo snappy service logs go-webserver 2015-11-01T02:31:18.148438Z systemd Started Go websever. 2015-11-01T02:31:18.150106Z systemd Starting Go websever... 2015-11-12T01:44:49.276470Z ubuntu-core-launcher 2015/11/12 01:44:49 Starting webserver on :8081
$ sudo snappy install snappy-debug
(RaspberryPi2)ubuntu@localhost:~$ snappy-debug.security list System policy: Policy vendor: ubuntu-core Policy version: 15.04 Templates: default unconfined Caps: network-admin network-client network-firewall network-service network-status networking snapd Framework policy: Templates: Caps: docker_client
$ snappy-debug.security scanlog上述命令用来查看/var/log/syslog中所有的安全policy问题
$ sudo aa-status上述命令用来显示在系统已经装载的所有apparmor的policy.
$ kvm -m 512 -redir :8090::80 -redir :8022::22 -redir :4200::4200 ubuntu-15.04-snappy-amd64-generic.img
$ sudo apt-get install click-reviewers-tools $ click-review webcam_1.0_armhf.snap webcam_1.0_armhf.snap: pass
$ kvm -m 512 -redir :8090::80 -redir :8022::22 -redir :4200::4200 ubuntu-15.04-snappy-amd64-generic.img
$ snappy-remote --url=ssh://localhost:8022 install hello-world_1.0.18_all.snap
$ snappy-remote --url=ssh://IPaddressOfDevice install hello-world.snap
$ snappy-remote --url=ssh://webdm.local install port-listener_0.1_multi.snap
$ scp -P 8022 hello-world_1.0.18_all.snap [email protected]:/home/ubuntu hello-world_1.0.18_all.snap 100% 21KB 21.0KB/s 00:00
$ sudo snappy remove hello-world
$ snappy list -v Name Date Version Developer ubuntu-core 2015-09-25 2 ubuntu* ubuntu-core 2015-09-25 2 ubuntu docker 2015-11-09 1.6.2.004 canonical* hello-world 2015-10-31 1.0.18 canonical* mqtt-piglow 2015-11-02 IEWUKJCENbWA sideload* port-listener 2015-10-31 IERSNIVOKWSF sideload* webdm 2015-10-27 0.9.3 sideload webdm 2015-10-29 0.9.4 sideload* pi2 2015-09-25 0.16 canonical* ~$ sudo snappy remove hello-world Removing hello-world
name: mqtttestclient version: 1 vendor: Thibaut Rouffineau <[email protected]> summary: MQTT client on Eclipse Foundation sandbox description: This app is a small client using Eclipse Foundation MQTT client and using the Eclipse Foundation sandbox icon: ./icons/Paho.png binaries: mqttpublish: exec: bin/mqttpublish parts: mqtt: plugin: python3 source: git://git.eclipse.org/gitroot/paho/org.eclipse.paho.mqtt.python publish: plugin: copy files: ./bin/mqttpublish.py: bin/mqttpublish
$ mqtttestclient.mqttpublish
name: go-webserver vendor: XiaoGuo, Liu <[email protected]> icon: go.png version: 1.0.7 summary: Go webserver description: This is a simple go webserver. It is a service services: webserver: description: "Go websever" start: bin/golang-http caps: - network-client - network-service parts: webserver: plugin: go source: git://github.com/liu-xiao-guo/golang-http就像上面指出的那样,它的启动方式是一个service.启动路径由"start"项指定.
$SNAP_APP_PATH = /apps/<app-name>/<version>/ $SNAP_APP_DATA_PATH = /var/lib/apps/<app-name>/<version>/
$ hello-world.env | grep SNAP SNAP_APP_PATH=/apps/hello-world.sideload/IEYVDLXLHXJD SNAP_ORIGIN=sideload SNAP_APP_USER_DATA_PATH=/home/ubuntu/apps/hello-world.sideload/IEYVDLXLHXJD SNAP_FULLNAME=hello-world.sideload SNAPP_OLD_PWD=/home/ubuntu SNAPPY_APP_ARCH=amd64 SNAPP_APP_USER_DATA_PATH=/home/ubuntu/apps/hello-world.sideload/IEYVDLXLHXJD SNAPP_APP_DATA_PATH=/var/lib/apps/hello-world.sideload/IEYVDLXLHXJD SNAPP_APP_TMPDIR=/tmp SNAP_NAME=hello-world SNAP_APP_TMPDIR=/tmp SNAP_OLD_PWD=/home/ubuntu SNAPP_APP_PATH=/apps/hello-world.sideload/IEYVDLXLHXJD SNAP_ARCH=amd64 SNAP_VERSION=IEYVDLXLHXJD SNAP_APP_DATA_PATH=/var/lib/apps/hello-world.sideload/IEYVDLXLHXJD
$ sudo mount -o remount,rw /
$ sudo dpkg -i *.deb
$ dpkg -c webcam-webui_1_amd64.snap drwxrwxr-x root/root 0 2015-12-02 12:39 ./bin -rwxr-xr-x root/root 5781872 2015-12-02 12:34 ./bin/golang-static-http -rwxrwxr-x root/root 297 2015-11-27 16:33 ./bin/webcam-webui -rwxr-xr-x root/root 540 2015-12-02 12:39 ./bin/webcam-webui.wrapper drwxrwxr-x root/root 0 2015-12-02 12:39 ./etc -rw-r--r-- root/root 449 2015-01-07 03:12 ./etc/mailcap.order -rw-r--r-- root/root 24146 2015-01-07 03:12 ./etc/mime.types drwxrwxr-x root/root 0 2015-12-02 12:39 ./etc/python3.4 -rw-r--r-- root/root 155 2015-03-27 07:18 ./etc/python3.4/sitecustomize.py drwxrwxr-x root/root 0 2015-12-02 12:39 ./lib drwxrwxr-x root/root 0 2015-12-02 12:39 ./lib/x86_64-linux-gnu -rw-r--r-- root/root 1965440 2015-06-11 23:35 ./lib/x86_64-linux-gnu/libcrypto.so.1.0.0 lrwxrwxrwx root/root 0 2015-12-02 12:39 ./lib/x86_64-linux-gnu/libexpat.so.1 -> libexpat.so. 1.6.0 -rw-r--r-- root/root 166000 2015-08-28 23:04 ./lib/x86_64-linux-gnu/libexpat.so.1.6.0 lrwxrwxrwx root/root 0 2015-12-02 12:39 ./lib/x86_64-linux-gnu/libpng12.so.0 -> libpng12.so.0.51.0 -rw-r--r-- root/root 153936 2015-11-19 21:56 ./lib/x86_64-linux-gnu/libpng12.so.0.51.0 -rw-r--r-- root/root 395640 2015-06-11 23:35 ./lib/x86_64-linux-gnu/libssl.so.1.0.0 drwxrwxr-x root/root 0 2015-12-02 12:39 ./meta drwxrwxr-x root/root 0 2015-12-02 12:39 ./meta/hooks -rwxr-xr-x root/root 574 2015-12-02 12:39 ./meta/hooks/config -rw-rw-r-- root/root 14565 2015-12-02 12:39 ./meta/icon.png ...
$ sudo snappy install snappy-debug $ snappy-debug.security list -V ubuntu-core -i
(amd64)ubuntu@localhost:~$ snappy-debug.security list -V ubuntu-core -i System policy: Policy vendor: ubuntu-core Policy version: 15.04 Templates: default - Description: Allows access to app-specific directories and basic runtime - Usage: common unconfined - Description: Allows unrestricted access to the system - Usage: reserved Caps: network-admin - Description: Can configure networking - Usage: reserved network-client - Description: Can access the network as a client - Usage: common network-firewall - Description: Can configure firewall - Usage: reserved network-service - Description: Can access the network as a server - Usage: common network-status - Description: Can query network status information - Usage: reserved networking - Description: Can access the network as a client - Usage: common snapd - Description: Can use snapd - Usage: reserved Framework policy: Templates: Caps:
$ snappy-debug.security list -i
(amd64)ubuntu@localhost:~$ snappy-debug.security list -i System policy: Policy vendor: ubuntu-core Policy version: 15.04 Templates: default - Description: Allows access to app-specific directories and basic runtime - Usage: common unconfined - Description: Allows unrestricted access to the system - Usage: reserved Caps: network-admin - Description: Can configure networking - Usage: reserved network-client - Description: Can access the network as a client - Usage: common network-firewall - Description: Can configure firewall - Usage: reserved network-service - Description: Can access the network as a server - Usage: common network-status - Description: Can query network status information - Usage: reserved networking - Description: Can access the network as a client - Usage: common snapd - Description: Can use snapd - Usage: reserved Framework policy: Templates: Caps:
(RaspberryPi2)ubuntu@localhost:~$ sudo snappy hw-info temp.sideload temp.sideload: /dev/i2c-1
$ sudo snappy hw-assign temp.sideload /dev/i2c-1