All of lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH 1/1] package/dcron: create directories if needed on startup
@ 2020-01-02 12:37 Christopher McCrory
  2020-01-02 13:39 ` Thomas Petazzoni
  0 siblings, 1 reply; 3+ messages in thread
From: Christopher McCrory @ 2020-01-02 12:37 UTC (permalink / raw)
  To: buildroot

Create the /var/spool/cron/crontabs and /var/spool/cron/cronstamps directories
on startup if they don't exist.  By default /var/spool is a symlink to /tmp so
the contents get deleted on reboot.  If the cronstamps directory does not exist
anything in /etc/cron.hourly/ , etc. will fail to run.

Signed-off-by: Christopher McCrory <chrismcc@gmail.com>
---
 package/dcron/S90dcron      | 105 +++++++++++++++++++++++++++++-------
 package/dcron/dcron.service |   6 +++
 2 files changed, 93 insertions(+), 18 deletions(-)

diff --git a/package/dcron/S90dcron b/package/dcron/S90dcron
index de21d2ca13..f51513d41e 100644
--- a/package/dcron/S90dcron
+++ b/package/dcron/S90dcron
@@ -1,22 +1,91 @@
 #!/bin/sh
 
+# Make sure umask is sane
+umask 022
+
+PATH="/sbin:/usr/sbin:/bin:/usr/bin"
+export PATH
+
+DAEMON_NAME="dcron"
+DAEMON_DESC="dcron"
+DAEMON_BINARY="/usr/sbin/crond"
+DAEMON_BASENAME="crond"
+DAEMON_CONFIG="/etc/cron.d/system"
+DAEMON_ARGS="-- -f"
+DAEMON_PID="/var/run/crond.pid"
+
+[ -r /etc/default/$DAEMON_BASENAME ] && . /etc/default/$DAEMON_BASENAME
+[ -x $DAEMON_BINARY ] || exit 5
+[ -r $DAEMON_CONFIG ] || exit 6
+
+start() {
+  printf "Starting $DAEMON_DESC: "
+  [ -d /var/spool/cron/crontabs   ] || mkdir -vp /var/spool/cron/crontabs
+  [ -d /var/spool/cron/cronstamps ] || mkdir -vp /var/spool/cron/cronstamps
+  start-stop-daemon -S -q -b  -m -p $DAEMON_PID  -x $DAEMON_BINARY $DAEMON_ARGS
+  sleep 2 ; status ; RETVAL=$?
+  if [ $RETVAL -ne 0 ]; then
+    echo "FAIL"
+  else
+    echo "OK"
+  fi
+  return $RETVAL
+}
+
+# -R doesn't work with busybox, but doesn't error out
+stop() {
+  printf "Stopping $DAEMON_DESC: "
+  start-stop-daemon -K -R 59 -x $DAEMON_BINARY
+  RETVAL=$?
+  if [ $RETVAL -ne 0 ]; then
+    echo "FAIL"
+  else
+    echo "OK"
+  fi
+  return $RETVAL
+}
+
+status() {
+  PIDS=`pidof $DAEMON_BASENAME`
+  RETVAL=$?
+  if [ $RETVAL -eq 0 ]; then
+    echo "RUNNING (pid $PIDS)"
+  else
+    echo "NOT OK"
+  fi
+  return $RETVAL
+}
+
 case "$1" in
-	start)
-		printf "Starting cron ... "
-		start-stop-daemon -S -q -m -b -p /var/run/dcron.pid --exec /usr/sbin/crond -- -f
-		echo "done."
-		;;
-	stop)
-		printf "Stopping cron ..."
-		start-stop-daemon -K -q -p /var/run/dcron.pid
-		echo "done."
-		;;
-	restart)
-		$0 stop
-		sleep 1
-		$0 start
-		;;
-	*)
-		echo "usage: $0 {start|stop|restart}"
-		;;
+  start)
+    start
+    ;;
+  stop)
+    stop
+    ;;
+  restart)
+    echo "Restarting $DAEMON_DESC: "
+    stop
+    sleep 1
+    start
+    echo ""
+    ;;
+  try-restart)
+    status
+    if [ $RETVAL -eq 0 ]; then
+      stop
+      sleep 1
+      start
+    fi
+    ;;
+  status)
+    printf "Status of $DAEMON_DESC: "
+    status
+    ;;
+  *)
+    echo "Usage: $0 {start|stop|restart|status|try-restart}" >&2
+    exit 3
+    ;;
 esac
+
+exit 0
diff --git a/package/dcron/dcron.service b/package/dcron/dcron.service
index 924ed72205..19c66b1535 100644
--- a/package/dcron/dcron.service
+++ b/package/dcron/dcron.service
@@ -3,6 +3,12 @@ Description=Task scheduler daemon
 After=syslog.target
 
 [Service]
+# make sure directories exist. use -v so it gets logged
+ExecStartPre=/bin/sh -c '\
+test -d /var/spool/cron/crontabs   || mkdir -pv /var/spool/cron/crontabs  ; \
+test -d /var/spool/cron/cronstamps || mkdir -pv /var/spool/cron/cronstamps; \
+'
+
 ExecStart=/usr/sbin/crond -S
 Type=forking
 
-- 
2.18.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [Buildroot] [PATCH 1/1] package/dcron: create directories if needed on startup
  2020-01-02 12:37 [Buildroot] [PATCH 1/1] package/dcron: create directories if needed on startup Christopher McCrory
@ 2020-01-02 13:39 ` Thomas Petazzoni
  2020-01-02 14:24   ` Christopher McCrory
  0 siblings, 1 reply; 3+ messages in thread
From: Thomas Petazzoni @ 2020-01-02 13:39 UTC (permalink / raw)
  To: buildroot

Hello Christopher,

On Thu,  2 Jan 2020 12:37:46 +0000
Christopher McCrory <chrismcc@gmail.com> wrote:

> Create the /var/spool/cron/crontabs and /var/spool/cron/cronstamps directories
> on startup if they don't exist.  By default /var/spool is a symlink to /tmp so
> the contents get deleted on reboot.  If the cronstamps directory does not exist
> anything in /etc/cron.hourly/ , etc. will fail to run.
> 
> Signed-off-by: Christopher McCrory <chrismcc@gmail.com>

We already have http://patchwork.ozlabs.org/patch/1196301/ pending to
fix the same issue. Could you instead have a look at Carlos patch and
see if it fixes the problem for you as well ?

Best regards,

Thomas
-- 
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Buildroot] [PATCH 1/1] package/dcron: create directories if needed on startup
  2020-01-02 13:39 ` Thomas Petazzoni
@ 2020-01-02 14:24   ` Christopher McCrory
  0 siblings, 0 replies; 3+ messages in thread
From: Christopher McCrory @ 2020-01-02 14:24 UTC (permalink / raw)
  To: buildroot

On Thu, Jan 2, 2020 at 5:39 AM Thomas Petazzoni <
thomas.petazzoni@bootlin.com> wrote:

> Hello Christopher,
>
> On Thu,  2 Jan 2020 12:37:46 +0000
> Christopher McCrory <chrismcc@gmail.com> wrote:
>
> > Create the /var/spool/cron/crontabs and /var/spool/cron/cronstamps
> directories
> > on startup if they don't exist.  By default /var/spool is a symlink to
> /tmp so
> > the contents get deleted on reboot.  If the cronstamps directory does
> not exist
> > anything in /etc/cron.hourly/ , etc. will fail to run.
> >
> > Signed-off-by: Christopher McCrory <chrismcc@gmail.com>
>
> We already have http://patchwork.ozlabs.org/patch/1196301/ pending to
> fix the same issue. Could you instead have a look at Carlos patch and
> see if it fixes the problem for you as well ?
>
>
It looks like it would work. Its a superset of what I did.  The same basic
changes are made to the two init bits for creating the directories. The
source code patch addresses the bigger picture. The directory creating bits
from the earlier patch or my patch should fix the immediate bug. Changing
the way dcrond starts up can be thought of as a different issue.



Best regards,
>
> Thomas
> --
> Thomas Petazzoni, CTO, Bootlin
> Embedded Linux and Kernel engineering
> https://bootlin.com
>


-- 
Christopher McCrory
To the optimist, the glass is half full.
To the pessimist, the glass is half empty.
To the engineer, the glass is twice as big as it needs to be.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.busybox.net/pipermail/buildroot/attachments/20200102/ae0423f2/attachment.html>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-01-02 14:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-02 12:37 [Buildroot] [PATCH 1/1] package/dcron: create directories if needed on startup Christopher McCrory
2020-01-02 13:39 ` Thomas Petazzoni
2020-01-02 14:24   ` Christopher McCrory

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.