# Cannot make Udev rules without init system.

**URL:** <https://forums.balena.io/t/cannot-make-udev-rules-without-init-system/50209>\
**Category:** balenaOS\
**Created:** [December 11, 2019, 12:55am UTC](https://forums.balena.io/t/cannot-make-udev-rules-without-init-system/50209 "2019-12-11T00:55:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![matthewcroughan](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/matthewcroughan/32/9424_2.png) [@matthewcroughan](https://forums.balena.io/u/matthewcroughan)\
**Post date:** [December 11, 2019, 12:55am UTC](https://forums.balena.io/t/cannot-make-udev-rules-without-init-system/50209/1 "2019-12-11T00:55:32Z")

</div>

I want to make stuff happen without systemd being involved. My desired rule is something like this:

`ACTION=="add", KERNEL=="tty*", RUN+="/bin/sh -c '/app/script.sh'"`

but I can only obtain this functionality like this, with systemd being present:

```auto
ACTION=="add", KERNEL=="tty*", \
   TAG+="systemd", ENV{SYSTEMD_WANTS}="script@%k.service"

```

With the following systemd service:

```auto
[Unit]
Description=Run script when tty* device plugged in
BindsTo=dev-%i.device
After=dev-%i.device

[Service]
Type=oneshot
User=root
RemainAfterExit=yes
ExecStart=/app/script.sh

```

This is inconsistent with [https://github.com/tmigone/balena-udev-examples/tree/master/usb-copy](https://github.com/tmigone/balena-udev-examples/tree/master/usb-copy) which seems to work without systemd. Any advice? Thanks!

---

<div class="post-metadata">

**Author:** ![matthewcroughan](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/matthewcroughan/32/9424_2.png) [@matthewcroughan](https://forums.balena.io/u/matthewcroughan)\
**Post date:** [December 11, 2019, 1:13am UTC](https://forums.balena.io/t/cannot-make-udev-rules-without-init-system/50209/2 "2019-12-11T01:13:37Z")

</div>

Apologies, I believe I’ve solved the problem as it’s now working as expected. The problem was I was using `UDEV=1` instead of `UDEV=on`.

---

<div class="post-metadata">

**Author:** ![matthewcroughan](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/matthewcroughan/32/9424_2.png) [@matthewcroughan](https://forums.balena.io/u/matthewcroughan)\
**Post date:** [December 11, 2019, 1:36am UTC](https://forums.balena.io/t/cannot-make-udev-rules-without-init-system/50209/3 "2019-12-11T01:36:11Z")

</div>

The documentation suggests using UDEV=1 here, which is why I did so. [https://www.balena.io/docs/reference/base-images/base-images/](https://www.balena.io/docs/reference/base-images/base-images/)

---

<div class="post-metadata">

**Author:** ![matthewcroughan](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/matthewcroughan/32/9424_2.png) [@matthewcroughan](https://forums.balena.io/u/matthewcroughan)\
**Post date:** [December 11, 2019, 1:43am UTC](https://forums.balena.io/t/cannot-make-udev-rules-without-init-system/50209/4 "2019-12-11T01:43:02Z")

</div>

Hmm. So the documentation suggests that 1, true and on are all evaluated as on. I will double check this later.

However, I am now having a separate issue.

The script I want to run is a curl script to a local container. Let’s say the container’s name is `container1`.

With systemd I can run:

`curl -siL -X POST -H "Content-Type: application/json" -H "X-Api-Key: ${APIKEY}" http://container1/api/connection -d '{"command":"connect"}'`

Without systemd I cannot run this, as it returns nothing. The base image documentation states:

“ **Note:** The new balenalib base images make sure `udevd` runs in its own network namespace,”

I believe this has something to do with it? This is really annoying, is there any way around this?

---

<div class="post-metadata">

**Author:** ![matthewcroughan](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/matthewcroughan/32/9424_2.png) [@matthewcroughan](https://forums.balena.io/u/matthewcroughan)\
**Post date:** [December 11, 2019, 2:06am UTC](https://forums.balena.io/t/cannot-make-udev-rules-without-init-system/50209/5 "2019-12-11T02:06:50Z")

</div>

I see in the balena base image `unshare` is used to cause my problem here.

I didn’t realise udev functionality would be as simple as running `udevd --daemon &` at the start of my entry. I would say I’m happy with this solution 🙂

> <https://github.com/balena-io-library/base-images/blob/eed487b93c74028f90326893f2201dbcd6f4e7b2/balena-base-images/armv7hf/debian/stretch/run/entry.sh#L43>

---

<div class="post-metadata">

**Author:** ![CameronDiver](https://avatars.discourse-cdn.com/v4/letter/c/2acd7d/32.png) [@CameronDiver](https://forums.balena.io/u/CameronDiver)\
**Post date:** [December 11, 2019, 9:27am UTC](https://forums.balena.io/t/cannot-make-udev-rules-without-init-system/50209/6 "2019-12-11T09:27:34Z")

</div>

Looks like you managed to get there in the end? Thanks for posting the results so anybody stuck in a similar situation might be helped!

A small note, `1`, `on` and `true` will indeed all evaluate to truthy when setting env vars in the base image.
