Is it possible to run Gazebo (Indigo) from a snap?

I’ve been working for some days in trying to make a snap of my ROS Indigo workspace, which apart from the packages for running the real robot, contains the necessary for launching a simulation in Gazebo. In this snap I just selected the necessary packages for running the simulation.

However, after the first tests I had realised that it wasn’t going to be as easy as I expected, so finally I decided to just focus in trying to make Gazebo working first. Basically I wanted to be able to execute roslaunch gazebo_ros empty_world.launch --screen from my snap.

Here is my snapcraft.yaml:

name: mobile-base-snap
version: '0.1'
summary: Trying to snap the complete workspace.
description: That's all.

grade: stable
confinement: devmode

apps:

  system:
    command: roslaunch mobile_base_snap mobile_base_snap.launch --screen
    plugs: [network, network-bind, home, x11, opengl]

  gazebo:
    command: roslaunch gazebo_ros empty_world.launch --screen
    plugs: [network, network-bind, home, x11, opengl]

parts:
  simulation:
    plugin: catkin
    rosdistro: indigo
    catkin-packages: [mobile_base_snap, mobile_base_description, mobile_base_simulator]
    install:
      sed --in-place "s:setup_path=.*:setup_path=/snap/mobile-base-snap/current/usr/share/gazebo:g" "$SNAPCRAFT_PART_INSTALL/opt/ros/indigo/lib/gazebo_ros/debug";
      sed --in-place "s:setup_path=.*:setup_path=/snap/mobile-base-snap/current/usr/share/gazebo:g" "$SNAPCRAFT_PART_INSTALL/opt/ros/indigo/lib/gazebo_ros/gazebo";
      sed --in-place "s:setup_path=.*:setup_path=/snap/mobile-base-snap/current/usr/share/gazebo:g" "$SNAPCRAFT_PART_INSTALL/opt/ros/indigo/lib/gazebo_ros/gzclient";
      sed --in-place "s:setup_path=.*:setup_path=/snap/mobile-base-snap/current/usr/share/gazebo:g" "$SNAPCRAFT_PART_INSTALL/opt/ros/indigo/lib/gazebo_ros/gzserver";
      sed --in-place "s:setup_path=.*:setup_path=/snap/mobile-base-snap/current/usr/share/gazebo:g" "$SNAPCRAFT_PART_INSTALL/opt/ros/indigo/lib/gazebo_ros/perf";

You must have realised about the sed commands at the install section. This was made in order to solve this bug (probably in an incorrect way, please, correct me if so!).

Well, after being able to “solve it” in a more than doubtful way, now I’m getting this one when running the snap:

$ snap run mobile-base-snap.gazebo
... logging to /home/mbeneto/snap/mobile-base-snap/x1/ros/log/922a9c0a-af27-11e7-8b36-d8cb8a37dac2/roslaunch-utxera-32604.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://utxera:41526/

SUMMARY
========

PARAMETERS
 * /rosdistro: indigo
 * /rosversion: 1.11.21
 * /use_sim_time: True

NODES
  /
    gazebo (gazebo_ros/gzserver)
    gazebo_gui (gazebo_ros/gzclient)

auto-starting new master
process[master]: started with pid [32677]
ROS_MASTER_URI=http://localhost:11311

setting /run_id to 922a9c0a-af27-11e7-8b36-d8cb8a37dac2
process[rosout-1]: started with pid [32690]
started core service [/rosout]
process[gazebo-2]: started with pid [32693]
process[gazebo_gui-3]: started with pid [32696]
Error opening log file: "/home/mbeneto/snap/mobile-base-snap/x1/.gazebo/gzserver.log"
Gazebo multi-robot simulator, version 2.2.3
Copyright (C) 2012-2014 Open Source Robotics Foundation.
Released under the Apache 2 License.
http://gazebosim.org

Gazebo multi-robot simulator, version 2.2.3
Copyright (C) 2012-2014 Open Source Robotics Foundation.
Released under the Apache 2 License.
http://gazebosim.org

Msg Waiting for master
Msg Connected to gazebo master @ http://127.0.0.1:11345
Msg Publicized address: 10.100.128.76
[ INFO] [1507797016.449831934]: Finished loading Gazebo ROS API Plugin.
[ INFO] [1507797016.450176981]: waitForService: Service [/gazebo/set_physics_properties] has not been advertised, waiting...
Msg Waiting for master
Msg Connected to gazebo master @ http://127.0.0.1:11345
Msg Publicized address: 10.100.128.76
X Error:  BadValue
  Request Major code 154 (GLX)
  Request Minor code 3 ()
  Value 0x0
  Error Serial #26
  Current Serial #27
gzserver: /usr/include/boost/thread/pthread/recursive_mutex.hpp:101: boost::recursive_mutex::~recursive_mutex(): Assertion `!pthread_mutex_destroy(&m)' failed.
Aborted (core dumped)
[gazebo-2] process has died [pid 32693, exit code 134, cmd /snap/mobile-base-snap/x1/opt/ros/indigo/lib/gazebo_ros/gzserver -e ode worlds/empty.world __name:=gazebo __log:=/home/mbeneto/snap/mobile-base-snap/x1/ros/log/922a9c0a-af27-11e7-8b36-d8cb8a37dac2/gazebo-2.log].
log file: /home/mbeneto/snap/mobile-base-snap/x1/ros/log/922a9c0a-af27-11e7-8b36-d8cb8a37dac2/gazebo-2*.log

I’m running out of ideas and taking into account that this is my first snap experience I’m pretty lost. Any hint or tip?

Oh man, I’m not sure I’ve seen a less helpful error message :stuck_out_tongue: . Any chance that logfile contains something more informative?

core dumps are often a sign that seccomp kicked-in and killed the snap or a process therein. Try installing snappy-debug and running scanlog while you re-run your snap to reproduce the error. snappy-debug will highlight any missing plugs that it knows about and will also show you all the apparmor and seccomp denials that occur while it’s running:

sudo snap install snappy-debug
sudo snap connect snappy-debug:log-observe
/snap/bin/snappy-debug.security scanlog

Then run your app in a separate terminal:

/snap/bin/mobile-base-snap.gazebo

or using snap run mobile-base-snap.gazebo as you were doing before, either way will run the snap - the important bit I wanted to emphasize was the usage of snappy-debug :slight_smile:

So do I! I didn’t post the contents of the log files cause they don’t even exists… unfortunately, nothing strange when it comes to ROS failures. :pensive:

Thanks for the tip @lucyllewy. I tried what you suggested and I could debug some errors. First of all, the most important was that the du program wasn’t shipped in the snap, so I included the package containing it at: stage-packages: [coreutils]

After that, the amount of errors got drastically reduced. However, there are still two that I’m not sure if they might be related with the problem shown at the regular output.

= AppArmor =
Time: Oct 16 12:52:08
Log: apparmor="ALLOWED" operation="open" profile="snap.mobile-base-snap.gazebo" name="/proc/20182/mounts" pid=20182 comm="python" requested_mask="r" denied_mask="r" fsuid=1000 ouid=1000
File: /proc/20182/mounts (read)
Suggestions:
* adjust program to not access '@{PROC}/@{pid}/mounts'
* add one of 'mount-observe, network-control' to 'plugs'

= AppArmor =
Time: Oct 16 12:52:08
Log: apparmor="ALLOWED" operation="open" profile="snap.mobile-base-snap.gazebo" name="/proc/20247/mountinfo" pid=20247 comm="du" requested_mask="r" denied_mask="r" fsuid=1000 ouid=1000
File: /proc/20247/mountinfo (read)
Suggestions:
* adjust program to not access '@{PROC}/@{pid}/mountinfo'
* add 'mount-observe' to 'plugs'

Of course, I tried to add “mount-observe” and “network-control” to the plug section, looking like that currently, however the error is still shown.

plugs: [network, network-bind, home, x11, opengl, network-control, mount-observe]

Hey, just a naive question. Are all of the plugs you’ve added connected?

An even more naive question. Connected where? :sweat_smile:

I’m just creating a snap that is not communicating with any other, so I thought these plugs were just pointing the system “resources” accessible from the snap.

All of the plugs you’ve listed are provided by the core snap. Indeed, they represent system resources.

You can see more about that using the snap interfaces (plural) and snap interface (singular) commands.

Thanks @zyga-snapd , now all the plugs are properly connected to the core slots.

However, looks like the “X Error” had nothing to do with that plugs configuration, as is still appearing.

It might be related with the host system nvidia drivers? Obviously, before creating the snap I performed several simulations with Gazebo in my machine without any problem. It might be necessary any other plug? I’ve made a quick search with the key words “snap” and “nvidia” and I got some posts related with snap-confine. Should I keep looking on that direction?

Can you try the snapd 2.28.5 release? If you refresh the core snap to the beta channel on many distributions (especially on Ubuntu) snap refresh --core beta you will get improved nvidia support.

Tried it, the “X Error” disappeared, however got a new bunch of errors.

Msg Waiting for master
Msg Connected to gazebo master @ http://127.0.0.1:11345
Msg Publicized address: 10.100.128.76
[ INFO] [1508201586.469524003]: Finished loading Gazebo ROS API Plugin.
[ INFO] [1508201586.469910426]: waitForService: Service [/gazebo/set_physics_properties] has not been advertised, waiting...
Msg Waiting for master
Msg Connected to gazebo master @ http://127.0.0.1:11345
Msg Publicized address: 10.100.128.76
Exception [RenderEngine.cc:634] unable to find OpenGL rendering system. OGRE is probably installed incorrectly. Double check the OGRE cmake output, and make sure OpenGL is enabled.

Error [RenderingIface.cc:38] Failed to load the Rendering engine subsystem
unable to find OpenGL rendering system. OGRE is probably installed incorrectly. Double check the OGRE cmake output, and make sure OpenGL is enabled.
Error [gazebo.cc:179] Unable to load sensors
Error [Server.cc:212] Unable to load gazebo
gzserver: /usr/include/boost/thread/pthread/recursive_mutex.hpp:101: boost::recursive_mutex::~recursive_mutex(): Assertion `!pthread_mutex_destroy(&m)' failed.
Aborted (core dumped)
[gazebo-2] process has died [pid 17326, exit code 134, cmd /snap/mobile-base-snap/x1/opt/ros/indigo/lib/gazebo_ros/gzserver -e ode worlds/empty.world __name:=gazebo __log:=/home/mbeneto/snap/mobile-base-snap/x1/ros/log/88b056c2-b2d5-11e7-a73b-d8cb8a37dac2/gazebo-2.log].
log file: /home/mbeneto/snap/mobile-base-snap/x1/ros/log/88b056c2-b2d5-11e7-a73b-d8cb8a37dac2/gazebo-2*.log
Warning [gazebo.cc:215] Waited 1seconds for namespaces.
Warning [gazebo.cc:215] Waited 1seconds for namespaces.
Warning [gazebo.cc:215] Waited 1seconds for namespaces.
Warning [gazebo.cc:215] Waited 1seconds for namespaces.
Warning [gazebo.cc:215] Waited 1seconds for namespaces.
Warning [gazebo.cc:215] Waited 1seconds for namespaces.
Warning [gazebo.cc:215] Waited 1seconds for namespaces.
Warning [gazebo.cc:215] Waited 1seconds for namespaces.
Warning [gazebo.cc:215] Waited 1seconds for namespaces.
Warning [gazebo.cc:215] Waited 1seconds for namespaces.
Error [gazebo.cc:220] Waited 11 seconds for namespaces. Giving up.
Exception [RenderEngine.cc:634] unable to find OpenGL rendering system. OGRE is probably installed incorrectly. Double check the OGRE cmake output, and make sure OpenGL is enabled.

Error [RenderingIface.cc:38] Failed to load the Rendering engine subsystem
unable to find OpenGL rendering system. OGRE is probably installed incorrectly. Double check the OGRE cmake output, and make sure OpenGL is enabled.
Gtk-Message: Failed to load module "overlay-scrollbar"
Gtk-Message: Failed to load module "unity-gtk-module"
Gtk-Message: Failed to load module "canberra-gtk-module"
Fontconfig warning: ignoring C.UTF-8: not a valid language tag

(gzclient:17336): Pango-WARNING **: failed to choose a font, expect ugly output. engine-type='PangoRenderFc', script='common'
Qt: Session management error: None of the authentication protocols specified are supported
Error [Node.cc:90] No namespace found
Error [Node.cc:90] No namespace found
Error [Node.cc:90] No namespace found
Error [Node.cc:90] No namespace found
Error [Node.cc:90] No namespace found
Error [Node.cc:90] No namespace found
Error [Node.cc:90] No namespace found
Error [Node.cc:90] No namespace found
Error [Node.cc:90] No namespace found
Error [Node.cc:90] No namespace found
Error [Node.cc:90] No namespace found
Error [Node.cc:90] No namespace found
Error [parser.cc:79] Unable to load file[root.sdf]
Warning [parser.cc:478] XML Attribute[version] in element[sdf] not defined in SDF, ignoring.
Error [parser.cc:697] XML Element[model], child of element[sdf] not defined in SDF. Ignoring.[]
Warning [parser.cc:405] Unable to parse sdf element[]
Error [parser.cc:316] parse as sdf version 1.4 failed, should try to parse as old deprecated format
Error [SDF.cc:1162] Unable to parse sdf string[<sdf version ='1.4'><model name='building_template_model'><pose>0 0 0.0 0 0 0</pose><link name ='link'><collision name ='collision'><geometry><box><size>1.0 1.0 1.0</size></box></geometry></collision><visual name ='visual'><pose>0 0 0.0 0 0 0</pose><geometry><box><size>1.0 1.0 1.0</size></box></geometry><material><script><uri>file://media/materials/scripts/gazebo.material</uri><name>Gazebo/Grey</name></script></material></visual></link><static>true</static></model></sdf>]
Error [Node.cc:90] No namespace found

(gzclient:17336): Pango-WARNING **: failed to choose a font, expect ugly output. engine-type='PangoRenderFc', script='latin'
Error [Node.cc:90] No namespace found
Error [WindowManager.cc:112]  Unable to create the rendering window
Error [WindowManager.cc:112]  Unable to create the rendering window
Error [WindowManager.cc:112]  Unable to create the rendering window
Error [WindowManager.cc:112]  Unable to create the rendering window
Error [WindowManager.cc:112]  Unable to create the rendering window
Error [WindowManager.cc:112]  Unable to create the rendering window
Error [WindowManager.cc:112]  Unable to create the rendering window
Error [WindowManager.cc:112]  Unable to create the rendering window
Error [WindowManager.cc:112]  Unable to create the rendering window
Error [WindowManager.cc:112]  Unable to create the rendering window
Exception [WindowManager.cc:119] Unable to create the rendering window

I’m starting to think that this might be too difficult for a snapcraft beginner. Actually, unless anybody has another suggestion, I’m going to stop working on this and try to do other tests without using Gazebo. Thanks for your support this days.

Being “unable to find OpenGL rendering system” suggests that the LD_LIBRARY_PATH is missing some paths for the OpenGL libraries. As your commands are using the desktop-related interfaces I would recommend using a desktop- helper and prepending the command with desktop-launch:

name: mobile-base-snap
version: '0.1'
summary: Trying to snap the complete workspace.
description: That's all.

grade: stable
confinement: devmode

apps:

  system:
    command: desktop-launch roslaunch mobile_base_snap mobile_base_snap.launch --screen
    plugs: [network, network-bind, home, x11, opengl, network-control, mount-observe]

  gazebo:
    command: desktop-launch roslaunch gazebo_ros empty_world.launch --screen
    plugs: [network, network-bind, home, x11, opengl, network-control, mount-observe]

parts:
  simulation:
    after: [desktop-glib-only] # possibly want desktop-qt5, desktop-qt4, desktop-gtk3 or desktop-gtk2 instead.
    plugin: catkin
    rosdistro: indigo
    catkin-packages: [mobile_base_snap, mobile_base_description, mobile_base_simulator]
    install:
      sed --in-place "s:setup_path=.*:setup_path=/snap/mobile-base-snap/current/usr/share/gazebo:g" "$SNAPCRAFT_PART_INSTALL/opt/ros/indigo/lib/gazebo_ros/debug";
      sed --in-place "s:setup_path=.*:setup_path=/snap/mobile-base-snap/current/usr/share/gazebo:g" "$SNAPCRAFT_PART_INSTALL/opt/ros/indigo/lib/gazebo_ros/gazebo";
      sed --in-place "s:setup_path=.*:setup_path=/snap/mobile-base-snap/current/usr/share/gazebo:g" "$SNAPCRAFT_PART_INSTALL/opt/ros/indigo/lib/gazebo_ros/gzclient";
      sed --in-place "s:setup_path=.*:setup_path=/snap/mobile-base-snap/current/usr/share/gazebo:g" "$SNAPCRAFT_PART_INSTALL/opt/ros/indigo/lib/gazebo_ros/gzserver";
      sed --in-place "s:setup_path=.*:setup_path=/snap/mobile-base-snap/current/usr/share/gazebo:g" "$SNAPCRAFT_PART_INSTALL/opt/ros/indigo/lib/gazebo_ros/perf";