Why does my app exit after running?

I’ve got an app that’s meant to broadcast as an Apple Time Capsule for backups via my WiFi but the logs show the app exiting after the script’s run.

Full source is here

Entrypoint file:

#!/bin/bash

# create the mount directory
mkdir -p /media/tm
# add fstab entry
echo "/dev/sda2 /media/tm hfsplus force,rw,user,auto 0 0" >> /etc/fstab
# mount it all
mount -a

systemctl enable avahi-daemon
systemctl enable netatalk


# start services
service dbus start
service avahi-daemon start
netatalk start

Logs

07.07.17 18:24:44 (+0500) Restarting application 'registry2.resin.io/pwnbox/8dc5899d88c88cbd30f9a6196d7a310a3397581f'
07.07.17 18:10:25 (+0500) Synchronizing state for avahi-daemon.service with sysvinit using update-rc.d...
07.07.17 18:10:25 (+0500) Executing /usr/sbin/update-rc.d avahi-daemon defaults
07.07.17 18:10:26 (+0500) Executing /usr/sbin/update-rc.d avahi-daemon enable
07.07.17 18:10:26 (+0500) Created symlink from /etc/systemd/system/multi-user.target.wants/netatalk.service to /lib/systemd/system/netatalk.service.
07.07.17 18:10:26 (+0500) [....] Starting system message bus: dbus[ ok .
07.07.17 18:10:26 (+0500) [....] Starting Avahi mDNS/DNS-SD Daemon: avahi-daemon[ ok .
07.07.17 18:10:29 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:10:29 (+0500) Synchronizing state for avahi-daemon.service with sysvinit using update-rc.d...
07.07.17 18:10:29 (+0500) Executing /usr/sbin/update-rc.d avahi-daemon defaults
07.07.17 18:10:30 (+0500) Executing /usr/sbin/update-rc.d avahi-daemon enable
07.07.17 18:10:30 (+0500) [....] Removing stale PID file /var/run/dbus/pid.[ ok .
07.07.17 18:10:30 (+0500) [....] Starting system message bus: dbus[ ok .
07.07.17 18:10:30 (+0500) [....] Starting Avahi mDNS/DNS-SD Daemon: avahi-daemonProcess 57 died: No such process; trying to remove PID file. (/var/run/avahi-daemon//pid)
07.07.17 18:10:30 (+0500) [ ok .
07.07.17 18:10:33 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:10:33 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:10:33 (+0500) Synchronizing state for avahi-daemon.service with sysvinit using update-rc.d...
07.07.17 18:10:33 (+0500) Executing /usr/sbin/update-rc.d avahi-daemon defaults
07.07.17 18:10:33 (+0500) Executing /usr/sbin/update-rc.d avahi-daemon enable
07.07.17 18:10:33 (+0500) [....] Removing stale PID file /var/run/dbus/pid.[ ok .
07.07.17 18:10:34 (+0500) [....] Starting system message bus: dbus[ ok .
07.07.17 18:10:34 (+0500) [....] Starting Avahi mDNS/DNS-SD Daemon: avahi-daemonProcess 78 died: No such process; trying to remove PID file. (/var/run/avahi-daemon//pid)
07.07.17 18:10:34 (+0500) [ ok .
07.07.17 18:10:36 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:10:36 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:10:36 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:10:36 (+0500) Synchronizing state for avahi-daemon.service with sysvinit using update-rc.d...
07.07.17 18:10:36 (+0500) Executing /usr/sbin/update-rc.d avahi-daemon defaults
07.07.17 18:10:36 (+0500) Executing /usr/sbin/update-rc.d avahi-daemon enable
07.07.17 18:10:37 (+0500) [....] Removing stale PID file /var/run/dbus/pid.[ ok .
07.07.17 18:10:37 (+0500) [....] Starting system message bus: dbus[ ok .
07.07.17 18:10:37 (+0500) [....] Starting Avahi mDNS/DNS-SD Daemon: avahi-daemonProcess 78 died: No such process; trying to remove PID file. (/var/run/avahi-daemon//pid)
07.07.17 18:10:37 (+0500) [ ok .
07.07.17 18:10:40 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:10:40 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:10:40 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:10:40 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:10:40 (+0500) Synchronizing state for avahi-daemon.service with sysvinit using update-rc.d...
07.07.17 18:10:40 (+0500) Executing /usr/sbin/update-rc.d avahi-daemon defaults
07.07.17 18:10:40 (+0500) Executing /usr/sbin/update-rc.d avahi-daemon enable
07.07.17 18:10:40 (+0500) [....] Removing stale PID file /var/run/dbus/pid.[ ok .
07.07.17 18:10:40 (+0500) [....] Starting system message bus: dbus[ ok .
07.07.17 18:10:40 (+0500) [....] Starting Avahi mDNS/DNS-SD Daemon: avahi-daemonProcess 78 died: No such process; trying to remove PID file. (/var/run/avahi-daemon//pid)
07.07.17 18:10:40 (+0500) [ ok .
07.07.17 18:10:44 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:10:44 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:10:44 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:10:44 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:10:44 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:10:44 (+0500) Synchronizing state for avahi-daemon.service with sysvinit using update-rc.d...
07.07.17 18:10:44 (+0500) Executing /usr/sbin/update-rc.d avahi-daemon defaults
07.07.17 18:10:44 (+0500) Executing /usr/sbin/update-rc.d avahi-daemon enable
07.07.17 18:10:44 (+0500) [....] Removing stale PID file /var/run/dbus/pid.[ ok .
07.07.17 18:10:44 (+0500) [....] Starting system message bus: dbus[ ok .
07.07.17 18:10:44 (+0500) [....] Starting Avahi mDNS/DNS-SD Daemon: avahi-daemonProcess 78 died: No such process; trying to remove PID file. (/var/run/avahi-daemon//pid)
07.07.17 18:10:44 (+0500) [ ok .
07.07.17 18:10:49 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:10:49 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:10:49 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:10:49 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:10:49 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:10:49 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:10:49 (+0500) Synchronizing state for avahi-daemon.service with sysvinit using update-rc.d...
07.07.17 18:10:49 (+0500) Executing /usr/sbin/update-rc.d avahi-daemon defaults
07.07.17 18:10:49 (+0500) Executing /usr/sbin/update-rc.d avahi-daemon enable
07.07.17 18:10:50 (+0500) [....] Removing stale PID file /var/run/dbus/pid.[ ok .
07.07.17 18:10:50 (+0500) [....] Starting system message bus: dbus[ ok .
07.07.17 18:10:50 (+0500) [....] Starting Avahi mDNS/DNS-SD Daemon: avahi-daemonProcess 78 died: No such process; trying to remove PID file. (/var/run/avahi-daemon//pid)
07.07.17 18:10:50 (+0500) [ ok .
07.07.17 18:10:59 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:10:59 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:10:59 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:10:59 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:10:59 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:10:59 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:10:59 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:10:59 (+0500) Synchronizing state for avahi-daemon.service with sysvinit using update-rc.d...
07.07.17 18:10:59 (+0500) Executing /usr/sbin/update-rc.d avahi-daemon defaults
07.07.17 18:10:59 (+0500) Executing /usr/sbin/update-rc.d avahi-daemon enable
07.07.17 18:10:59 (+0500) [....] Removing stale PID file /var/run/dbus/pid.[ ok .
07.07.17 18:10:59 (+0500) [....] Starting system message bus: dbus[ ok .
07.07.17 18:10:59 (+0500) [....] Starting Avahi mDNS/DNS-SD Daemon: avahi-daemonProcess 78 died: No such process; trying to remove PID file. (/var/run/avahi-daemon//pid)
07.07.17 18:10:59 (+0500) [ ok .
07.07.17 18:11:14 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:11:14 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:11:14 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:11:14 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:11:14 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:11:14 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:11:14 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:11:14 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:11:14 (+0500) Synchronizing state for avahi-daemon.service with sysvinit using update-rc.d...
07.07.17 18:11:14 (+0500) Executing /usr/sbin/update-rc.d avahi-daemon defaults
07.07.17 18:11:15 (+0500) Executing /usr/sbin/update-rc.d avahi-daemon enable
07.07.17 18:11:15 (+0500) [....] Removing stale PID file /var/run/dbus/pid.[ ok .
07.07.17 18:11:15 (+0500) [....] Starting system message bus: dbus[ ok .
07.07.17 18:11:15 (+0500) [....] Starting Avahi mDNS/DNS-SD Daemon: avahi-daemonProcess 79 died: No such process; trying to remove PID file. (/var/run/avahi-daemon//pid)
07.07.17 18:11:15 (+0500) [ ok .
07.07.17 18:11:43 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:11:43 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:11:43 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:11:43 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:11:43 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:11:43 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:11:43 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:11:43 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:11:43 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:11:44 (+0500) Synchronizing state for avahi-daemon.service with sysvinit using update-rc.d...
07.07.17 18:11:44 (+0500) Executing /usr/sbin/update-rc.d avahi-daemon defaults
07.07.17 18:11:44 (+0500) Executing /usr/sbin/update-rc.d avahi-daemon enable
07.07.17 18:11:44 (+0500) [....] Removing stale PID file /var/run/dbus/pid.[ ok .
07.07.17 18:11:44 (+0500) [....] Starting system message bus: dbus[ ok .
07.07.17 18:11:44 (+0500) [....] Starting Avahi mDNS/DNS-SD Daemon: avahi-daemonProcess 78 died: No such process; trying to remove PID file. (/var/run/avahi-daemon//pid)
07.07.17 18:11:44 (+0500) [ ok .
07.07.17 18:12:38 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:12:38 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:12:38 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:12:38 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:12:38 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:12:38 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:12:38 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:12:38 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:12:38 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:12:38 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:12:38 (+0500) Synchronizing state for avahi-daemon.service with sysvinit using update-rc.d...
07.07.17 18:12:38 (+0500) Executing /usr/sbin/update-rc.d avahi-daemon defaults
07.07.17 18:12:39 (+0500) Executing /usr/sbin/update-rc.d avahi-daemon enable
07.07.17 18:12:39 (+0500) [....] Removing stale PID file /var/run/dbus/pid.[ ok .
07.07.17 18:12:39 (+0500) [....] Starting system message bus: dbus[ ok .
07.07.17 18:12:39 (+0500) [....] Starting Avahi mDNS/DNS-SD Daemon: avahi-daemonProcess 78 died: No such process; trying to remove PID file. (/var/run/avahi-daemon//pid)
07.07.17 18:12:39 (+0500) [ ok .
07.07.17 18:14:24 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:14:24 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:14:24 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:14:24 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:14:24 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:14:24 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:14:24 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:14:24 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:14:24 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:14:24 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:14:24 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:14:24 (+0500) Synchronizing state for avahi-daemon.service with sysvinit using update-rc.d...
07.07.17 18:14:24 (+0500) Executing /usr/sbin/update-rc.d avahi-daemon defaults
07.07.17 18:14:24 (+0500) Executing /usr/sbin/update-rc.d avahi-daemon enable
07.07.17 18:14:25 (+0500) [....] Removing stale PID file /var/run/dbus/pid.[ ok .
07.07.17 18:14:25 (+0500) [....] Starting system message bus: dbus[ ok .
07.07.17 18:14:25 (+0500) [....] Starting Avahi mDNS/DNS-SD Daemon: avahi-daemonProcess 78 died: No such process; trying to remove PID file. (/var/run/avahi-daemon//pid)
07.07.17 18:14:25 (+0500) [ ok .
07.07.17 18:17:52 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:17:52 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:17:52 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:17:52 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:17:52 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:17:52 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:17:52 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:17:52 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:17:52 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:17:52 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:17:52 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:17:52 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:17:52 (+0500) Synchronizing state for avahi-daemon.service with sysvinit using update-rc.d...
07.07.17 18:17:52 (+0500) Executing /usr/sbin/update-rc.d avahi-daemon defaults
07.07.17 18:17:52 (+0500) Executing /usr/sbin/update-rc.d avahi-daemon enable
07.07.17 18:17:53 (+0500) [....] Removing stale PID file /var/run/dbus/pid.[ ok .
07.07.17 18:17:53 (+0500) [....] Starting system message bus: dbus[ ok .
07.07.17 18:17:53 (+0500) [....] Starting Avahi mDNS/DNS-SD Daemon: avahi-daemonProcess 78 died: No such process; trying to remove PID file. (/var/run/avahi-daemon//pid)
07.07.17 18:17:53 (+0500) [ ok .
07.07.17 18:24:44 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:24:44 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:24:44 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:24:44 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:24:44 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:24:44 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:24:44 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:24:44 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:24:44 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:24:44 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:24:44 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:24:44 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:24:44 (+0500) mount: /dev/sda2 is already mounted or /media/tm busy
07.07.17 18:24:45 (+0500) Synchronizing state for avahi-daemon.service with sysvinit using update-rc.d...
07.07.17 18:24:45 (+0500) Executing /usr/sbin/update-rc.d avahi-daemon defaults
07.07.17 18:24:45 (+0500) Executing /usr/sbin/update-rc.d avahi-daemon enable
07.07.17 18:24:45 (+0500) [....] Removing stale PID file /var/run/dbus/pid.[ ok .
07.07.17 18:24:45 (+0500) [....] Starting system message bus: dbus[ ok .
07.07.17 18:24:45 (+0500) [....] Starting Avahi mDNS/DNS-SD Daemon: avahi-daemonProcess 78 died: No such process; trying to remove PID file. (/var/run/avahi-daemon//pid)
07.07.17 18:24:45 (+0500) [ ok .
07.07.17 18:24:46 (+0500) Application exited 'registry2.resin.io/pwnbox/8dc5899d88c88cbd30f9a6196d7a310a3397581f'

Hey, it looks like the problem is that you’re running with the initsystem off, which means that your entrypoint process is expected to stay running for the duration of your application as when that process exits then the container also exits, whereas with the initsystem on then the initsystem is the long running process and handles watching background processes. In the case of initsystem off this is usually handled by starting a long-running process synchronously in your script, however for you case it looks like the best option would be to set ENV INITSYSTEM on in your dockerfile: https://docs.resin.io/runtime/runtime/#init-system as it looks like you’re expecting to be using systemd

Thanks Page!