---
title: Split Personality Snaps
description: Broadly speaking, most snaps in the Snap Store fall into one of two categories,
  desktop applications and server daemons. The graphical applications such as Chromium
  and Spotify use desktop files, which ensure they can be opened on demand by any
  user via a menu or launcher. The server applications such as NextCloud and AdGuard-Home
  typical […]
url: https://canonical.com/blog/split-personality-snaps?format=md
---

1. [Blog](https://canonical.com/blog)
2. Article

---

[Alan Pope](https://canonical.com/blog/author/popey "More about Alan Pope")

25 June 2020

# Split Personality Snaps

[sc:snap:mir-kiosk](https://canonical.com/blog/tag/scsnapmir-kiosk)
[sc:snap:scummvm](https://canonical.com/blog/tag/scsnapscummvm)
[snapcraft](https://canonical.com/blog/tag/snapcraft)
[snapcraft.io](https://canonical.com/blog/tag/snapcraft-io)

---

Share the article

Broadly speaking, most snaps in the [Snap Store](https://snapcraft.io/store) fall into one of two categories, desktop applications and server daemons. The graphical applications such as [Chromium](https://snapcraft.io/chromium) and [Spotify](https://snapcraft.io/spotify) use desktop files, which ensure they can be opened on demand by any user via a menu or launcher. The server applications such as [NextCloud](https://snapcraft.io/nextcloud) and [AdGuard-Home](https://snapcraft.io/adguard-home) typically have systemd units, which control their automatic (background) startup.

Taking an existing desktop application and converting it to an always-running [appliance](https://ubuntu.com/appliance) leads to some interesting engineering challenges. Applications and games tend to have expectations for what programs and services are accessible at runtime, which need mitigating. Application confinement in snaps on [Ubuntu Core](https://ubuntu.com/core) means some assumptions about file and device access may no longer apply.

We will typically need to stand-up a configuration in which the application believes it’s running in a standard desktop environment. The application will also need the startup automated in an appliance setting, but launched on demand when in a desktop environment.

We can be quite creative with snaps and build a “split personality” snap that can run both as a desktop application and as an appliance!

## Building Blocks

Ubuntu Core doesn’t ship with Xorg or PulseAudio out of the box. This isn’t a problem if the appliance doesn’t require a connected monitor, nor makes any sounds, as is the case with [Plex Media Server](https://snapcraft.io/plexmediaserver) and [Mosquitto](https://snapcraft.io/mosquitto) but this can be a problem with applications which require access to the display or sound hardware.

Unlike multi-user desktop environments, appliances tend to only require one local system user under which services automatically start. On a desktop system, the logged-in user launches applications on demand, whereas with an appliance, a system user launches the appliance on boot.

Our snap needs to service the needs of running on a desktop environment where Xorg and PulseAudio exist, and on an Ubuntu Core system where they don’t. It also needs to be capable of being manually launched in a window, but also auto-start full-screen on an appliance.

## Multiple Personality Order

Let’s have a look at [ScummVM](https://snapcraft.io/scummvm), where we’ve done this work already.

[ScummVM](https://www.scummvm.org/) is a program that allows you to run a variety of  classic graphical point-and-click adventure games like [The Secret of Monkey Island](https://wikipedia.org/wiki/The_Secret_of_Monkey_Island), provided you already have their data files. This makes it a great asset in the hands of old-game fans.

It’s published as a snap in the Snap Store, and runs on many different desktop Linux distributions. We thought it might be fun to make a “ScummVM Appliance” using this snap on top of Ubuntu Core. The goal is to create a single purpose device, which boots directly to the game selection screen, and functions like a ScummVM console.

As Ubuntu Core has no Xorg, we need to use [mir-kiosk](https://snapcraft.io/mir-kiosk) to provide a Wayland-compatible display stack to drive an external monitor. Ubuntu Core also ships without PulseAudio, so  we’ll get no in-game sound. This is resolved by installing the [pulseaudio](https://snapcraft.io/pulseaudio) snap. Keyboards & mice will just work as expected.

To enable the snap to function both on-demand on a desktop, and launch automatically on an appliance, we need to create two ‘apps’ stanzas in the snapcraft.yaml file that is used to build the ScummVM snap.

```
apps:
  scummvm:
    command: desktop-launch $SNAP/bin/wayland-if-possible.sh $SNAP/bin/scummvm-launch.sh
  daemon:
    command: daemon-start.sh $SNAP/bin/scummvm-launch.sh -f
    daemon: simple
```

The `daemon: simple` directive means the specified command will launch automatically on start.

This command includes logic that detects whether the program is running on an Ubuntu Core appliance, and if it is, it will launch using Mir as the Wayland display system. If the logic determines it’s not running on an Ubuntu Core appliance, the script exits immediately.

```
#!/bin/sh
 if [ "$(id -u)" = "0" ]  && [ "$(snapctl get daemon)" = "false" ]
 then
   # If not configured to run as a daemon we have to stop here
   # (There's no "snapctl disable …")
   snapctl stop $SNAP_NAME.daemon
   exit 0
 fi
 mkdir -p "$XDG_RUNTIME_DIR" -m 700
 if [ -z "${WAYLAND_DISPLAY}" ]
 then WAYLAND_DISPLAY=wayland-0
 fi
 real_wayland=$(dirname "$XDG_RUNTIME_DIR")/${WAYLAND_DISPLAY}
 while [ ! -O "${real_wayland}" ]; do echo waiting for Wayland socket; sleep 4; done
 ln -sf "${real_wayland}" "$XDG_RUNTIME_DIR"
 exec "$@"
```

That’s essentially all we need! One single yaml and a smattering of scripting is all that’s required to make a dual-personality snap that can run on-demand in desktop contexts, and automatically when run as an appliance.

ScummVM running on a traditional Linux desktop

ScummVM running under Ubuntu Core in a Virtual Machine

The ScummVM snap is built for both x86 and arm based CPUs, we could create a simple self-updating boot-to-game device based on a low-cost device like a Raspberry Pi. Plugin a keyboard, screen and mouse, and we can be gaming like it’s 1990 all over again.

If you have an idea for something we could turn into an official [Ubuntu Appliance](https://ubuntu.com/appliance), please join the [discourse](https://discourse.ubuntu.com/) and post a suggestion in the [proposed new appliances](https://discourse.ubuntu.com/c/appliance/proposed-new-appliances) category.

[Get in touch

Interested in running Ubuntu in your organization?](https://ubuntu.com/about/contact-us/form)

## Sign up for our newsletter

Get the latest Canonical news and updates in your inbox.

Work email:

\*I agree to receive information about Canonical's
products and services.

By submitting this form, I confirm that I have read and agree to [Canonical's Privacy Policy](https://canonical.com/legal/dataprivacy).

Sign up

## Share on

---

## Related posts

[### Snapcraft 8.0 and the respectable end of core18](https://canonical.com/blog/snapcraft-8-0-and-the-respectable-end-of-core18)

‘E’s not pinin’! ‘E’s passed on! This base is no more! He has ceased to be! ‘E’s expired and gone to meet ‘is maker! ‘E’s a stiff! Bereft of life, ‘e rests in peace! If you...

[Igor Ljubuncic](https://canonical.com/blog/author/igorljubuncic)

16 June 2023

[### TurtleBot3 OpenCR firmware update from a snap](https://canonical.com/blog/turtlebot3-opencr-firmware-update-from-a-snap)

The TurtleBot3 robot is a standard platform robot in the ROS community, and it’s a reference that Canonical knows well, since we’ve used it in our tutorials. As a matter of...

[gbeuzeboc](https://canonical.com/blog/author/gbeuzeboc)

25 September 2024

[### Creating Snaps on Ubuntu Touch](https://canonical.com/blog/creating-snaps-on-ubuntu-touch)

This article was written in collaboration with Alfred E. Neumayer of the UBports Project. Tablets, phones and current technology’s capabilities are phenomenal. Who would have...

[Aaron Prisk](https://canonical.com/blog/author/aaronprisk)

3 April 2024

[### Managing software in complex network environments: the Snap Store Proxy](https://canonical.com/blog/managing-software-snap-store-proxy)

As enterprises grapple with the evolving landscape of security threats, the need to safeguard internal networks from the broader internet is increasingly important. In...

[Holly Hall](https://canonical.com/blog/author/hollyhall)

15 January 2024
