Typo
[linux_from_scratch_hints.git] / OLD / fcrond-hint.txt
blob65b5b1a5ab0b8a9cea6cb1463ef9ae45f1b3e702
1 TITLE:          Fcron Scheduling Daemon
2 LFS VERSION:    4.0 (or older versions, with minor changes)
3 AUTHOR:         Lyle Vogtmann <vogtmann@pioneernet.net>
4 MAINTAINER:     Robert Park <rbpark@ualberta.ca>
6 SYNOPSIS:
7         How to set up the fcron scheduling daemon on an LFS system.
9 HINT:
11 Changelog
12 ---------
14 Revision 1.8  2003/01/22 07:55:04  feztaa
15 Updated cronmail script to version 1.6
17 Revision 1.7  2002/12/24 08:30:05  feztaa
18 Updated to fcron 2.9.3.
20 Revision 1.6  2002/09/15 05:38:52  feztaa
21 Changed email address, among other misc fixes.
23 Revision 1.5  2002/06/09 04:14:05  feztaa
24 Added some notes, changed style of code blocks, and fixed a couple typos.
26 Revision 1.4  2002/05/02 00:05:36  feztaa
27 Fixed a problem with the cronmail script improperly delivering mail,
28 clarified some abiguities, and reduced some redundancy in the fcrontabs.
30 Revision 1.3  2002/04/27 19:28:08  feztaa
31 Fixed various typos and other grammatical errors (oops ;)
33 Revision 1.2  2002/04/27 19:17:48  feztaa
34 I've taken over maintenance of this hint from Lyle.
35 Added 'cronmail' script, updated bootscripts to LFS 3.3,
36 and reformatted the layout of the hint.
38 Intro
39 -----
41 I wrote this to help others set up and use the Vixie Cron replacement known as
42 fcron. Cron is a very useful and nearly ever-present system daemon on
43 Unix-like systems.  It is started at boot time and runs in the background,
44 starting sheduled tasks specified in a "crontab". There are several versions of
45 cron available, each with it's own additions and features. Fcron has a mixture
46 of some of the best features.
48 Fcron can function as a standard cron, running tasks at a certain time on a
49 certain day. It can also function like anacron, running tasks after a certain
50 amount of time at an unspecific time (if you don't leave your computer on all
51 the time, this is a godsend). It can also run tasks after a certain amount of
52 uptime, too.
54 For more information, check out the fcron home page at http://fcron.free.fr.
56 Notes
57 -----
59 In an attempt to make this easier to read, all "code blocks" that you should
60 execute on the commandline start and end with "##--CODE--##". Feel free to copy
61 that onto the commandline along with the code itself, it won't hurt anything.
62 Also, for quoted text (the output of a program, for example), each line is
63 prefixed with four spaces.
65 Requirements
66 ------------
68 If you want to see the output of the commands that Fcron runs, you will want to
69 have a working mail system installed. If you are not interested in installing a
70 mail system on your box, I have written a "cronmail" script that you can use to
71 let fcron deliver mail to you without a full MTA on the system. You will need
72 to install the procmail package, though, because my cronmail script uses
73 formail (which comes with procmail).
75 This hint does not cover setting up a local mail service, but I'll show you how
76 to install cronmail. If you want to set up a local mail service, check out the
77 LDP at http://www.linuxdoc.org. I reccommend Postfix, http://www.postfix.org.
79 Instructions
80 ------------
82 1. Get fcron sources from http://fcron.free.fr and unpack them. I use fcron
83 2.9.3, but this hint should work for other versions as well.
85 2. Add the "fcron" user and group to your system:
87 ##--CODE--##
88 groupadd -g 13 fcron
89 useradd -u 13 -g fcron -d /dev/null -s /bin/false fcron
90 ##--CODE--##
92 This creates the group fcron with GID 13 and the user fcron with UID 13. It
93 also prevents anybody from logging into this account, because the home
94 directory is /dev/null and and the shell is /bin/false.
96 3. Run configure:
98 ##--CODE--##
99 ./configure --prefix=/usr --with-spooldir=/var/lib/fcron
100 ##--CODE--##
102 This tells fcron to put it's fcrontab files into /var/lib/fcron.  I personally
103 use /var/fcron, but if you want to be FHS-compliant, you have to use
104 /var/lib/fcron.
106 4. You might want to have a glance at config.h to make any changes to the build
107 process, but in my experience this is unneccessary. If you do edit this file,
108 be sure to check the locations of key files like fcron.allow, fcron.deny, etc.
109 You can also configure what Fcron calls itself when it mails you, if you like.
111 5. Compile:
113 ##--CODE--##
114 make && su -c "make install"
115 ##--CODE--##
117 This will compile the sources, then install them as root. When it asks you to
118 install the init script, don't. We are going to make our own, better init
119 script later on.
121 7. If you are upgrading, be sure to run this command for each user on your
122 system that had an fcrontab during installation:
124 ##--CODE--##
125 fcrontab -u <user> -z
126 ##--CODE--##
128 This simply updates the fcrontab, in case the format has changed.
130 8. Now we will create the bootscripts. Run this as root:
132 ##--CODE--##
133 cat >/etc/rc.d/init.d/fcron <<"EOF"
134 #!/bin/bash
135 # Begin $rc_base/init.d/fcron
137 source /etc/sysconfig/rc
138 source $rc_functions
140 case "$1" in
141   start)
142     echo "Starting fcron..."
143     loadproc /usr/sbin/fcron
144     ;;
146   stop)
147     echo "Stopping fcron..."
148     killproc fcron
149     ;;
151   restart)
152     $0 stop
153     sleep 1
154     $0 start
155     ;;
157   status)
158     statusproc fcron
159     ;;
161   *)
162     echo "Usage: $0 {start|stop|restart|status}"
163     exit 1
164     ;;
165 esac
167 # End $rc_base/init.d/fcron
169 chmod 755 /etc/rc.d/init.d/fcron
170 ##--CODE--##
172 You will also need to make the symlinks in the appropriate directories. I did
173 mine like this, but you might want to do it differently:
175 ##--CODE--##
176 cd /etc/rc.d/rc0.d &&
177 ln -s ../init.d/fcron K35fcron &&
178 cd /etc/rc.d/rc6.d &&
179 ln -s ../init.d/fcron K35fcron &&
180 cd /etc/rc.d/rc3.d &&
181 ln -s ../init.d/fcron S60fcron
182 ##--CODE--##
184 9. You need to give it some tasks to do (it wouldn't be very useful
185 otherwise! ;). Read the man page for fcrontab:
187 ##--CODE--##
188 man 5 fcrontab
189 ##--CODE--##
191 If you need some examples to get started, this is what I have in root's
192 fcrontab: (this is the output of 'fcrontab -l')
194     !mailto(feztaa),mail(yes),forcemail(yes),noticenotrun(yes)
195     %daily * 9-15 updatedb --prunepaths="/mnt /proc /dev"
196     %daily * 9-15 logreport
198 This fcrontab is fairly straightforward. First, we set some options: send mail
199 to feztaa (me), always send mail no matter what, and let me know if the command
200 was not run. Then, we run updatedb every day between 9 AM and 3 PM. Finally, we
201 run logreport at the same time that updatedb is run (logreport is just a quick
202 bash script I wrote to scan my logs and notify me of root logins).
204 In my own fcrontab, I have the following:
206     !mailto(feztaa),mail(yes),forcemail(yes),noticenotrun(yes)
207     %monthly * * 1-4 oldmail
209 This sets the same options as root's fcrontab, and then it runs oldmail as soon
210 as it can, some time during the first four days of every month (oldmail is
211 another simple script I wrote that simply archives and compresses my old mail).
213 What I've written here is by far no substitute for reading the man page; I've
214 barely scratched the surface in this hint. If you want to get the most out of
215 your fcron, do yourself a favour and read the man page.
217 To install your fcrontab, run:
219 ##--CODE--##
220 fcrontab -u <user> -e
221 ##--CODE--##
223 The -u option can be omitted if the fcrontab you want to edit belongs to the
224 same user who runs the command. The default editor (defined in /etc/fcron.conf)
225 should start with a blank screen. Type in your entries in accordance with the
226 fcrontab(5) man page.
228 When you're done, save and quit editing the file (:wq in vim). Fcrontab then
229 checks your work for errors, and it complains if it finds some. It will also
230 refuse to use the malformed fcrontab. If you get an error, try again, and read
231 the man page to see what you're doing wrong. When you get it right, fcrontab
232 passes the file to fcron and saves it in /var/lib/fcron/<username>. DO NOT EDIT
233 THIS FILE! Always use fcrontab to edit your fcrontab, it is much safer that
234 way.
236 10. Now, to control who has access to fcron, you edit /etc/fcron.allow and
237 fcron.deny. I think that only root and a select few priveleged users should be
238 able to use such a daemon, so I put "all" in fcron.deny and "root" and "feztaa"
239 in fron.allow.
241 11. We will now install the cronmail script that I talked about in the
242 introduction. If you do not want this script, you are now done! If you do want
243 it, read on...
245 First, run this as root:
247 ##--CODE--##
248 cat >/usr/bin/cronmail <<"EOF"
249 #!/bin/bash
250 # $Id: fcrond-hint.txt,v 1.1 2003/09/13 16:18:12 tushar Exp $
251 # Author: Rob Park <rbpark@ualberta.ca>
252 # License: GNU General Public License
254 ########################################################################
255 # You probably want to edit the following two variable definitions to  #
256 #            better match your system! You have been warned!!          #
257 ########################################################################
259 # What is the default name to use if none is specified, or if root is
260 # specified? Basically, who gets root's mail?
261 default="feztaa"
263 # Where should the mail be delivered to? This is an mbox somewhere
264 # inside the user's home directory (sorry, only mbox format is supported
265 # as of now).
266 mbox="mail/cron"
268 ###########################################################
269 # You shouldn't need to edit anything below this line! ;) #
270 ###########################################################
272 # Throw away all the arguments until we find one that's a valid username
273 until id "$1" >/dev/null 2>&1
275   shift
276 done
278 # The username is now the first argument
279 name="$1"
281 # If the first argument is missing, or "root", deliver it to the default
282 # user instead.
283 [ "$name" == "" ] && name=$default
284 [ "$name" == "root" ] && name=$default
286 # Pipe stdin to the mbox in the user's home folder, adding a few headers
287 # to make it look more like real mail.
288 formail -a "Message-ID:" -I "From: Cron <fcron@$HOSTNAME>" -I "To: $name <$name@$HOSTNAME>" >> /home/$name/$mbox
290 chmod 755 /usr/bin/cronmail
291 ##--CODE--##
293 This script is a very simple sendmail replacement. It looks for a username in
294 the argument list, stamps some email headers onto the message with formail, and
295 then sends it off to an mbox in the user's home directory.  You can edit where
296 exactly you want it to be delivered, and who you want to get root's mail. Since
297 I get all my mail in ~/mail, I have the script deliver my mail to ~/mail/cron.
299 The next thing we need to do is tell fcron to use our cronmail script.  Run
300 this command to make the change:
302 ##--CODE--##
303 cd /etc &&
304 perl -i -pe 's%^sendmail\s*=.*$%sendmail=/usr/bin/cronmail%' fcron.conf
305 ##--CODE--##
307 Now restart fcron (if it is running), and you're all ready to go!
309 The End
310 -------
312 You're done! Now you have a scheduling utility that will run commands
313 automatically for you.
315 If you have any questions, suggestions, or problems, PLEASE email me and I will
316 help you to the best of my ability (note, don't email Lyle, he doesn't maintain
317 this anymore. Just email me, Rob).