Can't find crontab or systemctl in Beaglebone debian image, what am I doing wrong?

Hi, based on the documentation and the “cron-example” project, I thought that if I just added a similar line to my dockerfile, I’d be in business. However, my container can’t find crontab

Connecting to 150deeb26a5b3d03c15f8bc1c64e0c8d...
Spawning shell...
root@150deeb:/usr/src/app# crontab
bash: crontab: command not found
root@150deeb:/usr/src/app# crontab -e
bash: crontab: command not found
root@150deeb:/usr/src/app# systemctl
bash: systemctl: command not found
root@150deeb:/usr/src/app#

…as you see, systemctl is also missing, despite including the line ENV INITSYSTEM on in my Dockerfile.

FWIW, I’m using the latest debian base image for Beaglebone Black.

I’m pretty confused, because I have not been doing any crazy modifications to the default example projects. Anyone who could help me figure out what’s going wrong here would be much appreciated!

AKA

editing to update: the container doesn’t even build successfully when I include a crontab reference:

[main]  Removing intermediate container d5aacaafd2a8
[main]  Step 10/11 : RUN echo "*/1 * * * * cd /usr/src/app/src && python3 spt.py" | crontab
[main]   ---> Running in fd051350c519
[main]  /bin/sh: 1: crontab: not found

Hey @aka this is really strange, as I just built your project successfully (with the crontab reference) for a raspberry pi application. What device type are you building for? Perhaps one of our base images has been built in an odd way that we haven’t noticed yet.

Hi Cameron, I’m glad to hear it built!

This is the same hardware (two Beaglebones Black) as another issue you helped with this morning: Can't find crontab or systemctl in Beaglebone debian image, what am I doing wrong?

…so I bet the container process is messing up (probably because of something I did), and not starting fully?

There are also some weird errors way earlier in the boot sequence:

26.03.18 09:27:47 (-0400) Starting application 'registry2.resin.io/v2/718afec1999df1a6eb7e9868e00717ba'
26.03.18 09:27:51 (-0400) Started application 'registry2.resin.io/v2/718afec1999df1a6eb7e9868e00717ba'
26.03.18 09:27:51 (-0400) Systemd init system enabled.
INIT: version 2.88 booting
26.03.18 09:27:52 (-0400) [info] Using makefile-style concurrent boot in runlevel S.
26.03.18 09:27:56 (-0400) [....] Filesystem mounted on /dev/shm; setting[warnompatibility bind mount. ... (warning).
26.03.18 09:27:56 (-0400) [....] Please remove this mount from /etc/fstab; it is no longer needed, and it is preventing completion of the transi[warnto /run/shm. ... (warning).
26.03.18 09:27:57 (-0400) [info] Setting the system clock.
26.03.18 09:27:57 (-0400) [info] System Clock set to: Mon Mar 26 13:27:57 UTC 2018.
[ ok .18 09:27:58 (-0400) [....] Activating swap...done.
[ ok .18 09:28:01 (-0400) [....] Activating lvm and md swap...done.
26.03.18 09:28:01 (-0400) [....] Checking file systems...fsck from util-linux 2.25.2
[ ok .18 09:28:01 (-0400) done.
26.03.18 09:28:02 (-0400) [....] Cleaning up temporary files...find: cannot delete `./resin': Device or resource busy
[FAIL.18 09:28:02 (-0400) [....] bootclean: Failure cleaning /tmp. ... failed!
[FAIL.18 09:28:02 (-0400)  failed!
[ ok .18 09:28:05 (-0400) [....] Mounting local filesystems...done.
[ ok .18 09:28:05 (-0400) [....] Activating swapfile swap...done.
[ ok .18 09:28:06 (-0400) [....] Cleaning up temporary files....
[ ok .18 09:28:06 (-0400) [....] Setting kernel variables ...done.
26.03.18 09:28:06 (-0400) /etc/init.d/udev-finish: 21: exec: /lib/udev/udev-finish: not found
[ ok .18 09:28:07 (-0400) [....] Configuring network interfaces...done.
[ ok .18 09:28:08 (-0400) [....] Cleaning up temporary files....
26.03.18 09:28:09 (-0400) [....] startpar: service(s) returned failure:[FAILroot-bootclean.sh ... failed!
INIT: Entering runlevel: 2
26.03.18 09:28:09 (-0400) [info] Using makefile-style concurrent boot in runlevel 2.
[ ok .18 09:28:10 (-0400) [....] Starting system message bus: dbus.
26.03.18 09:28:11 (-0400) [....] Starting Avahi mDNS/DNS-SD Daemon: avah[ ok mon.
[ ok .18 09:28:12 (-0400) [....] Starting DirMngr: dirmngr.
26.03.18 09:28:12 (-0400) Starting redis-server: redis-server.

Hey @aka, can you tell us what is the base image you are using? The INITSYSTEM variable only has effect in the resin/... base images maintained by us, as much as I know, and almost all of them include systemd.

If we may, it would be great to look at your Dockerfile or Dockerfile.template, and any scripts that your CMD in there might refer to!
Thanks!

Sure, I’m using Beaglebone Black’s Debian image (or trying to)…

# base-image for python on any machine using a template variable,
# see more about dockerfile templates here:http://docs.resin.io/pages/deployment/docker-templates
FROM resin/%%RESIN_MACHINE_NAME%%-debian

# RUN apt-get update && apt-get install -y  && \
#    apt-get clean && rm -rf /var/lib/apt/lists/*

RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    python \
    python-pip \
    pkg-config \
    python-dev \
    python-dbus \
    python-setuptools \
    libusb-1.0.0  \
    libusb-1.0.0-dev  \
    git  \
    cython \
    cython3 \
    g++ \
    cmake \
    git-core  \
    libudev-dev  \
    libusbhid-common  \
    libusb-dev \
    build-essential  \
    python-smbus \
    python3 \
    python3-setuptools \
    python3-dbus \
    python3-pip \
    python3-dev \
    python-smbus \
    python-psutil \
    avahi-daemon \
    avahi-utils \
    libnss-mdns \
    redis-server \
    wireless-tools && \
    apt-get clean && rm -rf /var/lib/apt/lists/*


# switch on systemd init system in container
ENV INITSYSTEM on

# Set our working directory
WORKDIR /usr/src/app

# Copy requirements.txt first for better cache on later pushes
COPY ./requirements.txt /requirements.txt

# pip install python deps from requirements.txt on the resin.io build server
#RUN pip install -I -r /requirements.txt
#RUN pip install -r /requirements.txt
RUN pip3 install -r /requirements.txt # blink1 library that i like is only for python3!!

# try to install blink1 pip3 library without hitting pypi repo b/c repo is unmaintained ffs
RUN git clone https://github.com/todbot/blink1.git && cd blink1/commandline && make
RUN cd blink1/python/pypi && python3 setup.py install

# This will copy all files in our root to the working  directory in the container
COPY . ./

RUN echo "*/1 * * * * cd /usr/src/app/src && python3 spt.py >/proc/1/fd/1" | crontab

# main.py will run when container starts up on the device
CMD ["python3","src/main.py"]

Looks like you need to install the cron package explicitly, seems like with that change it works. Can you please try that?

Also, an idea, since you have initsystem enabled, an alternative is using systemd timers instead of cron, described e.g. here https://wiki.archlinux.org/index.php/Systemd/Timers Just a thought, it’s not the same, but similar functionality.

Thanks for the reply! In th first post you can see that systemctl / systemd is also missing.

I’d like to figure out why the base image isn’t behaving as expected, rather than manually install stuff that’s supposed to come with Debian…I think it’s an indicator something more substantial is messed-up.

Also, cron isn’t available:

root@150deeb:/usr/src/app# apt-get install cron
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package cron

Thanks again for any other tips you can think of!

AKA

What do you get if you just add cron \ to the list of packages required in the dockerfile? That may well solve for the immediate problem, whilst we look at the base image.

As a colleague of mine has just pointed out, the following line in the dockerfile tidies the package lists from the build, as there’s no need for that to be deployed to every device in a fleet once the container is built with the correct packages.

If you want to apt-get a package after your container has been built and deployed, you’ll need to do an apt-get update. The recommendation however would be to install the packages as part of building the container, so they’ll persist and you’ll get a consistent execution environment.

Thanks for the replies! Adding cron and systemd to the list of required packages works well once you delete the apt-get clean && rm -rf /var/lib/apt/lists/* stuff…

Weirdly, the CMD still isn’t running properly once the container starts. I reproduced this on another Beaglebone Black here, just in case something basic was wrong with the hardware, but still no luck.

I think the series of errors at the beginning of the container start are probably why the final CMD isn’t running properly, but I’ve had a difficult time Googling errors related to this line:
27.03.18 11:31:11 (-0400) [....] startpar: service(s) returned failure:[FAILroot-bootclean.sh ... failed!

…if I recall correctly, for this project I had to change the update strategy, but otherwise it is a default Beaglebone Black / Debian project. Maybe I should try resetting the update strategy?

Thanks!

AKA

Hmmm, now with cron and systemd installed via the Dockerfile, I’m seeing this error on both Beaglebones:

27.03.18 12:07:43 (-0400) Systemd init system enabled.

27.03.18 12:07:44 (-0400) Failed to insert module 'kdbus': Function notimplemented

27.03.18 12:07:44 (-0400) systemd 230 running in system mode. (+PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ -LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD +IDN)

27.03.18 12:07:44 (-0400) Detected virtualization docker.

27.03.18 12:07:44 (-0400) Detected architecture arm.

27.03.18 12:07:44 (-0400) Set hostname to <0a8df44>.

27.03.18 12:07:44 (-0400) Cannot determine cgroup we are running in: Nomedium found

27.03.18 12:07:44 (-0400) Failed to allocate manager object: No medium found

27.03.18 12:07:45 (-0400) [!!!!!!] Failed to allocate manager object, freezing.

27.03.18 12:07:45 (-0400) Freezing execution.

…I am in way over my head now, as I haven’t much familiarity with boot sequences and container stuff. But perhaps this will help someone else reading this?

AKA

1 Like

Might be the same thing as The "Failed to install release agent" bug is back