# Best custom hook for service enable / disable and file copy in data partition

**URL:** <https://hub.mender.io/t/best-custom-hook-for-service-enable-disable-and-file-copy-in-data-partition/3522>\
**Category:** General Discussions\
**Tags:** mender-convert\
**Created:** [April 16, 2021, 9:34am UTC](https://hub.mender.io/t/best-custom-hook-for-service-enable-disable-and-file-copy-in-data-partition/3522 "2021-04-16T09:34:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![profff](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/profff/32/1117_2.png) [@profff](https://hub.mender.io/u/profff)\
**Post date:** [April 16, 2021, 9:34am UTC](https://hub.mender.io/t/best-custom-hook-for-service-enable-disable-and-file-copy-in-data-partition/3522/1 "2021-04-16T09:34:28Z")

</div>

hello  
when converting an image i would need to  
disable `mender-client.service` (or not enable it)  
copy some file in `/data/mender` and `/usr/share/mender`  
and add one or tow new services files  
what would be the best custom hook ?  
I was thinking at `USER_LOCAL_MODIFY_HOOK` ?  
what do you think ??  
and where could I find in docker builder the right volume to get the new files I want to add into image from

---

<div class="post-metadata">

**Author:** ![profff](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/profff/32/1117_2.png) [@profff](https://hub.mender.io/u/profff)\
**Post date:** [April 16, 2021, 12:35pm UTC](https://hub.mender.io/t/best-custom-hook-for-service-enable-disable-and-file-copy-in-data-partition/3522/2 "2021-04-16T12:35:35Z")

</div>

I tried to add this config file :  
`preauth_config` :

```auto
disable_mender_client_service() {
    log_info "disable mender-client.service."
    run_and_log_cmd "sudo rm -f work/rootfs/etc/systemd/system/multi-user.target.wants/mender-client.service"
}
USER_LOCAL_MODIFY_HOOK+=(disable_mender_client_service)

copy_preauth_files() {
    log_info "copy preauth files"
    run_and_log_cmd "sudo mkdir -p work/rootfs/data/mender/preauth"
    run_and_log_cmd "sudo cp preauth/* work/rootfs/data/mender/preauth"
}
USER_LOCAL_MODIFY_HOOK+=(copy_preauth_files)

change_iddentity_script() {
    log_info "change identity script"
    run_and_log_cmd "sudo cp preauth/mender-device-identity work/rootfs/usr/share/mender/iddentity/"
}
USER_LOCAL_MODIFY_HOOK+=(change_iddentity_script)

enable_preauth_service() {
    log_info "copy and enable preauth.service"
    run_and_log_cmd "sudo cp preauth/preauth.service work/rootfs/etc/systemd/system/"
    run_and_log_cmd "sudo ln -sf /lib/systemd/system/preauth.service work/rootfs/etc/systemd/system/multi-user.target.wants/preauth.service"
}
USER_LOCAL_MODIFY_HOOK+=(enable_preauth_service)

```

I call mender-convert with `--config config/preaut_config`  
I well seen the use in log :

```auto
2021-04-16 12:15:57 [INFO] [mender-convert-modify] Using configuration file: configs/preauth_config

```

but when hook time is coming specific hook time nothing logged

```auto
2021-04-16 12:16:04 [INFO] [mender-convert-modify] Performing user/local specific modifications (if any)
2021-04-16 12:16:04 [INFO] [mender-convert-modify] Running hook: user_local_modify
2021-04-16 12:16:04 [INFO] [mender-convert-modify] Applying rootfs overlay: rootfs_overlay_hosted/
2021-04-16 12:16:04 [DEBUG] [mender-convert-modify] Running: (./mender-convert-modify:369): run_and_log_cmd():  

	sending incremental file list
./
etc/
etc/mender/
etc/mender/mender.conf

sent 1,023 bytes received 50 bytes 2,146.00 bytes/sec
total size is 846 speedup is 0.79

```

---

<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:** [April 16, 2021, 1:59pm UTC](https://hub.mender.io/t/best-custom-hook-for-service-enable-disable-and-file-copy-in-data-partition/3522/3 "2021-04-16T13:59:48Z")

</div>

The variable name is plural: `USER_LOCAL_MODIFY_HOOKS`

---

<div class="post-metadata">

**Author:** ![profff](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/profff/32/1117_2.png) [@profff](https://hub.mender.io/u/profff)\
**Post date:** [April 16, 2021, 2:24pm UTC](https://hub.mender.io/t/best-custom-hook-for-service-enable-disable-and-file-copy-in-data-partition/3522/4 "2021-04-16T14:24:26Z")

</div>

how I could have missed that … sorry all my apologies

---

<div class="post-metadata">

**Author:** ![freddy47](https://avatars.discourse-cdn.com/v4/letter/f/57b2e6/32.png) [@freddy47](https://hub.mender.io/u/freddy47)\
**Post date:** [March 11, 2022, 8:22am UTC](https://hub.mender.io/t/best-custom-hook-for-service-enable-disable-and-file-copy-in-data-partition/3522/5 "2022-03-11T08:22:01Z")

</div>

I also did that because it is called HOOK in the docs, but should be HOOKS 😉
