Snap for cast-web-api?

Has anyone created a snap for cast-web-api? If not, how hard would it be to create one? My understanding is that all you need is to do the following:

  1. Install nodejs and npm
  2. npm install cast-web-api -g
  3. npm install --no-optional forever

Then to start it as a daemon you would need to run forever start `which cast-web-api

I read this documentation and watched a youtube tutorial to try to create my own snap. Alas, it is not working

name: cast-web-api
version: '1.0'
summary: Control your Google Cast devices.
description: >
  See what's currently playing pause, play, set the volume and more, all from the SmartThings app. Quickly play your favourite content through presets.
  The server runs on your network IP:3000 by default. On error it defaults to 127.0.0.1. Adjustable via:
    $ cast-web-api --hostname=192.168.0.11 --port=8080
  Run as daemon
    $ forever start `which cast-web-api`

grade: devel
confinement: devmode

node-packages:
  cast-web-api   
  forever  

parts:
  cast-web-api:
    plugin: nodejs
    source: .

apps:
  cast-web-api:
    command: cast-web-api
ignacio@ignacio-XPS-8930:~/Documents/cast-web-api$ snapcraft
Issues while validating snapcraft.yaml: Additional properties are not allowed ('node-packages' was unexpected)

Could anyone point me in the right direction?

I made some progress so i thought i should add a reply instead of modifying my original post (someone may find this useful someday). The following yaml works

name: cast-web-api
version: '1.0'
summary: Control your Google Cast devices.
description: >
  See what's currently playing pause, play, set the volume and more, all from the SmartThings app. Quickly play your favourite content through presets.
  The server runs on your network IP:3000 by default. On error it defaults to 127.0.0.1. Adjustable via:
    $ cast-web-api --hostname=192.168.0.11 --port=8080
  Run as daemon
    $ cast-web-api-daemon

grade: devel
confinement: devmode



parts:
  cast-web-api:
    plugin: nodejs
    node-packages:
      - cast-web-api 
      - forever  
    source: .

apps:
  cast-web-api:
    command: cast-web-api
  daemon:
    command: forever start `which cast-web-api`
snapcraft
sudo snap install --dangerous cast-web-api_1.0_amd64.snap --devmode
cast-web-api

Alas, the command I was expecting to use to run this as a daemon does not work. Moreover, its name is not working

ignacio@ignacio-XPS-8930:~/Documents/cast-web-api$ cast-web-api.daemon 
/snap/cast-web-api/x1/command-daemon.wrapper: 1: /snap/cast-web-api/x1/command-daemon.wrapper: which cast-web-api: not found

Any ideas for how to fix that? Any other recommendations for my snap? Ultimately, i want to install this on a raspberry pi running ubuntu core and have the daemon automagically start at boot time.

You might not need to use forever. I believe you should be able to create a daemon like this:

apps:
  cast-web-api: 
    command: cast-web-api
    daemon: simple

If you do need to use forever, try forever start $SNAP/bin/cast-web-api (instead of using which).

This is an awesome project btw!

Thanks @ryanjyoder . I modifyed my yaml to look like this:

name: cast-web-api
version: '1.0'
summary: Control your Google Cast devices.
description: >
  See what's currently playing pause, play, set the volume and more, all from the SmartThings app. Quickly play your favourite content through presets.
  The server runs on your network IP:3000 by default. On error it defaults to 127.0.0.1. Adjustable via:
    $ cast-web-api --hostname=192.168.0.11 --port=8080

grade: devel
confinement: devmode



parts:
  cast-web-api:
    plugin: nodejs
    node-packages:
      - cast-web-api 
    source: .

apps:
  cast-web-api:
    command: cast-web-api
    daemon: simple

I have a couple of questions

  1. After installing the snap do i need to do anything to start the service?
  2. how do i know if the daemon is running?
  3. how do i restart it?
  4. will it start automagically at boot time?
  1. You shouldn’t need to do anything. They should start automatically.
  2. snap services cast-web-api
  3. snap restart cast-web-api
  4. Yes

The snap command has some other interesting commands for managing services, snap logs for example. Just do $ snap help to get a complete list.

1 Like

I was able to build this with snapcraft!

Do you know why it is failing to build for some architectures? should i do something about that?

Thanks for all the help!

Hmm… Can you paste (or link to) the build logs for the platforms that aren’t building?

BTW, I believe you will need to update your snapcraft.yaml file to included the correct plugs. I believe you will need at least network and network-bind.

Could you show me how to do that?

These are the logs for ppc64el and s390x

Hmm… It appears nodejs is the culprit:

You can define interfaces like this:

apps:
  cast-web-api:
    command: cast-web-api
    daemon: simple
    plugs: [network, network-bind]

Here’s some more detail: https://docs.snapcraft.io/interface-management/6154
Since snaps run inside a sandbox by default, Interfaces grant access to specific system resources on a per snap basis.

1 Like

Two more question.

  1. How do i fix the ‘failed to release’ error?

image

I tried installing this snap on my ubuntu core and failed :frowning:

ignacio82@localhost:~$ snap find cast-web-api
No matching snaps for "cast-web-api"
  1. Is it possible to start the daemon on a different port? By default, the server runs on IP:3000 but it can be adjustable via: cast-web-api - --port=8080 . Is it possible to do that with the snap?

Hard to say why it didnt release just from the screenshot. Do the build logs have any more details about why it didn’t release?

For configuring the port, there are a couple options. You could hard code it in your snapcraft.yaml. command: cast-web-api - --port=8080. If you don’t need to change the port, this would work fine.

Otherwise you would probably want to write a wrapper script to read the configs from a specific location and start the command with the appropriate options. Here’s an example I’ve used:


https://github.com/ryanjyoder/couchdb-pkg/blob/master/snap/config/snap_run

(There are some issues with this implementation, so I wouldn’t copy and paste it directly. But you get the idea.)

I was able to get fix my problem but I cannot install the snap on my raspberry pi:

ignacio82@localhost:~$ snap install cast-web-api
error: snap "cast-web-api" is not available on stable but is available to install on the following
       channels:

       edge       snap install --edge cast-web-api

       Please be mindful pre-release channels may include features not completely tested or
       implemented. Get more information with 'snap info cast-web-api'.

I tried releasing it to the stable channel but it did not work:

ignacio@ignacio-XPS-8930:~$ snapcraft release cast-web-api 9 stable
Track    Arch    Channel    Version    Revision
latest   arm64   stable     1.0.1      9
                 candidate  ^          ^
                 beta       ^          ^
                 edge       1.0.1      9

What am I missing?

I had to run snapcraft release cast-web-api 8 stable i don’t get why 8 instead of 9, but that did the trick.

One more question Can i set the license and icon in the yaml or the only way of doing that is through the website?

the raspberry pi images are armhf, not arm64 …