# State Scripts sanity check

**URL:** <https://hub.mender.io/t/state-scripts-sanity-check/941>\
**Category:** General Discussions\
**Created:** [August 15, 2019, 11:31am UTC](https://hub.mender.io/t/state-scripts-sanity-check/941 "2019-08-15T11:31:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![brianPTL](https://avatars.discourse-cdn.com/v4/letter/b/a587f6/32.png) [@brianPTL](https://hub.mender.io/u/brianPTL)\
**Post date:** [August 15, 2019, 11:31am UTC](https://hub.mender.io/t/state-scripts-sanity-check/941/1 "2019-08-15T11:31:12Z")

</div>

I have the following file:

`/etc/mender/scripts/ArtifactReboot_Enter_01_machine-safe.sh`

Contents are as follows:

```
#!/usr/bin/env bash

1>&2 echo "Script aborted due to failed bash command. Telling Mender to try later";

# Return code 21 to tell Mender to try again later
exit 21;

```

It has the following properties:  
ls -alrt ArtifactReboot\_Enter\_01\_machine-safe.sh  
-rwxrwxrwx 1 root root 235 Aug 15 11:08 ArtifactReboot\_Enter\_01\_machine-safe.sh

I can run the file manually:

```
# ./ArtifactReboot_Enter_01_machine-safe.sh
Script aborted due to failed bash command. Telling Mender to try later

# echo $?
21

```

Version of mender:  
# mender -version  
2.0.0  
runtime: go1.9.4

My ultimate goal is for the script to stall the reboot under certain circumstances, but it doesn’t seem to stall it at all. What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![mirzak](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/mirzak/32/2056_2.png) [@mirzak](https://hub.mender.io/u/mirzak)\
**Post date:** [August 15, 2019, 11:35am UTC](https://hub.mender.io/t/state-scripts-sanity-check/941/2 "2019-08-15T11:35:38Z")

</div>

Scripts for states starting with `Artifact` must be part of the Mender Artifact and not the root filesystem.

You can provide scripts when creating the Mender Artifact with the `-s` flag,

```auto
$ mender-artifact write rootfs-image --help
NAME:
   mender-artifact write rootfs-image - Writes Mender artifact containing rootfs image

USAGE:
   mender-artifact write rootfs-image [command options] <image path>

OPTIONS:
   --file FILE, -f FILE Payload FILE.
   --device-type value, -t value Type of device(s) supported by the Artifact. You can specify multiple compatible devices providing this parameter multiple times.
   --artifact-name value, -n value Name of the artifact
   --output-path value, -o value Full path to output artifact file.
   --version value, -v value Version of the artifact. (default: 3)
   --key value, -k value Full path to the private key that will be used to verify the artifact signature.
   --script value, -s value Full path to the state script(s). You can specify multiple scripts providing this parameter multiple times.

```

If you are using Yocto, take a look at the reference recipe for state-scripts,

> <https://github.com/mendersoftware/meta-mender/blob/master/meta-mender-demo/recipes-mender/example-state-scripts/example-state-scripts_1.0.bb>
