title: Why is crond failing to run a non-root crontab on alpine linux?
body: <p>I am having a nasty time running a non-root crontab file on Alpine Linux.</p>
  
  <p>I've been through two other cron related posts and I don't have an answer:</p>
  
  <p><a href="https://askubuntu.com/questions/23009/why-crontab-scripts-are-not-working">https://askubuntu.com/questions/23009/why-crontab-scripts-are-not-working</a></p>
  
  <p><a href="https://serverfault.com/questions/449651/why-is-my-crontab-not-working-and-how-can-i-troubleshoot-it">https://serverfault.com/questions/449651/why-is-my-crontab-not-working-and-how-can-i-troubleshoot-it</a></p>
  
  <p>Here is the setup.</p>
  
  <p>My crontab looks like this:</p>
  
  <pre><code>PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/aws/bin:/home/ec2-user/bin
  SHELL=/bin/bash
  
  * * * * * /opt/monitor/monitor.sh &gt;&gt; /var/log/monitor.log 2&gt;&amp;1
  0 3 * * * /opt/monitor/monitor-log-clean.sh &gt;&gt; /var/log/monitor.log 2&gt;&amp;1
  </code></pre>
  
  <p>My Dockerfile is a little messy now, but only because I have been desperately trying to resolve this. It looks something like this. In short, I add SUID for crontab -e to work as other users, I create my user, I import my crontab file, and then I provide permissions to everything I can think of.</p>
  
  <pre><code>FROM alpine:3.5
  
  # DEPENDENCY TO ALLOW USERS TO RUN crontab -e
  RUN apk add --update busybox-suid
  
  # I LIKE BASH
  RUN apk --no-cache add bash bash-doc
  RUN apk --no-cache add util-linux pciutils usbutils coreutils binutils findutils grep
  
  #... lots of custom stuff ...    
  
  # CREATE USER
  RUN adduser -S robuser &amp;&amp; \
      mkdir -p /home/robuser
  
  # ADD ENTRY POINT
  ADD src/entrypoint.sh /home/robuser/entrypoint.sh
  
  # GIVE MY USER ACCESS
  RUN mkdir /etc/cron.d
  RUN echo "robuser" &gt; /etc/cron.allow
  RUN echo "" &gt;&gt; /etc/cron.allow
  RUN chmod -R 644 /etc/cron.d
  
  # ADD MY CRONTAB
  RUN mkdir -p /var/spool/cron/crontabs
  ADD ./src/crontab.conf /tmp/cloudwatch/crontab.conf
  RUN crontab -u robuser /tmp/cloudwatch/crontab.conf
  
  # DEBUG... GIVE MY USER ACCESS TO EVERYTHING
  RUN chown -R robuser /etc/cron.d
  RUN chmod -R 755 /etc/cron.d
  RUN chown -R robuser /var/spool/cron
  RUN chmod -R 744 /var/spool/cron
  RUN chown robuser /var/spool/cron/crontabs
  RUN chmod 744 /var/spool/cron/crontabs
  RUN chown -R robuser /etc/crontabs
  RUN chmod -R 744 /etc/crontabs
  RUN chown robuser /etc/crontabs/robuser
  RUN chmod -R 744 /etc/crontabs/robuser
  RUN chmod 600 /var/spool/cron/crontabs/robuser
  
  # ADD MY MONITORING PROGRAM
  RUN mkdir -p /opt/monitor
  ADD src/monitor /opt/monitor
  RUN mkdir -p /opt/monitor/.tmp &amp;&amp; \
      chown -R robuser /opt/monitor &amp;&amp; \
      chmod -R 700 /opt/monitor
  
  RUN touch /var/log/entrypoint.log &amp;&amp; \
      touch /var/log/monitor.log &amp;&amp; \
      touch /var/log/cron.log &amp;&amp; \
      touch /var/log/awslogs.log &amp;&amp; \
      chown -R robuser /var/log
  
  USER robuser
  
  ENTRYPOINT /home/robuser/entrypoint.sh
  </code></pre>
  
  <p>meanwhile, my entrypoint.sh has this somewhere in it. I start the cron daemon as a background service and log to cron.log verbosely. I've also tried specifying -d 0 to get even more debug, but the didn't really add anything to the output.</p>
  
  <pre><code>#!/bin/bash
  
  crond -b -l 0 -L /var/log/cron.log
  
  #... lots of other startup stuff ...
  </code></pre>
  
  <p>An important point: If I don't switch to <em>robuser</em>, <strong>everything works okay as root</strong>. </p>
  
  <p>If I check the <em>cron.log</em>, its pretty empty:</p>
  
  <pre><code>crond: crond (busybox 1.25.1) started, log level 0
  crond: wakeup dt=45
  crond: wakeup dt=60
  crond: wakeup dt=60
  </code></pre>
  
  <p>Meanwhile, /var/log/monitor.log is completely empty (see crontab at the beginning of the post).</p>
  
  <p>So crond is not printing any errors.</p>
  
  <p>I've tried everything i can think of to debug this. There's no error message. It simply runs and never prints. A good suggestion was to simply my crontab.. but this also did not work:</p>
  
  <pre><code>PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/aws/bin:/home/ec2-user/bin
  SHELL=/bin/bash
  
  * * * * * touch /tmp/test.txt
  </code></pre>
  
  <p>I've tried searching for other alpine containers who use non-root cron, but most people don't go through the trouble of getting their alpine containers to run non-root.</p>
  
  <p>Does anyone have any further suggestions to help debug this?</p>