# Issues with rollback using Directory Update Module

**URL:** <https://hub.mender.io/t/issues-with-rollback-using-directory-update-module/1073>\
**Category:** General Discussions\
**Created:** [September 23, 2019, 4:40pm UTC](https://hub.mender.io/t/issues-with-rollback-using-directory-update-module/1073 "2019-09-23T16:40:08Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![bonini\_lucas](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/bonini_lucas/32/124_2.png) [@bonini\_lucas](https://hub.mender.io/u/bonini_lucas)\
**Post date:** [September 23, 2019, 4:40pm UTC](https://hub.mender.io/t/issues-with-rollback-using-directory-update-module/1073/1 "2019-09-23T16:40:08Z")

</div>

How can i roll back the update using this module?

---

<div class="post-metadata">

**Author:** ![lluiscampos](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/lluiscampos/32/112_2.png) [@lluiscampos](https://hub.mender.io/u/lluiscampos)\
**Post date:** [September 24, 2019, 7:26am UTC](https://hub.mender.io/t/issues-with-rollback-using-directory-update-module/1073/2 "2019-09-24T07:26:15Z")

</div>

Hi Lucas,

So if you have installed it in standalone mode, and assuming you have not committed it yet, you can rollback the artifact by running `mender -rollback`.

But if you were using managed mode, the the install/commit was done automatically and the rollback is only performed if there are errors during the process.

I think you will understand this better if you have a look at the Architecture part of our docs, ref: [https://docs.mender.io/2.1/architecture/overview](https://docs.mender.io/2.1/architecture/overview)

---

<div class="post-metadata">

**Author:** ![bonini\_lucas](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/bonini_lucas/32/124_2.png) [@bonini\_lucas](https://hub.mender.io/u/bonini_lucas)\
**Post date:** [September 24, 2019, 12:48pm UTC](https://hub.mender.io/t/issues-with-rollback-using-directory-update-module/1073/3 "2019-09-24T12:48:23Z")

</div>

I performed an update for testing and used the command with sudo permissions. I got this:  
 ![image](https://canada1.discourse-cdn.com/flex036/uploads/mender/original/1X/461b6c7bf685ac83830963d919a923ba521e80ad.png)  
So, regardless of anything happening, I tried to upload a new artifact again and now I have the following error:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/mender/original/1X/94d4f8b387bc3351f4598e4ebb66852805c8e705.png)

I’m running the pre-build client.

---

<div class="post-metadata">

**Author:** ![lluiscampos](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/lluiscampos/32/112_2.png) [@lluiscampos](https://hub.mender.io/u/lluiscampos)\
**Post date:** [September 24, 2019, 1:21pm UTC](https://hub.mender.io/t/issues-with-rollback-using-directory-update-module/1073/4 "2019-09-24T13:21:41Z")

</div>

Can you please copy the error log in text? I cannot read the full log from an image.

---

<div class="post-metadata">

**Author:** ![bonini\_lucas](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/bonini_lucas/32/124_2.png) [@bonini\_lucas](https://hub.mender.io/u/bonini_lucas)\
**Post date:** [September 24, 2019, 1:51pm UTC](https://hub.mender.io/t/issues-with-rollback-using-directory-update-module/1073/5 "2019-09-24T13:51:18Z")

</div>

I performed the authentication procedure again and went back to working normally.  
I sent a new artifact, the folder appeared in my home directory but when I run the -rollback command I get this:  
`sudo mender -rollback`  
`INFO[0000] Loaded configuration file: /etc/mender/mender.conf module=config`  
`INFO[0000] No dual rootfs configuration present module=main`  
`ERRO[0000] There is nothing to commit module=standalone`  
`WARN[0000] There is nothing to commit module=main`

---

<div class="post-metadata">

**Author:** ![lluiscampos](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/lluiscampos/32/112_2.png) [@lluiscampos](https://hub.mender.io/u/lluiscampos)\
**Post date:** [September 24, 2019, 2:16pm UTC](https://hub.mender.io/t/issues-with-rollback-using-directory-update-module/1073/6 "2019-09-24T14:16:26Z")

</div>

Still not clear to me what are you trying to achieve.

Are you running mender in managed mode or in standalone mode? If you are running in managed mode you cannot manually perform a rollback. The rollback mechanism will be handled automatically by mender if the installation fails.

---

<div class="post-metadata">

**Author:** ![bonini\_lucas](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/bonini_lucas/32/124_2.png) [@bonini\_lucas](https://hub.mender.io/u/bonini_lucas)\
**Post date:** [September 24, 2019, 2:28pm UTC](https://hub.mender.io/t/issues-with-rollback-using-directory-update-module/1073/7 "2019-09-24T14:28:51Z")

</div>

Thanks for the reply,

I am running from a locally hosted server. I believe it is managed mode. I now understand that mender automatically handles rollback with this directory module. But what I mean is if there is an error in an application because of the update and not in the installation of the artifact itself, how will Mender handle it? Can Mender somehow at least send me a debug info?

---

<div class="post-metadata">

**Author:** ![lluiscampos](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/lluiscampos/32/112_2.png) [@lluiscampos](https://hub.mender.io/u/lluiscampos)\
**Post date:** [September 24, 2019, 2:40pm UTC](https://hub.mender.io/t/issues-with-rollback-using-directory-update-module/1073/8 "2019-09-24T14:40:01Z")

</div>

I recommend you have a look at this tutorial on Update Modules, to better understand the rollback mechanism: [https://docs.mender.io/2.1/devices/update-modules](https://docs.mender.io/2.1/devices/update-modules)

The logs are sent to the server, you should be able to find them in the finished deployment.

---

<div class="post-metadata">

**Author:** ![drewmoseley](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/drewmoseley/32/47_2.png) [@drewmoseley](https://hub.mender.io/u/drewmoseley)\
**Post date:** [September 24, 2019, 3:48pm UTC](https://hub.mender.io/t/issues-with-rollback-using-directory-update-module/1073/9 "2019-09-24T15:48:11Z")

</div>

@bonini_lucas I would also recommend looking into a pre-commit state script that will allow you to plugin your own post-install checks. It’s basically a shell script that you provide that Mender will call and if you detect an error condition, you return the value 1 and the managed mode update will be rolled back. Full details are here: [https://docs.mender.io/2.1/artifacts/state-scripts](https://docs.mender.io/2.1/artifacts/state-scripts)

---

<div class="post-metadata">

**Author:** ![bonini\_lucas](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/bonini_lucas/32/124_2.png) [@bonini\_lucas](https://hub.mender.io/u/bonini_lucas)\
**Post date:** [September 24, 2019, 4:27pm UTC](https://hub.mender.io/t/issues-with-rollback-using-directory-update-module/1073/10 "2019-09-24T16:27:08Z")

</div>

@lluiscampos @drewmoseley Thanks so much for the support.

I will read these documents. But, is there somewhere where I can find script examples of these cases?

---

<div class="post-metadata">

**Author:** ![drewmoseley](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/drewmoseley/32/47_2.png) [@drewmoseley](https://hub.mender.io/u/drewmoseley)\
**Post date:** [September 24, 2019, 6:29pm UTC](https://hub.mender.io/t/issues-with-rollback-using-directory-update-module/1073/11 "2019-09-24T18:29:17Z")

</div>

We have some example state scripts that simply return “OK” to show how they can be added to a Yocto build here: [https://github.com/mendersoftware/meta-mender/tree/master/meta-mender-demo/recipes-mender/example-state-scripts/files](https://github.com/mendersoftware/meta-mender/tree/master/meta-mender-demo/recipes-mender/example-state-scripts/files)

You can do something similar only having appropriate checks and returning “1” in case they fail.

---

<div class="post-metadata">

**Author:** ![bonini\_lucas](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/bonini_lucas/32/124_2.png) [@bonini\_lucas](https://hub.mender.io/u/bonini_lucas)\
**Post date:** [September 25, 2019, 11:34am UTC](https://hub.mender.io/t/issues-with-rollback-using-directory-update-module/1073/12 "2019-09-25T11:34:25Z")

</div>

Hello,  
I was performing rollback tests and tried to reproduce this part of the documentation:

> You can experiment with the rollback mechanism by forcing the update to fail. For example, creating a directory under `/var/www` with the same name as one of the files contained in the incoming Artifact will trigger an error in the `cp` command. Once this happens, the Update Module should restore the previous files.

But it did not work. I got the folder I was ordered to create and on the mender server I got this:  
 ![image](https://canada1.discourse-cdn.com/flex036/uploads/mender/original/1X/003f96f28e3a71ee007e03cac3d8331b057ba65a.png)

inside the client:  
`sudo mender -show-artifact`  
`web-file-4.0_INCONSISTENT`

Logs:

> 2019-09-24 18:28:02 +0000 UTC info: Running Mender version 2.1.0  
> 2019-09-24 18:28:02 +0000 UTC debug: handle update fetch state  
> 2019-09-24 18:28:02 +0000 UTC debug: status reported, response 204 No Content  
> 2019-09-24 18:28:03 +0000 UTC debug: Received fetch update response &{200 OK 200 HTTP/1.1 1 1 map[Date:[Tue, 24 Sep 2019 18:28:03 GMT] Etag:[“6864c457d91d952e6aeb756d249c2b59”] X-Amz-Request-Id:[15C77338D0B8F668] X-Xss-Protection:[1; mode=block] Strict-Transport-Security:[max-age=63072000; includeSubdomains; preload] Vary:[Origin] Connection:[keep-alive] Content-Security-Policy:[block-all-mixed-content] Last-Modified:[Tue, 24 Sep 2019 17:35:59 GMT] X-Content-Type-Options:[nosniff] Server:[openresty/1.13.6.2] Content-Type:[application/vnd.mender-artifact] Content-Length:[5120] Accept-Ranges:[bytes] X-Frame-Options:[DENY]] 0xc0c8e0 5120 false false map 0xe3e280 0xc7ca20}+  
> 2019-09-24 18:28:03 +0000 UTC info: State transition: update-fetch [Download\_Enter] → update-store [Download\_Enter]  
> 2019-09-24 18:28:03 +0000 UTC debug: handle update install state  
> 2019-09-24 18:28:03 +0000 UTC debug: status reported, response 204 No Content  
> 2019-09-24 18:28:03 +0000 UTC debug: Read data from device manifest file: device\_type=raspberrypi3  
> 2019-09-24 18:28:03 +0000 UTC debug: Current manifest data: raspberrypi3  
> 2019-09-24 18:28:03 +0000 UTC info: no public key was provided for authenticating the artifact  
> 2019-09-24 18:28:03 +0000 UTC debug: checking if device [raspberrypi3] is on compatible device list: [raspberrypi3]  
> 2019-09-24 18:28:03 +0000 UTC debug: Executing ModuleInstaller.Initialize  
> 2019-09-24 18:28:03 +0000 UTC debug: Returning artifact name web-file-4.0\_INCONSISTENT from database.  
> 2019-09-24 18:28:03 +0000 UTC debug: Read data from device manifest file: artifact\_name=unknown  
> 2019-09-24 18:28:03 +0000 UTC debug: Read data from device manifest file: device\_type=raspberrypi3  
> 2019-09-24 18:28:03 +0000 UTC debug: Current manifest data: raspberrypi3  
> 2019-09-24 18:28:03 +0000 UTC debug: installer: successfully read artifact [name: web-file-4.0; version: 3; compatible devices: [raspberrypi3]]  
> 2019-09-24 18:28:03 +0000 UTC debug: Executing ModuleInstaller.PrepareStoreUpdate  
> 2019-09-24 18:28:03 +0000 UTC debug: Calling module: /usr/share/mender/modules/v3/web-file Download /var/lib/mender/modules/v3/payloads/0000/tree  
> 2019-09-24 18:28:03 +0000 UTC debug: Executing ModuleInstaller.StoreUpdate  
> 2019-09-24 18:28:03 +0000 UTC debug: Executing ModuleInstaller.FinishStoreUpdate  
> 2019-09-24 18:28:03 +0000 UTC debug: Executing ModuleInstaller.SupportsRollback  
> 2019-09-24 18:28:03 +0000 UTC debug: Calling module: /usr/share/mender/modules/v3/web-file SupportsRollback /var/lib/mender/modules/v3/payloads/0000/tree  
> 2019-09-24 18:28:03 +0000 UTC debug: Update module output: Yes  
> 2019-09-24 18:28:03 +0000 UTC debug: Module supports rollback  
> 2019-09-24 18:28:03 +0000 UTC debug: status reported, response 204 No Content  
> 2019-09-24 18:28:03 +0000 UTC info: State transition: update-store [Download\_Enter] → update-after-store [Download\_Leave]  
> 2019-09-24 18:28:03 +0000 UTC info: State transition: update-after-store [Download\_Leave] → update-install [ArtifactInstall]  
> 2019-09-24 18:28:03 +0000 UTC debug: statescript: timeout for executing scripts is not defined; using default of 1h0m0s seconds  
> 2019-09-24 18:28:03 +0000 UTC debug: statescript: timeout for executing scripts is not defined; using default of 1h0m0s seconds  
> 2019-09-24 18:28:03 +0000 UTC debug: status reported, response 204 No Content  
> 2019-09-24 18:28:03 +0000 UTC debug: Executing ModuleInstaller.InstallUpdate  
> 2019-09-24 18:28:03 +0000 UTC debug: Calling module: /usr/share/mender/modules/v3/web-file ArtifactInstall /var/lib/mender/modules/v3/payloads/0000/tree  
> 2019-09-24 18:28:03 +0000 UTC info: Update module output: rm:  
> 2019-09-24 18:28:03 +0000 UTC info: Update module output: missing operand  
> 2019-09-24 18:28:03 +0000 UTC info: Update module output: Try ‘rm --help’ for more information.  
> 2019-09-24 18:28:03 +0000 UTC error: Update module terminated abnormally: exit status 123  
> 2019-09-24 18:28:03 +0000 UTC error: transient error: Update module terminated abnormally: exit status 123  
> 2019-09-24 18:28:03 +0000 UTC info: State transition: update-install [ArtifactInstall] → rollback [ArtifactRollback]  
> 2019-09-24 18:28:03 +0000 UTC debug: transitioning to error state  
> 2019-09-24 18:28:03 +0000 UTC debug: statescript: timeout for executing scripts is not defined; using default of 1h0m0s seconds  
> 2019-09-24 18:28:03 +0000 UTC debug: statescript: timeout for executing scripts is not defined; using default of 1h0m0s seconds  
> 2019-09-24 18:28:03 +0000 UTC info: performing rollback  
> 2019-09-24 18:28:03 +0000 UTC debug: Executing ModuleInstaller.Rollback  
> 2019-09-24 18:28:03 +0000 UTC debug: Calling module: /usr/share/mender/modules/v3/web-file ArtifactRollback /var/lib/mender/modules/v3/payloads/0000/tree  
> 2019-09-24 18:28:03 +0000 UTC error: Update module terminated abnormally: exit status 1  
> 2019-09-24 18:28:03 +0000 UTC error: rollback failed: Update module terminated abnormally: exit status 1  
> 2019-09-24 18:28:03 +0000 UTC error: fatal error: Update module terminated abnormally: exit status 1  
> 2019-09-24 18:28:03 +0000 UTC debug: Setting artifact name to web-file-4.0\_INCONSISTENT  
> 2019-09-24 18:28:03 +0000 UTC info: State transition: rollback [ArtifactRollback] → update-error [ArtifactFailure]  
> 2019-09-24 18:28:03 +0000 UTC debug: statescript: timeout for executing scripts is not defined; using default of 1h0m0s seconds  
> 2019-09-24 18:28:03 +0000 UTC debug: statescript: timeout for executing scripts is not defined; using default of 1h0m0s seconds  
> 2019-09-24 18:28:03 +0000 UTC debug: handle update error state  
> 2019-09-24 18:28:03 +0000 UTC debug: Executing ModuleInstaller.Failure  
> 2019-09-24 18:28:03 +0000 UTC debug: Calling module: /usr/share/mender/modules/v3/web-file ArtifactFailure /var/lib/mender/modules/v3/payloads/0000/tree  
> 2019-09-24 18:28:03 +0000 UTC info: State transition: update-error [ArtifactFailure] → cleanup [Error]  
> 2019-09-24 18:28:03 +0000 UTC debug: statescript: timeout for executing scripts is not defined; using default of 1h0m0s seconds  
> 2019-09-24 18:28:03 +0000 UTC debug: statescript: timeout for executing scripts is not defined; using default of 1h0m0s seconds  
> 2019-09-24 18:28:03 +0000 UTC debug: Handling Cleanup state  
> 2019-09-24 18:28:03 +0000 UTC debug: Executing ModuleInstaller.Cleanup  
> 2019-09-24 18:28:03 +0000 UTC debug: Calling module: /usr/share/mender/modules/v3/web-file Cleanup /var/lib/mender/modules/v3/payloads/0000/tree  
> 2019-09-24 18:28:03 +0000 UTC info: State transition: cleanup [Error] → update-status-report [none]  
> 2019-09-24 18:28:03 +0000 UTC debug: statescript: timeout for executing scripts is not defined; using default of 1h0m0s seconds  
> 2019-09-24 18:28:03 +0000 UTC debug: handle update status report state  
> 2019-09-24 18:28:03 +0000 UTC debug: status reported, response 204 No Content  
> 2019-09-24 18:28:03 +0000 UTC debug: attempting to upload deployment logs for failed update

What I think is that the rollback seems to be looking for content in an empty folder. And then it shows the artifact as inconsistent, regardless of whether I make new deploys

![image](https://canada1.discourse-cdn.com/flex036/uploads/mender/original/1X/ef10c8c66fc1bcde1b0a9abfc5527113719ff340.png)

---

<div class="post-metadata">

**Author:** ![drewmoseley](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/drewmoseley/32/47_2.png) [@drewmoseley](https://hub.mender.io/u/drewmoseley)\
**Post date:** [September 25, 2019, 2:05pm UTC](https://hub.mender.io/t/issues-with-rollback-using-directory-update-module/1073/13 "2019-09-25T14:05:54Z")

</div>

Hmm. The relevant part of the log appears to be

> 2019-09-24 18:28:03 +0000 UTC debug: Calling module: /usr/share/mender/modules/v3/web-file ArtifactRollback /var/lib/mender/modules/v3/payloads/0000/tree  
> 2019-09-24 18:28:03 +0000 UTC error: Update module terminated abnormally: exit status 1  
> 2019-09-24 18:28:03 +0000 UTC error: rollback failed: Update module terminated abnormally: exit status 1

@lluiscampos do you know why the update module when trying to rollback could exit abnormally? The only thing I see is if the prev\_files.tar file is missing it will error out.

---

<div class="post-metadata">

**Author:** ![kacf](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/kacf/32/146_2.png) [@kacf](https://hub.mender.io/u/kacf)\
**Post date:** [September 26, 2019, 6:14am UTC](https://hub.mender.io/t/issues-with-rollback-using-directory-update-module/1073/14 "2019-09-26T06:14:26Z")

</div>

> [@Directory](https://hub.mender.io/t/directory/325/45):
>
> 2019-09-24 18:28:03 +0000 UTC debug: Calling module: /usr/share/mender/modules/v3/web-file ArtifactInstall /var/lib/mender/modules/v3/payloads/0000/tree  
> 2019-09-24 18:28:03 +0000 UTC info: Update module output: rm:  
> 2019-09-24 18:28:03 +0000 UTC info: Update module output: missing operand  
> 2019-09-24 18:28:03 +0000 UTC info: Update module output: Try ‘rm --help’ for more information.  
> 2019-09-24 18:28:03 +0000 UTC error: Update module terminated abnormally: exit status 123  
> 2019-09-24 18:28:03 +0000 UTC error: transient error: Update module terminated abnormally: exit status 123

Earlier there are these errors also, during ArtifactInstall. Maybe the backup is never created?

---

<div class="post-metadata">

**Author:** ![lluiscampos](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/lluiscampos/32/112_2.png) [@lluiscampos](https://hub.mender.io/u/lluiscampos)\
**Post date:** [September 26, 2019, 8:47am UTC](https://hub.mender.io/t/issues-with-rollback-using-directory-update-module/1073/15 "2019-09-26T08:47:46Z")

</div>

@kacf @drewmoseley @bonini_lucas yes, that is what is puzzling me as well (I had some PMs with @bonini_lucas on this), that the actual failure is in the `rm` command in `ArtifactInstall` stage, not in the rollback.

It must be a bug in this `web-file` Update Module. The code is here: [https://docs.mender.io/2.1/devices/update-modules#advanced-example-update-module-with-rollback](https://docs.mender.io/2.1/devices/update-modules#advanced-example-update-module-with-rollback)

One obvious error in the code is that the first install always assume there are files in `/var/www`, which might not be the case. So instead of `find /var/www -maxdepth 1 -type f | xargs rm` we should first check if there are any files there.

@bonini_lucas, please try replacing that line with something like:

```auto
if $(ls /var/www >/dev/null 2>&1); then
  find /var/www -maxdepth 1 -type f | xargs rm
if 

```

---

<div class="post-metadata">

**Author:** ![kacf](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/kacf/32/146_2.png) [@kacf](https://hub.mender.io/u/kacf)\
**Post date:** [September 26, 2019, 8:59am UTC](https://hub.mender.io/t/issues-with-rollback-using-directory-update-module/1073/16 "2019-09-26T08:59:57Z")

</div>

Better yet, just:

```auto
find /var/www -maxdepth 1 -type f | xargs -r rm

```

Notice the `-r` argument. Then you don’t need the `if`.
