Problem in executing created snap of apache2


#1

I am trying to create a snap of apache2 httpd, And I successfully created the snap, but facing error in executing it. My snapcraft.yaml file looks like:

name: apache2snap
version: '2.4.37' 
summary: Snap for apache2 server # 79 char long summary
description: |
    This is the snap for apache2 server. 

grade: stable 
confinement: devmode # use 'strict' once you have the right plugs and slots

apps:
   apache2snap:
       command: INSTALL # is this correct?

parts:
  apache2snap:
     # See 'snapcraft plugins'
     plugin: dump # not sure about this.
     source: /home/mra/Downloads/httpd-2.4.37.tar.bz2

And the error I am getting while executing it is:
Command ‘apache2snap’ is available in ‘/snap/bin/apache2snap’
The command could not be located because ‘/snap/bin’ is not included in the PATH
environment variable.
apache2snap: command not found

Where I am making mistake?


#2

There are quite a few things that are messed up in your practice… Please, finish the create your first snap ubuntu tutorial before trying to snap anything.

The most significant problem, however, is this:

The command could not be located because ‘/snap/bin’ is not included in the PATH

It seems that your snapd installation is problematic as the /snap/bin directory isn’t in your command search PATHs. What is the GNU+Linux distribution you’re using? Have you overwritten your PATH environment variable?


#3

Hi @Lin-Buo-Ren,

Thanks for sharing the information with me. I have already completed that tutorial and it worked. But I am unsure about the plugin to be used and the commands to be added in the app of snap. But I understood some things after reading some information, please correct me if I am wrong.
I understood:

  1. To make snap of apache2 I need to follow same steps that are executed while building and installing from source and hence the command exposed need to be the same steps involved in installing via building from source.

  2. So if followed this approach then plugin would be nil as the source is available.

  3. If followed this approach then it needs APR(Apache runtime) so this goes in dependency of snap. But how do I add such dependency?

Please guide me if this is correct.

By using above approach my snap.yaml file looks like this:

name: apache2snap # you probably want to 'snapcraft register <name>'
version: '2.4.37' # just for humans, typically '1.2+git' or '1.3.2'
summary: Snap for apache2 server # 79 char long summary
description: |
    This is the snap for apache2 server. 

grade: stable # must be 'stable' to release into candidate/stable channels
confinement: devmode # use 'strict' once you have the right plugs and slots

apps:
   apache2snap:
       command: ./configure --prefix=Downloads/apache
       command: make
       command: make install
     #command: Downloads/apache/bin/apachectl start

 parts:
     apache2snap:
      # See 'snapcraft plugins'
          plugin: nil
          source: /home/mra/Downloads/httpd-2.4.37.tar.bz2

#4

I can see several problems. Firstly the “command” section under apps/apache2snap should be the command to RUN the program, not the command to compile it. So it should look like this:

apps:
    apache2snap:
        command: apachectl start

or something like that.

The source uses autotools (configure script) so you should be using the autotools plugin, not the nil plugin. Furthermore giving an absolute local path in your home directory for your source package is poor practice that WILL bite you, for example if you want to use cleanbuild etc. Either provide a URL for the source code, or extract the source archive and keep your snapcraft.yaml in the same directory. In the latter case, use “.” as your source path.

That means your “parts” section should look something like this:

parts:
    apache2snap:
        plugin: autotools
        source: .

Keep in mind that your snap will not work in non-devel mode because at the moment it lacks all the required plugs (at a minimum, network-bind will obviously be required).

Generally since obviously you just started learning, I would advise you to start with something easier. Building snaps for network services his HARD. How are you going to handle configuration? By default your /etc/ will be in a read-only location. You will need to make sure that it gets copied into $SNAP_COMMON upon first installation. Then you will need to make sure that Apache picks it from there and not from /etc. You will need to implement a mechanism so that the user can configure apache through snap set/snap get, which will need to regenerate the config files accordingly. You will have to manage the service life cycle. Etc.

If you completed the intro tutorial, why don’t you try something like “curl”, for example? It will be a good learning experience, slightly more complex than a hello world, but not by much. After that, try some daemon that kind of “just works” and doesn’t need much config, just start/stop etc. Apache, IMHO, is the ultimate destination of a long and difficult learning journey.


#5

Hi @jzimm,
Thanks for sharing your insights. I am new to snaps and hence I was unknown about the complexity in creating the snaps for Apache like things. And thanks for clearing the doubt regarding commands, I thought commands means “what to do after snap installation”! and hence I wrote the commands for compiling it! So considering this should need to expose all the commands of Apache like start, stop, restart etc?

And why absolute path would be a bad idea? I think the snap bundles this file isn’t it?


#6

Snap bundles the binaries and all required resources, libraries etc. It doesn’t bundle the source code. It’s possible to do that, obviously, but it wouldn’t really serve any purpose at all. If you use the autotools plugin, as is appropriate here, it will simply compile the package from the source.

Giving an absolute path is a bad idea because such a path is only valid on YOUR computer. If you use “snapcraft cleanbuild”, it will create a new container and build your package in it. This is an excellent way to avoid polluting your machine by installing tons of build dependencies, but then your absolute path won’t be accessible from the build container and it won’t work.

Once you have a working snap, the best way to release it is to commit your snapcraft.yaml & friends to github. The snap store’s build farm will pick it up automatically from there, and will build your package for all the supported architectures, but again, if the source files are not accessible from there, it won’t work.