0

I need to run a command to initialize environment for an application. This needs to happen just once when snap package is installed.

DEB packages provide post-install script that serves this and many other purposes like setting up application specific user accounts and such.

So, what is DEB's post-install script equivalent in snap packages?

1

There is no post* script on purpose (to ensure that you have transactional updates).

Some hooks system though would be released very soon in snapd itself to enable you achieving this. It's not available yet at this date though, but you can use $SNAP_DATA file flag to make your daemon wait until the user file up the configuration (via another command from the same snap for instance).

| improve this answer | |
  • An example, perhaps? I barely follow this idea with $SNAP_DATA. – ILIV Jul 4 '16 at 9:04
0

You can configure the environment for the application in a launcher script that does it just before starting the application. What @didrocks says is that you can create a hidden flag file in $SNAP_DATA folder to know if the application has been launched previously or not.

For instance, you can have a bash script in $SNAP/bin/myapp-launcher.sh that performs:

#!/bin/sh
...
if [ ! -e "$SNAP_DATA/.flag_file ]; then
  <configure the app>
  touch $SNAP_DATA/.flag_file
fi
...
exec "<command of your app>" "$@"

and in snapcraft.yaml configure that app to be started by calling its launcher, like

...
apps:
  myapp:
    command: bin/myapp-launcher.sh
...
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.