Skip to contentSkip to conversation

crontab: can't change directory to '/var/spool/cron/crontabs': No such file or directory

Buildroot Alexey Brodkin 4 participants 4 messages Jan 28, 2016 – Feb 1, 2016

lore
Share & tools
lore
#0 lore raw

Hello,

Just noticed this:
------------------>8-------------------

# crontab -e
crontab: can't change directory to '/var/spool/cron/crontabs': No such file or directory
------------------>8-------------------

Obvious solution is:
------------------>8-------------------

# mkdir -p /var/spool/cron/crontabs
------------------>8-------------------

But the question is if we want that to be done automatically and if we do want how (read "where") to do it properly?

The point is crond is enabled by default in Busybox, see
https://git.busybox.net/buildroot/tree/package/busybox/busybox.config#n664
so users expect crond to just work but that doesn't happen :)

Any thoughts?

-Alexey

#1 lore raw
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Alexey" == Alexey Brodkin <[email protected]> writes:

Hello,
Just noticed this:

------------------> 8-------------------

Quoted 2 lines
# crontab -e
crontab: can't change directory to '/var/spool/cron/crontabs': No such file or directory

------------------> 8-------------------

Quoted 1 line

Obvious solution is:

------------------> 8-------------------

Quoted 1 line
# mkdir -p /var/spool/cron/crontabs

------------------> 8-------------------

Quoted 2 lines

But the question is if we want that to be done automatically and if we do want how (read "where") to do it properly?

Yes, the problem is also how should this work together with a readonly rootfs? Our default skeleton has /var/spool as a symlink to /tmp/, so we cannot add /var/spool/cron/crontabs at build time (unless we change the skeleton).

What I have done in the past is simply to do it in an init script, E.G. something like:

# /var/spool is link to /tmp => crontabs are not persistent over boot
mkdir -p /var/spool/cron/crontabs
cp /root/crontab /var/spool/cron/crontabs/root
start-stop-daemon -S -q -p /var/run/crond.pid --exec /usr/sbin/crond -- -l 9

But that isn't very generic.

Signature · 2 lines
Venlig hilsen,
Peter Korsgaard 
#2 lore raw

Dear Alexey, Peter,

Quoted 14 lines · Peter Korsgaard
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Alexey" == Alexey Brodkin <[email protected]> writes:

Hello,
Just noticed this:

------------------> 8-------------------

Quoted 2 lines
# crontab -e
crontab: can't change directory to '/var/spool/cron/crontabs': No such file or directory

------------------> 8-------------------

Quoted 1 line

Obvious solution is:

------------------> 8-------------------

Quoted 1 line
# mkdir -p /var/spool/cron/crontabs

------------------> 8-------------------

Quoted 7 lines
Quoted 2 lines

But the question is if we want that to be done automatically and if we do want how (read "where") to do it properly?

Yes, the problem is also how should this work together with a readonly rootfs? Our default skeleton has /var/spool as a symlink to /tmp/, so we cannot add /var/spool/cron/crontabs at build time (unless we change the skeleton).

Yeah, changing the skeleton looks like a clean solution at first, but it would potentially break existing configurations using /var/spool with a readonly rootfs, and quietly change the behaviour of those with a rw rootfs... Not good.

Another option, specific for crond and crontab, would be to change CONFIG_FEATURE_CROND_DIR in the Busybox config so it points to non-volatile storage. A candidate might be /var/cron, but according to hier(7):

- /var/cron: Reserved for historical reasons.
- /var/spool/cron: Spooled jobs for cron(8).

A variant on this might be:
- store crontab files in /var/cron (or wherever in the rootfs)
- add a boot script that creates a symlink

    /var/spool/cron -> /var/cron

- _not_ change the Busybox config.

Quoted 11 lines

What I have done in the past is simply to do it in an init script, E.G. something like:

# /var/spool is link to /tmp => crontabs are not persistent over boot
mkdir -p /var/spool/cron/crontabs
cp /root/crontab /var/spool/cron/crontabs/root
start-stop-daemon -S -q -p /var/run/crond.pid --exec /usr/sbin/crond -- -l 9

But that isn't very generic.

And it does not save /var/spool/cron/crontabs/root to /root/crontab after edits, which is the worst drawback IMHO.

This is a topic we may discuss during the Developer Days next week.

Signature · 1 line
Luca
#3 lore raw
In reply to Peter Korsgaard
Quoted 14 lines · Peter Korsgaard
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Alexey" == Alexey Brodkin <[email protected]> writes:

Hello,
Just noticed this:

------------------> 8-------------------

Quoted 2 lines
# crontab -e
crontab: can't change directory to '/var/spool/cron/crontabs': No such file or directory

------------------> 8-------------------

Quoted 1 line

Obvious solution is:

------------------> 8-------------------

Quoted 1 line
# mkdir -p /var/spool/cron/crontabs

------------------> 8-------------------

Quoted 7 lines
Quoted 2 lines

But the question is if we want that to be done automatically and if we do want how (read "where") to do it properly?

Yes, the problem is also how should this work together with a readonly rootfs? Our default skeleton has /var/spool as a symlink to /tmp/, so we cannot add /var/spool/cron/crontabs at build time (unless we change the skeleton).

I think it's a mistake that we have /var/spool as a symlink to /tmp. /var/spool
shouldn't contain any files directly. So instead, I think any package that needs a /var/spool directory should create it either as a directory or as a symlink. In the particular case of crontab, that should probably be a directory, not a symlink, since it doesn't make much sense to have crontab files non-persistent.

In fact, dcron does create $(TARGET_DIR)/var/spool/cron/crontabs - which is
silly of course since it will just create a directory in /tmp and the tmpfs will be mounted over it.

Of course, changing this may break other packages, probably at runtime only.
The following packages are currently referring to /var/spool from buildroot, but there are probably a few others (including busybox) that refer to it from their own Makefiles:
at boa busybox dcron dcron exim leafnode2 mutt smstools3

Regards,
Arnout

Quoted 12 lines

What I have done in the past is simply to do it in an init script, E.G. something like:

# /var/spool is link to /tmp => crontabs are not persistent over boot
mkdir -p /var/spool/cron/crontabs
cp /root/crontab /var/spool/cron/crontabs/root
start-stop-daemon -S -q -p /var/run/crond.pid --exec /usr/sbin/crond -- -l 9

But that isn't very generic.

Signature · 6 lines
Arnout Vandecappelle                          arnout at mind be
Senior Embedded Software Architect            +32-16-286500
Essensium/Mind                                http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium           BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7493 020B C7E3 8618 8DEC 222C 82EB F404 F9AC 0DDF