How to run our Hook script at snap installation

Source: Internet
Author: User
Tags syslog

For some snap applications, we would like to be able to run our script in the snap installation to do something we want to do, such as creating a folder. So how can we get this event? In our previous article, "How to set up for our Ubuntu core app," We've shown how to set up our snap app. The Configure script in that polygon is called when it is set. In fact, it is automatically called when it is installed. Below, we illustrate the following examples:

Https://github.com/liu-xiao-guo/helloworld-install

In the example above, our configure script is as follows: Configure

#!/bin/sh

echo "This is called during the installation!"
Exit 1

This is a very simple scripting program. During our installation, it returned a value of "1", indicating that it was a failure. Then this app will not be installed successfully:
liu-xiao-guo@localhost:~/apps/helloworld-install$ sudo snap install *.snap--dangerous
Error:cannot perform the Following tasks:
-Run Configure Hook of "hello-install" snap if present (this is called during the installation!)
liu-xiao-guo@localhost:~/apps/helloworld-install$ Snap List
Name            Version       Rev  Developer  Notes
Classic         16.04   canonical  DevMode
Core            16.04.1       716  canonical  -
grovepi-server  1.0           x1              DEVMODE
Packageproxy    0.1           3    ogra       -
pi2             16.04-0.17    canonical  -
Pi2-kernel      4.4.0-1030-3   canonical  -
snapweb         0.21.2   Canonical  -

Obviously through the above show, Helloworld-install is not installed in our system. If we change the Configure script to:
Configure
#!/bin/sh

echo "This is called during the installation!"
Exit 0

The return value of this script is "0", indicating that its installation was successful.
liu-xiao-guo@localhost:~/apps/helloworld-install$ sudo snap install *.snap--dangerous
Hello-install 1.0 Installed
liu-xiao-guo@localhost:~/apps/helloworld-install$ snap list
Name            Version       Rev  Developer  Notes
Classic         16.04   canonical  devmode
core            16.04.1       716  canonical  -
grovepi-server  1.0           x1              devmode
hello-install   1.0           x1              -
packageproxy    0.1           3    ogra       -
pi2             16.04-0.17   Canonical  -
pi2-kernel      4.4.0-1030-3   canonical  -
snapweb         0.21.2   Canonical  -
liu-xiao-guo@localhost:~/apps/helloworld-install$ vi/var/log/syslog
liu-xiao-guo@localhost:~/apps/helloworld-install$ sudo vi/var/log/syslog

We can find the output of this script runtime in the/var/log/syslog of the system:


It is obvious that the script is running properly at the time of installation. We can do some initialization of our application by running such a hook, paving the way for the next application to run well.
Read MORE: Https://kyrofa.com/posts/snap-updates-automatic-rollbacks

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.