# State script clarifications

**URL:** <https://hub.mender.io/t/state-script-clarifications/4369>\
**Category:** General Discussions\
**Tags:** state-scripts\
**Created:** [December 2, 2021, 8:52am UTC](https://hub.mender.io/t/state-script-clarifications/4369 "2021-12-02T08:52:46Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![dimaxano](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/dimaxano/32/1434_2.png) [@dimaxano](https://hub.mender.io/u/dimaxano)\
**Post date:** [December 2, 2021, 8:52am UTC](https://hub.mender.io/t/state-script-clarifications/4369/1 "2021-12-02T08:52:46Z")

</div>

Hi!  
After reading [State Scripts](https://docs.mender.io/artifact-creation/state-scripts) section in docs I’m still unclear about its behavior.

1. Is there difference where to put state-scripts: `/etc/mender/scripts` or `/data/mender/scripts`?
2. If I want to run an ArtifactInstall\_Enter script (single script for any artifact), should I provide it with each Artifact or I can just put it in one of directories above?
3. Can I write state script for (Enter/Leave) Cleanup state? Not a single word about it in docs

Thank you!

---

<div class="post-metadata">

**Author:** ![oleorhagen](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/oleorhagen/32/297_2.png) [@oleorhagen](https://hub.mender.io/u/oleorhagen)\
**Post date:** [December 2, 2021, 9:04am UTC](https://hub.mender.io/t/state-script-clarifications/4369/2 "2021-12-02T09:04:19Z")

</div>

hi @dimaxano

1. You do not put scripts here directly, they are supposed to come bundled with an Artifact.  
The difference between the directories, is that one type of script (namely all having the Artifact prefix), are installed and run only during an update, and afterwards removed.  
non-Artifact scripts (such as Idle\_Enter etc), stay persistent on the device after the update.

2. Yes, then you do need to provide it with every Artifact you deploy.

3. No, the states that have script hooks can be seen [here](https://docs.mender.io/artifact-creation/state-scripts#the-nine-states)

---

<div class="post-metadata">

**Author:** ![dimaxano](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/dimaxano/32/1434_2.png) [@dimaxano](https://hub.mender.io/u/dimaxano)\
**Post date:** [December 2, 2021, 9:42am UTC](https://hub.mender.io/t/state-script-clarifications/4369/3 "2021-12-02T09:42:27Z")

</div>

Thank you!

But how should I deliver state script that will run before ArtifactInstall if not put them directly to the necessary folder? The only way I see is to put them by hand

---

<div class="post-metadata">

**Author:** ![oleorhagen](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/oleorhagen/32/297_2.png) [@oleorhagen](https://hub.mender.io/u/oleorhagen)\
**Post date:** [December 2, 2021, 9:44am UTC](https://hub.mender.io/t/state-script-clarifications/4369/4 "2021-12-02T09:44:11Z")

</div>

You can do:

1. Manually put them in the folder
2. Run an update with them included

Either will work for the persistent scripts 🙂

---

<div class="post-metadata">

**Author:** ![dimaxano](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/dimaxano/32/1434_2.png) [@dimaxano](https://hub.mender.io/u/dimaxano)\
**Post date:** [December 2, 2021, 10:06am UTC](https://hub.mender.io/t/state-script-clarifications/4369/5 "2021-12-02T10:06:34Z")

</div>

Ok, got it!

But the intuition behind the decision to provide `Artifact*` script only with artifacts is still unclear.  
What if I want to implement something similar to [dbus-notification](https://github.com/mendersoftware/mender/tree/master/examples/state-scripts/dbus-notification) (notify custom components about current installation state ) ?

So in current situation I can put `Download_Leave` script in persistent storage, but `ArtifactInstall_Enter` and `ArtifactCommit_Leave` scripts, for example, should always be provided with each artifact. That is not critical, but pretty annoying. It is obvious that they also can be stored in persistent

---

<div class="post-metadata">

**Author:** ![oleorhagen](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/oleorhagen/32/297_2.png) [@oleorhagen](https://hub.mender.io/u/oleorhagen)\
**Post date:** [December 2, 2021, 10:17am UTC](https://hub.mender.io/t/state-script-clarifications/4369/6 "2021-12-02T10:17:19Z")

</div>

> [@dimaxano](#):
>
> But the intuition behind the decision to provide `Artifact*` script only with artifacts is still unclear.  
> What if I want to implement something similar to [dbus-notification](https://github.com/mendersoftware/mender/tree/master/examples/state-scripts/dbus-notification) (notify custom components about current installation state ) ?

The idea initially was that these are supposed to customize a single update.

> [@dimaxano](#):
>
> So in current situation I can put `Download_Leave` script in persistent storage, but `ArtifactInstall_Enter` and `ArtifactCommit_Leave` scripts, for example, should always be provided with each artifact.

That is correct.

> [@dimaxano](#):
>
> That is not critical, but pretty annoying. It is obvious that they also can be stored in persistent

I see where you’re coming from. But what would you do if you are running multiple different updates, and they each only need a sub-set of the scripts present in say `ArtifactInstall` ?

An idea could perhaps to have like a tag for each script, where the script itself decides whether or not it should be persistent.

---

<div class="post-metadata">

**Author:** ![dimaxano](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/dimaxano/32/1434_2.png) [@dimaxano](https://hub.mender.io/u/dimaxano)\
**Post date:** [December 2, 2021, 1:54pm UTC](https://hub.mender.io/t/state-script-clarifications/4369/7 "2021-12-02T13:54:01Z")

</div>

Yeah, tag idea is cool (tag even can be integrated in the name of the script `ArtifactInstall_Enter_00_T/P_custom-name`, T - temporal, P - persistent, or some other way)

But at first it would be cool to be able just put `Artifact*` script by hand at `/data/mender/scripts` and make it persistent that way 🙂
