How to run a snapped application in the background after installation?


#1

I have created a webapi application using dotnet and snapped with the below snapcraft.yaml file :

name: testsnap4
version: '0.1'
summary: A simple example snap for dotnet in snaps
description: A simple example snap for dotnet in snaps

grade: devel 
confinement: strict 

base: core

apps:
  test4:
command: IoT_AnalyticsCore.service

parts:
  test4:
source: .
plugin: dump
stage-packages:
    - libasn1-8-heimdal
    - libcurl3
    - libgssapi3-heimdal
    - libhcrypto4-heimdal
    - libheimbase1-heimdal
    - libheimntlm0-heimdal
    - libhx509-5-heimdal
    - libkrb5-26-heimdal
    - libldap-2.4-2
    - liblttng-ust0
    - libroken18-heimdal
    - librtmp1
    - libsasl2-2
    - libunwind8
    - liburcu4
    - libwind0-heimdal
    - icu-devtools
    - wget
    - zlib1g

and after installation i have to run the snap as below :

image

and now i want to run this in the background. How can i do it ??

I would want the snap to be started automatically as soon as i turn on my machine. Is there any way to achieve this ?


#2

If you make your app a daemon with the daemon keyword it will automatically be run after snap installation and upon machine startup.

Try:

apps:
  test4:
  command: IoT_AnalyticsCore.service
  daemon: simple

(though note there are other values that daemon could take, see the docs at https://snapcraft.io/docs/snapcraft-app-and-service-metadata for more information)


#3

Thanks for your response. I did the changes as below :

name: testsnap5
version: '0.1'
summary: A simple example snap for dotnet in snaps
description: A simple example snap for dotnet in snaps

grade: devel 
confinement: strict 

base: core

apps:
  test5:
    command: IoT_AnalyticsCore.service
    daemon: simple
    plugs:
    - network-bind
    - network

parts:
  test5:
    source: .
    plugin: dump
    stage-packages:
        - libasn1-8-heimdal
        - libcurl3
        - libgssapi3-heimdal
        - libhcrypto4-heimdal
        - libheimbase1-heimdal
        - libheimntlm0-heimdal
        - libhx509-5-heimdal
        - libkrb5-26-heimdal
        - libldap-2.4-2
        - liblttng-ust0
        - libroken18-heimdal
        - librtmp1
        - libsasl2-2
        - libunwind8
        - liburcu4
        - libwind0-heimdal
        - icu-devtools
        - wget
        - zlib1g

and then i directly try to launch the browser as below. But then it doesn’t work :frowning:

Have i missed adding something ?


#4

What is the status of the service? Try snap services testsnap5

Also try checking the logs for your service with snap logs testsnap5


#5

Looking at your screenshot, you seem to be serving some files from your home folder. Snaps need all the assets to be included in them or you need to add a home interface to be able to access $HOME. The normal approach is to include the files in the snap.


#6

Thanks a lot for your help @ijohnson @jamesj . I sorted the issue with the help of logs. It was a missing file issue.