330 points · by otoolep · 10y ago · 126 comments
Those are all database functions. In UNIX/Linux, each configuration file has its own mechanism for all that. They're all inferior to SQLite.
Most of the things living under /etc are not databases. crontab certainly isn't:
- Only a single "table" (no table-relations)
- No standard database type exists for columns (how would you model the scheduling as database types, how would you model the shell command as database types, if not simply as sanitized strings)
So you can't get integrity for free. Need a custom parser and some integrity checks. Not so difficult (yes, cron will give instant feedback for the unlikely case that you did something wrong)
Re: editor, locking, access control:
I have an editor and prefer it to writing SQL DML any day.
File updates (rename(2)) are atomic, so no need for additional locking. And even if there is some broken tool writing to the old file instead of rename, the chances of that being simultaneous with a parse are microscopic. Don't overdesign. (there are many more things that can go wrong in a system that you can't possibly design out. Live with it).
Access control: Standard file permission modes are just fine. More complex permission model would be a serious overdesign. You can get granularity by using separate crontabs.
Checker: Never needed an additional tool to format the meaning as human-readable text. The syntax is a bit ugly but quite easy to remember and use.
Someone edits a cron file in the most common editor, vim. On many systems it doesn't do an atomic swap on save without extra configuration: http://stackoverflow.com/questions/13563627/how-does-vim-sav...
Now maybe your unresponsive, undergoing swap, system misses a cron job that was present in both edits. Opps.
I'm not sure this could really play out, but the approach definitely sounds firmly on the "worse is better" side of the scale.
Otherwise adding a file or deleting a file in /etc/cron.d/ is the way to go for automatic(ansbile, puppet etc) and package installations.
Nobody argues that there can't be problems. What all critics miss is to show how to avoid these problems.
What can you do about jobs that make the system unresponsive? Not a problem for cron to solve.
If someone writes a crontab (instead of rename()ing another version over it), that's not cron's fault. Sqlite databases can be just as easily corrupted or lose integrity. Now which format would you rather repair?
Missing a cron job can not be totally avoided, and it isn't the end of the world. What if your machine goes down or cron crashes? The answer is that the jobs themselves have to be provided with some resilience against that situation.
This isn't a case of "worse is better" since there weren't proposed solutions to the "problems" at all, however unrealistic.
Editor: of course you need some way to input data, and an editor is the simplest interface. You need to generate SQL to store data in SQLite and that's certainly not simpler.
Locking system: the OS/filesystem can provide this just as well as a database can.
Access control: same answer
Checker: input needs to be validated for its intended task and SQLite won't magically make this requirement disappear.
Or did we not read the manual, then complain about broken stuff and follow that with an over-enginered "solution" to a problem that didn't exist.
The syntax of cron isn't the most intuitive but it's powerful and would make even less sense in a database.
Also the tools argument just isn't true. A well designed plain text format is easier to parse with a one-off parser than with ugly one-off SQL queries. The reason that not many GUIs exist for plain text formats is that they are already designed to be easy to use. There are few cases where GUIs make sense.
From the top of my head, the only configuration GUI I regularly use is firefox's. Not that it wouldn't be possible to come up with a clean plain text design that would be easier to use.
Also most of the stuff is not represantable as relations. I'm looking forward to see how you encode a shell command in relations.
I don't think a database would offer anything unless it was managing 1000's of cron servers. Flat text is fine and easier to parse than querying a database and adding a dependency. A database is a huge requirement to ask for to manage a few simple files.
It's not like crontabs are written all the time. They don't need to be so terse. They shouldn't require learning a language... they shouldn't require a cron.guru website. Systemd timer syntax (https://wiki.archlinux.org/index.php/Systemd/Timers#Example) is far more readable, and there's still a lot of room for improvement.
Unix programmers aren't in the habit of throwing out a working system because it's hard to grok, nor building something more complex then it needs to be. I took a look at your systemd timers link and it is a more complex syntax to create the same effect. From their own caveats section:
> Complexity: to set up a timed job with systemd you create two files and run a couple systemctl commands. Compare that to adding a single line to a crontab.
I've spent the past years doing that. I do understand cron. I also strongly dislike it. You could build a thriving city within the bounds of the room there is for improvement.
> It even handles that crazy case where you want to run on a specific day of the week.
So does systemd's cron. Supporting "crazy cases" doesn't mean the syntax has to suck.
> Cron lines may seem arcane at first, but then again have you ever tried to write code that was timezone aware?
Yes...
Re systemd: It's one example; it's not perfect, I wouldn't even call it good, but it's leagues ahead of cron in terms of UX already. Bonus: usage of the ini format means it's programmatically much easier to interact with the cronjob itself.
Why is having the format be so concise and terse a virtue?
They could keep the flat file approach and everything about the system identical but just make it more explicit. Cron usage would become much simpler.
Does it handle the, in my opinion, not crazy case of running something every, say, 100 seconds?
Cron ticks every minute and checks to see if any crontab entries match the current time, if so it runs the job. But standard regular expressions aren't well suited to the types of patterns people normally try to express which is why they use their own syntax.
Cron could be considered as a good mix between complexity and brevity (readability).
Shameless plug: I tried to create a format in-between both in a JS project [1]. It is based on the ISO 8601 duration format [2], but it's better to stick to iCalendar.
[0] https://tools.ietf.org/html/rfc2445#section-4.3.10
http://pubs.opengroup.org/onlinepubs/7908799/xcu/crontab.htm...
In a sense, crontabs are the lowest common denominator for scheduling tasks on POSIX-compliant systems.
Killing off old designs is exceptionally difficult for Unix. Hell, Microsoft can barely force an upgrade on everyone and they don't have a hundred forked distros.
The configuration system absolutely demands the locking system (to alter it) and the checker (to correctly check if it is correct before the changes are ever committed). SQLite can provide some of them, but not all---most importantly, SQLite's locking system is independent of the runtime configuration which requires separate locking system (however rudimentary).
In UNIX, everything is a file
Do you see a pattern?
Just because Windows' registry is hard to manually edit doesn't mean they are a bad idea. Look at how much better Windows' GUI configuration tools are than anything on Linux. They all use the registry.
An associated problem is that the registry accretes trash that is never weeded out (and it's hard to weed it out).
Also at least in former times it was slow (partly because of the trash thing, probably partly because of the implementation, partly because of the centralised design).
That's not the problem with Windows registry.
Which itself has all sorts of complications around locking. Can't write when another process has read-only lock, for example:
Makes sense.
Have you tried any of these answers?
http://stackoverflow.com/questions/2135478/how-to-simulate-t...
env - HOME=$HOME LOGNAME=$LOGNAME sh -c 'command line'
Home, shell and logname are the only 3 variables guaranteed to be set.You could simply find something else to do for a minute, like rechecking that the other pieces of the system are setup correctly as well.
cronwtf:
0 0 1 1 0 COMMAND Runs `COMMAND` at minute :00, on hour 0, on day 1, in Feb, on Sun.<-- NO!
crontab:
0 0 1 1 0 At 00:00 on the 1st and every Sun in Jan. <-- CORRECT
5 4 W * *
Really gave Chrome some grief.> Really gave Chrome some grief.
You are evil.
It also gave Firefox a lot of grief. CPU usage shot to 100%.
[0] http://crontab-generator.org/
http://www.openjs.com/scripts/jslibrary/demos/crontab.php
http://htmlminifiers.com/cron-maker.php
http://cron.nmonitoring.com/cron-generator.html
0/5 * * * *
as it does for */5 * * * *If any of y'all are looking for a more modern cron replacement for running periodic tasks with a nice web uis here are a few other options:
* Rundeck http://rundeck.org/ * Stackstorm https://docs.stackstorm.com * ndscheduler https://github.com/Nextdoor/ndscheduler
All other fields are AND together, these two are OR
Also, lots of operators have decades of experience with cron, and don't want to give up on that easily.
[Update] After reading https://wiki.archlinux.org/index.php/Systemd/Timers I see two more reasons
* You don't have to write a service file to use cron jobs, which makes ad-hoc tasks much easier
* Sending mails is the default for cron, which requires extra work with systemd.
But, to be honest, writing crontab is easier task, systemd timers are not more intuitive than cron when you write them, i.e. I personally still look in documentation for various systemd options, but are IMHO much easier to read and more powerful, and have great "systemctl list-timers" view, but unfortunately not superset of crontab options. That's probably the second reason to still use crontab.
I like /etc/crontab. It is a simple text file. Nothing magic. Standard. Works every time. Well known by everybody. Works on a lot of UNIXes, old Linux systems etc.
I don't want no new complexity and a new way to do things every 6 months. What I hate most is that all this is pushed through our throats no matter what we want. FFS.
EDIT: BTW, I think luckily, /etc/crontab at least currently still works on Ubuntu Server 16.04 (what I've tried). I think this is the way to go. If you want to use some new features (systemd) you can opt-in. But don't break old stuff please.
Here's what I'd call a simple init.d-like example. non-needed things (if you think it's too complex) include: wait for fs mount and network, custom reload command, "don't log stdout"
[Unit]
After=network.target
AssertPathIsMountPoint=/mnt/service-data-if-needed
[Service]
ExecStart=/some/binary
Environment=CONF=/etc/i/guess.conf USER=nonrootmaybe
ExecReload=/bin/pkill binary
KillMode=process
Restart=always
StandardOutput=null
[Install]
WantedBy=multi-user.target
EDIT: man 5 systemd.unitThat only guarantees that your network devices have been enumerated, not that they are available with assigned addresses.
I encountered this problem with SSH failing to start on Ubuntu 16.04 server. systemd was launching SSH before the binding address had been assigned, causing SSH to abort and fail and the server to continue to boot without any way of accessing it remotely.
Workaround ( at the physical console ) was to add a Retry to the SSH unit and time it to coincide with the address having been assigned[0]. hacky, but no other unit imperatives worked.
[0] Default behaviour in the SSH unit, at least on Ubuntu, is that it tries once and never again.