How to run two python application with in one snap

Hi All ,

I am working on python based application. My requirement is that i want to run two application independently using on snap.

For example:

name: testsnapone # you probably want to 'snapcraft register ’

version: ‘1.0’ # just for humans, typically ‘1.2+git’ or ‘1.3.2’

summary: python test snap

description: | This is test snap

grade: devel # must be ‘stable’ to release into candidate/stable channels

confinement: devmode # use ‘strict’ once you have the right plugs and slots

base: core20

apps:

   test1:
      command: test1.py
      daemon: simple
      restart-condition: always
      plugs: [home,network-bind,network]

 test2:
    command: test2.py
    daemon: simple
    restart-condition: always
    plugs: [home,network-bind,network]

parts:

 testpackage:
      # See 'snapcraft plugins'
       source-type: local
       source: .
       plugin: python
       requirements: 
       -  'requirements.txt'

above is my snapcraft.yaml

My questions is how i can run two python application using one snap? Please suggest some solution

Thanks in advance

If you are asking how you’d launch each app, the commands should be testsnapone.test1 and testsnapone.test2 Edit: I see they are declared as daemons - thanks ppd for spotting that.

You declared your applications as daemons (https://snapcraft.io/docs/services-and-daemons), so both apps will start as system daemons, like how you would run a webserver or similar.

If that’s not what you want, make sure to give https://snapcraft.io/docs/snapcraft-overview a good read, and most importantly: look at a really easy example/tutorial like Create your first snap.

1 Like

I am asking that how to build this snap using two python services because i was facing issue at stage.

Is my above snapcraft.yaml declaration is correct or wrong?

If correct then tell me why i was facing issue during build

or

if wrong then suggest the way to do that

You really need to provide us with the error messages you are facing etc. Generally, try to answer the following questions when seeking help:

  1. What is happening? What’s the current output of the tool (snapcraft or the running program)? Error messages, anything like that.
  2. What do you expect to happen? What are you trying to achieve? What is the purpose of your program? Provide context here.
  3. What have you tried so far? Generally a good idea; people are more willing to help if an earnest attempt has been made. Also, this provides context and we can see what you’re actually trying to do.
  4. How can we reproduce the issue? If possible, give us access to the source, the repository etc. People can quickly judge whether stuff is right if they can see the whole picture. Trying to guess your problem is not going to be the favourite pastime of the experts here.
  5. What is your environment? In case the issue is not an obvious one, it might sometimes also be related to the versions of software or operating system you use. The environment is most likely not part of your issue here, but it’s still an important thing to keep in mind if you report issues in bug trackers or in forums.