# Is it sane to override launch.service if INITSYSTEM=on?

**URL:** <https://forums.balena.io/t/is-it-sane-to-override-launch-service-if-initsystem-on/1785>\
**Category:** Product support\
**Tags:** systemd\
**Created:** [August 31, 2017, 1:42am UTC](https://forums.balena.io/t/is-it-sane-to-override-launch-service-if-initsystem-on/1785 "2017-08-31T01:42:56Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![bgentry](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/bgentry/32/419_2.png) [@bgentry](https://forums.balena.io/u/bgentry)\
**Post date:** [August 31, 2017, 1:42am UTC](https://forums.balena.io/t/is-it-sane-to-override-launch-service-if-initsystem-on/1785/1 "2017-08-31T01:42:56Z")

</div>

When using `INITSYSTEM=on`, Resin no longer restarts my main process when it crashes (it doesn’t restart the container either).

The systemd unit `/etc/systemd/system/launch.service` is pretty simple:

```auto
[Unit]
Description=Resin.io User Application

[Service]
EnvironmentFile=/etc/docker.env
ExecStart=/etc/resinApp.sh
StandardOutput=tty
StandardError=tty
TTYPath=/dev/console

[Install]
WantedBy=basic.target

```

If I want to add behaviors to this service, is it sane to just overwrite this file with a modified version? If I do that, what’s the likelihood of it breaking with future ResinOS updates?

If it’s considered a normal use case to override this service, it also might be good to document it alongside the `INITSYSTEM=on` docs.

Cheers ✌

---

<div class="post-metadata">

**Author:** ![floion](https://avatars.discourse-cdn.com/v4/letter/f/45deac/32.png) [@floion](https://forums.balena.io/u/floion)\
**Post date:** [August 31, 2017, 11:20am UTC](https://forums.balena.io/t/is-it-sane-to-override-launch-service-if-initsystem-on/1785/2 "2017-08-31T11:20:34Z")

</div>

Hi, can you paste your Dockerfile please?  
And is this service you pasted here intended for the user container?

---

<div class="post-metadata">

**Author:** ![bgentry](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/bgentry/32/419_2.png) [@bgentry](https://forums.balena.io/u/bgentry)\
**Post date:** [August 31, 2017, 4:45pm UTC](https://forums.balena.io/t/is-it-sane-to-override-launch-service-if-initsystem-on/1785/3 "2017-08-31T16:45:01Z")

</div>

Hi @floion,

Is the Dockerfile actually relevant here? I meant this as a general question as to whether it’s considered a good or bad practice to override `launch.service` (the systemd unit that launches the user application, such as [this one](https://github.com/resin-io-library/base-images/blob/master/debian/launch.service)).

I’ve read in other forum posts that with `INITSYSTEM=on`, the container no longer gets restarted when the application crashes, and that this is expected behavior ([here](https://forums.balena.io/t/raspberry-pi-resets-every-40-seconds-if-offline/1556/15), for example). And in that specific post, @imrehg recommends overriding the application launch service, which I guess answers my question on whether it’s acceptable to do that.

In either case, it might be worth documenting all this stuff in the `INITSYSTEM` documentation: [https://docs.resin.io/runtime/runtime/#init-system](https://docs.resin.io/runtime/runtime/#init-system)

---

<div class="post-metadata">

**Author:** ![floion](https://avatars.discourse-cdn.com/v4/letter/f/45deac/32.png) [@floion](https://forums.balena.io/u/floion)\
**Post date:** [September 13, 2017, 4:49am UTC](https://forums.balena.io/t/is-it-sane-to-override-launch-service-if-initsystem-on/1785/4 "2017-09-13T04:49:19Z")

</div>

I do believe this will get overwritten with application updates so it would not be safe to overwrite this service.  
@nghiant2710 please correct me if I am wrong

---

<div class="post-metadata">

**Author:** ![bgentry](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/bgentry/32/419_2.png) [@bgentry](https://forums.balena.io/u/bgentry)\
**Post date:** [September 13, 2017, 5:19am UTC](https://forums.balena.io/t/is-it-sane-to-override-launch-service-if-initsystem-on/1785/5 "2017-09-13T05:19:43Z")

</div>

I see, that’s what I was afraid of. So is there any officially supported way to ensure that my app gets restarted if it crashes, even when using `INITSYSTEM=on`?

---

<div class="post-metadata">

**Author:** ![nghiant2710](https://avatars.discourse-cdn.com/v4/letter/n/90db22/32.png) [@nghiant2710](https://forums.balena.io/u/nghiant2710)\
**Post date:** [September 13, 2017, 6:44am UTC](https://forums.balena.io/t/is-it-sane-to-override-launch-service-if-initsystem-on/1785/6 "2017-09-13T06:44:43Z")

</div>

@bgentry, you can override the `launch.service` without any problems at all. Moreover, you can add a new service if you don’t want to use the default service, just remember to enable by doing `systemctl enable <service>` in your Dockerfile.

---

<div class="post-metadata">

**Author:** ![bgentry](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/bgentry/32/419_2.png) [@bgentry](https://forums.balena.io/u/bgentry)\
**Post date:** [September 13, 2017, 8:33pm UTC](https://forums.balena.io/t/is-it-sane-to-override-launch-service-if-initsystem-on/1785/7 "2017-09-13T20:33:29Z")

</div>

Thanks, that’s great to know. Keep up the good work 🙂

---

<div class="post-metadata">

**Author:** ![exposedwiring](https://avatars.discourse-cdn.com/v4/letter/e/b4bc9f/32.png) [@exposedwiring](https://forums.balena.io/u/exposedwiring)\
**Post date:** [August 10, 2018, 5:36am UTC](https://forums.balena.io/t/is-it-sane-to-override-launch-service-if-initsystem-on/1785/8 "2018-08-10T05:36:19Z")

</div>

Hello, I have a similar interest to override the default launch behavior because I want these properties:

```auto
[Service]
Type=oneshot
Restart=no
RemainAfterExit=yes

```

The reason that I do this is that I want the entrypoint script to terminate completely and leave system to run my application as a separate unit file (which I set up in my entrypoint script), but to preserve the system status as healthy (graceful exit; do not attempt to restart entrypoint).

However, since updating two of my devices to Resin OS 2.13.6+rev1 (from 2.12 on a Pi2 and Pi3 device), the launch service fails very early after loading any new container. Simply starting the unit interactively works without error.

```auto
root@raspberry-pi2-0e771b3:~# journalctl -u launch
-- Logs begin at Thu 2018-08-09 22:09:35 UTC, end at Fri 2018-08-10 05:17:52 UTC. --
Aug 09 22:09:38 raspberry-pi2-0e771b3 systemd[1]: Starting Resin.io User Application...
Aug 09 22:09:39 raspberry-pi2-0e771b3 systemd[1]: launch.service: Main process exited, code=exited, status=1/FAILURE
Aug 09 22:09:39 raspberry-pi2-0e771b3 systemd[1]: Failed to start Resin.io User Application.
Aug 09 22:09:39 raspberry-pi2-0e771b3 systemd[1]: launch.service: Unit entered failed state.
Aug 09 22:09:39 raspberry-pi2-0e771b3 systemd[1]: launch.service: Failed with result 'exit-code'.
root@raspberry-pi2-0e771b3:~# systemctl start launch
root@raspberry-pi2-0e771b3:~# echo $?
0
root@raspberry-pi2-0e771b3:~# systemctl status launch
● launch.service - Resin.io User Application
   Loaded: loaded (/etc/systemd/system/launch.service; enabled; vendor preset: enabled)
  Drop-In: /etc/systemd/system/launch.service.d
           └─app_override.conf, override.conf
   Active: active (exited) since Fri 2018-08-10 07:18:58 SAST; 9min ago
 Main PID: 196 (code=exited, status=0/SUCCESS)
   CGroup: /docker/6d3b4774dfcbc88d5b33da59d7a439f1a3725fb9227d72ba74ad2244aeb4652c/system.slice/launch.service

...
Aug 10 07:18:58 raspberry-pi2-0e771b3 systemd[1]: Started Resin.io User Application.
root@raspberry-pi2-0e771b3:~#

```

For completeness, how are the relevant portions of my Dockerfile:

```auto
FROM resin/raspberry-pi2-debian:stretch
ENV INITSYSTEM on
...
# Resin systemd
COPY ./config/systemd.launch.service /etc/systemd/system/launch.service.d/app_override.conf

CMD ["/opt/app/entrypoint.sh"]

```

For my Pi3 I use `FROM resin/raspberrypi3-debian:stretch`.

Is there a way to get any more debugging information about why the launch service fails when launched upon container update? Just to emphasize, the launch service on both devices works as intended, without error if run interactively.

---

<div class="post-metadata">

**Author:** ![exposedwiring](https://avatars.discourse-cdn.com/v4/letter/e/b4bc9f/32.png) [@exposedwiring](https://forums.balena.io/u/exposedwiring)\
**Post date:** [August 10, 2018, 4:21pm UTC](https://forums.balena.io/t/is-it-sane-to-override-launch-service-if-initsystem-on/1785/11 "2018-08-10T16:21:15Z")

</div>

Just an update on this. When adding some debug logging to the top of my entrypoint script, my Pi3 device appears to be loading the entrypoint via the launch unit without any problems now (with the expected log message appearing).

```auto
Aug 10 16:15:15 raspberrypi3-6da19ce root: DEBUG: entrypoint reached!

```

I’ll report back on further problems if and when I see them.
