acc1d9414d588639af62360bdaf2d0dc32a1dab8
[whenjobs.git] / tools / whenjobs.pod
1 =encoding utf8
2
3 =head1 NAME
4
5 whenjobs - A powerful but simple cron replacement
6
7 =head1 SYNOPSIS
8
9 Editing the jobs script:
10
11  whenjobs -e | --edit
12  whenjobs -l | --list
13
14 Get and set variables:
15
16  whenjobs --get variable
17  whenjobs --set variable=value [variable=value ...]
18  whenjobs --variables
19
20 Start and stop the per-user daemon:
21
22  whenjobs --daemon-start
23  whenjobs --daemon-stop
24  whenjobs --daemon-status
25  whenjobs --daemon-restart
26
27 Examine running jobs:
28
29  whenjobs --jobs
30  whenjobs --cancel serial
31  whenjobs --start "name"
32  whenjobs --tail serial
33
34 =head1 DESCRIPTION
35
36 Whenjobs is a powerful but simple replacement for cron.  It lets you
37 run jobs periodically like cron, but it also lets you trigger jobs to
38 run when user-defined variables are set or change value.
39
40 Periodic jobs are written like this:
41
42  every 10 minutes :
43  <<
44    # Get the current load average.
45    load=`awk '{print $1}' /proc/loadavg`
46    whenjobs --set --type float load=$load
47  >>
48
49 When-statements let you create jobs that run based on variables set
50 elsewhere:
51
52  when load >= 6 :
53  <<
54    mail -s "ALERT: high load average: $load" $LOGNAME < /dev/null
55  >>
56
57 (When statements are "edge-triggered", meaning that this job will only
58 run when the load goes from under 6 to E<ge> 6).
59
60 Like L<crontab(5)>, whenjobs are controlled by a jobs file which can
61 be edited from the command line:
62
63  $ whenjobs -e
64
65 Whenjobs uses a daemon called L<whenjobsd(8)>.  Unlike crond, this
66 daemon runs as the same user.  Each user who wants to use whenjobs
67 starts their own daemon:
68
69  $ whenjobs --daemon-start
70
71 You can also have the daemon start as you when the machine boots by
72 adding the following line to a boot file such as C</etc/rc.local>.
73 Replace C<username> with your username:
74
75  su username -c /usr/sbin/whenjobsd
76
77 Variables are the key to expressing dependencies between whenjobs.
78 Variables are stored (per-user) in the daemon.  You can use the
79 command line tool to examine and set variables:
80
81  $ whenjobs --variables
82  JOBSERIAL=297
83  libguestfs_build_local=1.17.16
84  libguestfs_commit=7e32d892d76a31f55e2a4151902623b9949e3efa
85  libguestfs_dist=1.17.16
86  libguestfs_release=1.17.16
87  libguestfs_stable_build_local=1.16.10
88  libguestfs_stable_commit=27433a0a335301441b1eb6244ba425c2c44b2d99
89  libguestfs_stable_dist=1.16.10
90  libguestfs_stable_release=1.16.10
91  libguestfs_stable_version=1.16.10
92  libguestfs_version=1.17.16
93  $ whenjobs --set cat=sushi
94  $ whenjobs --get cat
95  sushi
96
97 Note: The act of setting a variable (using I<--set>) can trigger jobs
98 to run.
99
100 You can also list out what jobs are running:
101
102  $ whenjobs --jobs
103  287 libguestfs-stable: fedora 16
104     running in: /tmp/whenjobsa2afc44fd757465f95438309f1a51609
105     started at: 2012-03-13 10:59:37
106
107 and you can 'tail' the output of running jobs which is useful for
108 debugging:
109
110  $ whenjobs --tail 287
111  Uploading: 147496271972717053d46b82a07435ca  libguestfs-1.16.10.tar.gz
112
113 You can start and cancel jobs manually:
114
115  $ whenjobs --start 'libguestfs: poll'
116  $ whenjobs --cancel 287
117
118 =head1 OPTIONS
119
120 =over 4
121
122 =item B<--cancel> serial
123
124 Cancel the job with the given serial number.
125
126 Use I<--jobs> to list running jobs along with their serial numbers.
127 The serial number is also available in the job script (as
128 C<$JOBSERIAL>) and in the log file.
129
130 =item B<--daemon-start>
131
132 =item B<--daemon-stop>
133
134 Start and stop the per-user daemon.
135
136 =item B<--daemon-status>
137
138 Prints the status of the daemon: C<up> or C<down>.
139
140 =item B<--daemon-restart>
141
142 Restart the daemon.  (If it is not running, then this command
143 starts it).
144
145 =item B<-e>
146
147 =item B<--edit>
148
149 Edit the jobs script.  If you make changes to the jobs script, then it
150 is automatically uploaded to the daemon.
151
152 The C<$EDITOR> environment variable is used for editing.  If not set,
153 C<vi> is used.
154
155 =item B<--get> variable
156
157 Print the value of a variable.
158
159 =item B<-help>
160
161 =item B<--help>
162
163 Display brief usage and exit.
164
165 =item B<--job-names>
166
167 List the names of all loaded jobs (whether they are running or not).
168 Use I<--jobs> to list running jobs.
169
170 =item B<--jobs>
171
172 List all running jobs.
173
174 Note that it is possible for the same job to be running more than once
175 (for example, a periodic job that takes longer than the period to run).
176
177 =item B<-l>
178
179 =item B<--list>
180
181 List the jobs script.
182
183 =item B<--lib> directory
184
185 Set the library directory which needs to contain the auxiliary files
186 C<pa_when.cmo> and C<whenlib.cma>.  Normally you do not need to
187 specify this.  However if you are running whenjobs without installing
188 it, then you need to point this to the C<lib/> directory from the
189 source, eg:
190
191  whenjobs --lib $builddir/lib -e
192
193 =item B<--set> variable=value [variable=value ...]
194
195 =item B<--type> bool|int|float|string|unit
196
197 I<--set> sets the variable named C<variable> to the new C<value>.  The
198 variable is created if it does not already exist.  Note that setting a
199 variable can cause jobs to run immediately.
200
201 To unset a variable, set it to the empty string like this:
202
203  whenjobs --set var=
204
205 By default variables are strings.  You can also set the type of a
206 variable when setting it by adding the optional I<--type> parameter.
207 The I<--type> parameter should come I<before> the variable
208 declaration, like this:
209
210  whenjobs --set --type int free_space=10000
211
212 See the discussion of variable types in the L</REFERENCE> section
213 below.
214
215 You can set multiple variables.  When setting multiple variables in a
216 single command, the values are all changed in a single atomic
217 operation.
218
219  whenjobs --set cat=sushi food=fish
220
221 When using I<--type> and multiple variables, the type changes the
222 remaining command line parameters until the next I<--type>, eg:
223
224  whenjobs --set cat=sushi \
225      --type float weight=3.5 \
226      --type string food=fish
227
228 (C<cat> and C<food> are strings, and C<weight> is a float).
229
230 =item B<--start> "job name"
231
232 Start the job immediately and unconditionally.
233
234 This runs the job even if its normal preconditions are not met.  This
235 may cause unexpected results, so use with caution.
236
237 =item B<--tail> serial
238
239 Tail the output of the running job identified by its serial number.
240 Use the I<--jobs> flag to get a list of running jobs.
241
242 =item B<--test> variable=value [variable=value ...]
243
244 This works the same way as the I<--set> option, but the difference is
245 that the variables are not set.  Instead, it lists out the jobs that
246 I<would> run, I<if> the variables were updated to these new values.
247
248 The variables are not actually updated, and the jobs are not actually
249 run.
250
251 The output is a list of job names that would run.
252
253 =item B<--upload>
254
255 Compile the jobs file(s) and upload it to the daemon, without editing.
256 Note that the I<--edit> option does this automatically.  Furthermore,
257 when the daemon is started it checks for a jobs script and loads it if
258 found.
259
260 See also L</MULTIPLE JOBS FILES> below.
261
262 =item B<--variables>
263
264 Display all the variables and their values, in the format C<name=value>.
265
266 =item B<-V>
267
268 =item B<--version>
269
270 Display the name and version of the program and exit.
271
272 =item B<--whisper> variable=value [variable=value ...]
273
274 This works the same way as the I<--set> option, but with the
275 difference that jobs' when clauses are not reevaluated.  In other
276 words, the variables are set, but "quietly" so as not to trigger any
277 jobs to run.
278
279 Note that this can lead to some unexpected results: one case is a
280 when job such as:
281
282  when changed a || changed b : << ... >>
283
284 If C<a> is changed using I<--whisper>, then the job will not run.
285
286 But later on, if C<b> is set but to the same value that it already has
287 (ie. not changed), the job will run because the whole when-clause is
288 reevaluated and C<a> is found to have changed since the last run of
289 the job.
290
291 =back
292
293 =head1 REFERENCE
294
295 A whenjobs file consists of a series of one or more "every" or "when"
296 statements.
297
298 Comments in the file can be written using C<(* ... *)>.  Comments
299 may be nested.
300
301 Shell script fragments are written using C<E<lt>E<lt> ... E<gt>E<gt>>.
302 Within shell script fragments, use C<#> for comments (as in ordinary
303 shell scripts).  Because C<E<gt>E<gt>> has a special meaning, it
304 cannot be used in the shell script (ie. for redirection).  You have to
305 write C<E<gt>\E<gt>> instead which is replaced with C<E<gt>E<gt>> when
306 the shell script is parsed.
307
308 =head2 EVERY STATEMENTS (PERIODIC JOBS)
309
310 An every statement has the form:
311
312  every <period> :
313  <<
314    # shell script
315  >>
316
317 where C<E<lt>periodE<gt>> is a I<period expression>, which may take
318 one of the forms below.  Don't forget the colon character between the
319 period expression and the shell script.
320
321 An every statement is a job which runs periodically.
322
323 =head3 PERIOD EXPRESSIONS
324
325 =over 4
326
327 =item B<every second>
328
329 The job runs every second.
330
331 =item B<every minute>
332
333 The job runs every minute.
334
335 =item B<every hour>
336
337 The job runs every hour.
338
339 =item B<every day>
340
341 The job runs every day, at midnight UTC.
342
343 =item B<every week>
344
345 The job runs every week, on a Thursday at midnight UTC.
346
347 =item B<every month>
348
349 The job runs every month, on the first of the month at midnight UTC.
350
351 =item B<every year>
352
353 The job runs every year, on the first day of the year at midnight UTC.
354
355 =item B<every decade>
356
357 =item B<every century>
358
359 =item B<every millenium>
360
361 The job runs every 10, 100 or 1000 years.
362
363 =item B<every I<N> seconds>
364
365 The job runs every I<N> seconds (I<N> is any number E<ge> 1).
366
367 =item B<every I<N> minutes>
368
369 The job runs every I<N> minutes.
370
371 =item B<every I<N> hours>
372
373 The job runs every I<N> hours.
374
375 =item B<every I<N> days>
376
377 The job runs every I<N> days.
378
379 =item B<every I<N> weeks>
380
381 The job runs every I<N> weeks.
382
383 =item B<every I<N> months>
384
385 The job runs every I<N> months.
386
387 =item B<every I<N> years>
388
389 =item B<every I<N> decades>
390
391 =item B<every I<N> centuries>
392
393 =item B<every I<N> millenia>
394
395 The job runs every I<N>, I<10*N>, I<100*N> or I<1000*N> years.
396
397 =back
398
399 =head2 WHEN STATEMENTS (DEPENDENT JOBS)
400
401 A when statement has the form:
402
403  when <expr> :
404  <<
405    # shell script
406  >>
407
408 where C<E<lt>exprE<gt>> is a I<when expression>, described below.
409 Don't forget the colon character between the period expression and the
410 shell script.
411
412 A when statement is a job which runs when the conditions described in
413 its when-expression become true.
414
415 When jobs are I<edge triggered>.  This means that they run when the
416 condition changes from false to true (or in the case where the
417 expression has not been evaluated before, when it evaluates initially
418 to true).
419
420 =head3 WHEN EXPRESSIONS
421
422 When expressions are fully recursive expressions constructed from the
423 following elements:
424
425 =over 4
426
427 =item I<expr> B<&&> I<expr>
428
429 =item I<expr> B<||> I<expr>
430
431 The boolean "and" or "or" of the two sub-expressions.
432
433 =item I<expr> B<E<lt>> I<expr>
434
435 =item I<expr> B<E<lt>=> I<expr>
436
437 =item I<expr> B<==> I<expr>
438
439 =item I<expr> B<E<gt>=> I<expr>
440
441 =item I<expr> B<E<gt>> I<expr>
442
443 The two sub-expressions are evaluated and the usual comparison
444 operator is performed.
445
446 If the sub-expressions are numeric, then numeric comparison is done.
447 If either sub-expression is non-numeric, then both expressions are
448 converted (if necessary) to strings and string comparison is done.
449
450 =item B<!> I<expr>
451
452 Boolean negative of I<expr>.
453
454 =item I<expr> B<+> I<expr>
455
456 For numeric sub-expressions, this performs addition.
457
458 If both sub-expressions are strings, this performs string
459 concatenation.
460
461 Other types give an error.
462
463 =item I<expr> B<-> I<expr>
464
465 =item I<expr> B<*> I<expr>
466
467 =item I<expr> B</> I<expr>
468
469 =item I<expr> B<mod> I<expr>
470
471 Both sub-expressions are evaluated, and if both are numeric, then the
472 result is subtraction, multiplication, division or modulo.
473
474 Other types give an error.  Note that I<mod> really is an infix
475 operator.
476
477 =item B<len> I<expr>
478
479 If I<expr> is a string, this returns the length of the string.
480
481 =item I<variable>
482
483 The value of the named variable.
484
485 Previously undefined variables are automatically initialized to the
486 empty string.
487
488 =item B<prev> I<variable>
489
490 The I<previous> value of the named variable.  This means, the value
491 that it had last time this when-job ran.
492
493 If the when-job has not run yet, then this returns C<"">.
494
495 Job state is preserved across file reloads, but I<only> for jobs that
496 are explicitly named.  If you find that jobs using C<prev>, C<changes>
497 etc are running unnecessarily when the jobs file is edited or
498 uploaded, try giving the jobs an explicit name.
499
500 =item B<changes> I<variable>
501
502 If the named variable has changed since this job last ran, then this
503 evaluates to true, else false.
504
505 This is the same as writing C<prev variable == variable>.
506
507 =item B<increases> I<variable>
508
509 If the named variable has changed and increased since this job last
510 ran, then this evaluates to true, else false.
511
512 This is the same as writing C<prev variable E<lt> variable>.
513
514 =item B<decreases> I<variable>
515
516 If the named variable has changed and decreased since this job last
517 ran, then this evaluates to true, else false.
518
519 This is the same as writing C<prev variable E<gt> variable>.
520
521 B<Note:> There is a subtle gotcha with the I<decreases> operator: The
522 first time the expression is evaluated, the job has (by definition)
523 not yet run.  Therefore C<prev variable> evaluates to C<""> (see
524 definition of I<prev> above).  Since it is always true that
525
526  "" < anything
527
528 the I<decreases> operator evaluates to false, and since this usually
529 means the job does not run, the operator always evaluates to false.
530
531 To fix this, ensure that the variable is initialized (see
532 L</SETTING THE INITIAL VALUE OF VARIABLES> below).
533
534 =item B<reloaded ()>
535
536 This evaluates to true the first time the expression is evaluated
537 after the jobs file has been reloaded or the daemon restarted.
538 Thereafter it evaluates to false.
539
540 Don't use this to initialize variables: it won't do what you mean.
541
542 =item B<false>
543
544 =item B<true>
545
546 Constants that evaluate to boolean false or true respectively.
547
548 =item I<"any string">
549
550 Any string.
551
552 In a boolean context, the empty string evaluates to false, and
553 non-empty strings evaluate to true.
554
555 =item I<N>
556
557 Any integer.  (Arbitrarily large integers are supported.)
558
559 In a boolean context, 0 evaluates to false, and non-zero evaluates to
560 true.
561
562 =item I<N.>
563
564 =item I<.N>
565
566 =item I<N.N>
567
568 =item I<N.NeN>
569
570 Any floating point number.
571
572 In a boolean context, 0 evaluates to false, and non-zero evaluates to
573 true.
574
575 =back
576
577 =head2 SHELL SCRIPTS
578
579 The code between C<E<lt>E<lt> ... E<gt>E<gt>> is a shell script.  It
580 is executed using C<$SHELL>, or if that environment variable is not
581 set then C</bin/sh>.
582
583 =head3 SHELL SCRIPT VARIABLES
584
585 Every variable that has been set (using the whenjobs I<--set> option)
586 is exported to the script, so you can simply get the value of any
587 variable by writing C<$name>.
588
589 In addition, there are some special variables available:
590
591 =over 4
592
593 =item C<$JOBNAME>
594
595 The name of the job.  If the job has been named explicitly, then that
596 name is available through this variable, else it will be some implicit
597 name like C<job$1>.
598
599 =item C<$JOBSERIAL>
600
601 The serial number of the job.  This is simply a variable that
602 increments each time a job is run, and is unique to that run of the
603 job.
604
605 =back
606
607 Other environment variables such as C<$HOME>, C<$LOGNAME> etc are
608 available as normal.
609
610 =head3 SHELL SCRIPT TEMPORARY CURRENT DIRECTORY
611
612 The shell script runs with its current directory set to a temporary
613 directory.  The temporary directory is removed when the shell script
614 exits.  Therefore you can write temporary files here without worrying
615 about cleaning them up.
616
617 If you want to store permanent state, then you have to save it to a
618 well-known directory, eg. C<$HOME>, C</var> etc.
619
620 =head3 SHELL SCRIPT USER
621
622 The shell script runs as the ordinary user.  It has no special
623 privileges.
624
625 =head2 JOB NAMES
626
627 Jobs are given implicit names (C<job$1>, C<job$2> etc.).  You can also
628 name jobs explicitly by preceeding the "every" or "when" statement
629 with C<job "name">:
630
631  job "poll source"
632  every 10 seconds :
633  <<
634    # ...
635  >>
636
637 The job name is passed to the shell script in the C<$JOBNAME>
638 environment variable.
639
640 =head2 OCAML EXPRESSIONS
641
642 As well as simple "every" and "when" expressions, advanced users may
643 want to use arbitrary OCaml expressions, functions, etc in the jobs
644 script.  These are useful for factoring common code or strings, for
645 setting the initial values of variables, or for defining pre and post
646 functions.
647
648 A simple example of an OCaml expression is:
649
650  let prefix = "daily_"
651  
652  job (prefix ^ "virus_scan")
653  every day :
654  <<
655    # ...
656  >>
657  
658  job (prefix ^ "disk_check")
659  every day :
660  <<
661    # ...
662  >>
663
664 which creates two jobs called C<"daily_virus_scan"> and
665 C<"daily_disk_check"> (C<^> is the OCaml string concatenation
666 operator).
667
668 OCaml expressions have access to a library of functions called
669 B<Whentools> which is described below.  It lets you set variables,
670 create jobs algorithmically, etc.
671
672 The OCaml expressions run once, when the jobs file is being loaded or
673 reloaded.
674
675 =head3 SETTING THE INITIAL VALUE OF VARIABLES
676
677 Variables are created when they are referenced, and until set they
678 have the value empty string (just like the shell).  Across file
679 reloads, the previous values of variables are preserved.
680
681 To initialize a variable to a known value when the jobs file is
682 loaded, call one of the C<Whentools.set_variable*> functions as in
683 this example:
684
685  let () =
686    Whentools.set_variable "name" "Richard";
687    Whentools.set_variable_int "counter" 0
688
689 =head3 PRE FUNCTIONS
690
691 Before a job runs, you can arrange that a C<pre> function is called.
692 This function may decide not to run the job (by returning C<false>).
693
694 One use for this is to prevent a particular job from running if there
695 is already an instance of the same job running:
696
697  job "only one"
698  pre (Whentools.one ())
699  every 10 seconds :
700  <<
701    # Takes longer than 10 seconds to run, but 'Whentools.one ()'
702    # will ensure only one is ever running.
703    sleep 11
704  >>
705
706 When using pre functions, jobs must be given an explicit name, ie.
707 you must use the C<job> statement.
708
709 A number of pre functions are available in the library; see below.
710
711 You can also write your own post functions (in OCaml).  The function
712 is passed one argument which is a C<Whentools.preinfo> struct, defined
713 below.  It should return a boolean: C<true> if the job should run, and
714 C<false> if the job should not run.
715
716 Note that a fresh serial number (see L</JOBSERIAL>) is assigned to
717 each run, whether or not the job actually runs because of
718 preconditions.
719
720 =head3 POST FUNCTIONS
721
722 After a job runs, you can control what happens to its output by
723 writing a C<post> function.  To write a post function you have to
724 name the job (ie. have an explicit C<job> statement).  Put C<post ...>
725 after the job name like this:
726
727  job "poll source"
728  post (Whentools.mailto "you@example.com")
729  every 10 seconds :
730  <<
731    # ...
732  >>
733
734 A number of post functions are available in the library; see below.
735
736 You can also write your own post functions (in OCaml).  The
737 function is passed one argument which is a C<Whentools.result> struct,
738 defined below.
739
740 =head3 WHENTOOLS LIBRARY
741
742 =head4 Functions
743
744 =over 4
745
746 =item B<Whentools.mailto> [I<~only_on_failure:true>]
747 [I<~from:from_address>] I<email_address> I<result>
748
749 This built-in post function sends the result of the script by email to
750 the given email address.
751
752 If the optional C<~only_on_failure:true> flag is set, then it is only
753 sent out if the script failed.
754
755 If the optional C<~from> flag is set, then the from address is set
756 accordingly.  This is sometimes needed when sending mail.
757
758 Note the C<result> parameter is passed implicitly by the daemon.  You
759 do not need to add it.
760
761 Here are some examples of using the mailto function:
762
763  job "ex.1"
764  post (Whentools.mailto "you@example.com")
765  every 10 seconds :
766  <<
767    # do something
768  >>
769
770  job "ex.2"
771  post (Whentools.mailto ~only_on_failure:true
772                         "you@example.com")
773  every 10 seconds :
774  <<
775    # do something
776  >>
777
778  let from = "me@example.com"
779  let to_addr = "you@example.com"
780  
781  job "ex.3"
782  post (Whentools.mailto ~from to_addr)
783  every 10 seconds :
784  <<
785    # do something
786  >>
787
788 =item B<Whentools.max> I<n>
789
790 This built-in pre function ensures that a maximum of I<n> instances of
791 the job are running.
792
793 It checks the list of running jobs, and if I<n> or more instances are
794 already running, then it returns C<false>, which ensures that the new
795 job is not started.
796
797 =item B<Whentools.one> I<()>
798
799 This built-in pre function ensures that only one instance of the job
800 is running.  It is the same as calling:
801
802  Whentools.max 1
803
804 =item B<Whentools.set_variable> I<name> I<string>
805
806 Set variable I<name> to the string.
807
808 =item B<Whentools.set_variable_bool> I<name> I<b>
809
810 Set variable I<name> to the boolean value I<b>.
811
812 =item B<Whentools.set_variable_int> I<name> I<i>
813
814 Set variable I<name> to the integer value I<i>.
815
816 =item B<Whentools.set_variable_string> I<name> I<s>
817
818 Set variable I<name> to the string value <s>.  This is
819 the same as I<Whentools.set_variable>.
820
821 =item B<Whentools.set_variable_float> I<name> I<f>
822
823 Set variable I<name> to the floating point value I<f>.
824
825 =back
826
827 =head4 Structures
828
829 =over 4
830
831 =item B<Whentools.preinfo>
832
833 This structure is passed to pre functions.  It has the following
834 fields:
835
836  type preinfo = {
837    pi_job_name : string;           # Job name.
838    pi_serial : Big_int.big_int;    # Job serial number.
839    pi_variables : (string * variable) list; # Variables set in job.
840    pi_running : preinfo_running_job list;   # List of running jobs.
841  }
842  and preinfo_running_job = {
843    pirun_job_name : string;        # Running job name.
844    pirun_serial : Big_int.big_int; # Running job serial number.
845    pirun_start_time : float;       # Running job start time.
846    pirun_pid : int;                # Running job process ID.
847  }
848
849 =item B<Whentools.result>
850
851 This structure is passed to post functions.  It has the following
852 fields:
853
854  type result = {
855    res_job_name : string;  # job name
856    res_serial : big_int;   # job serial (same as $JOBSERIAL)
857    res_code : int;         # return code from the shell script
858    res_tmpdir : string;    # temporary directory script ran in
859    res_output : string;    # filename of stdout/stderr output
860    res_start_time : float; # when the job started
861  }
862
863 =back
864
865 =head1 MULTIPLE JOBS FILES
866
867 The whenjobs I<-e> and I<-l> options edit and list a file called
868 C<$HOME/.whenjobs/jobs.ml>.
869
870 You can also edit C<$HOME/.whenjobs/jobs.ml> by other means (eg.  your
871 own editor).  After editing, to recompile and upload it, use:
872
873  whenjobs --upload
874
875 When you have lots of jobs, it is convenient to split the jobs across
876 multiple files.  Any C<*.ml> files located in C<$HOME/.whenjobs> can
877 be used (with some restrictions on filenames -- see below).  These are
878 compiled and loaded into the daemon using the I<--upload> command.
879
880 To create multiple jobs files, you cannot use the I<-e> or I<-l>
881 options.  Instead you have to create them yourself in
882 C<$HOME/.whenjobs>, and when you have finished creating or editing
883 them, upload them.
884
885 =head2 FILENAME RESTRICTIONS ON JOBS FILES
886
887 In OCaml, a file called C<jobs.ml> corresponds to an OCaml module
888 called C<Jobs> (note the capitalization).  OCaml module names can only
889 contain ASCII alphanumeric characters, underscore, and C<'> (single
890 quote), and they must begin with an alphabetic character.  The same
891 rules apply to jobs files.
892
893 Furthermore, various OCaml module names are reserved (eg. C<Map>,
894 C<List>).  It is therefore better to prefix any names with something
895 specific to your application.
896
897 Examples of legal filenames are:
898
899  foo.ml
900  app_foo.ml
901  app_123.ml
902  jobs.ml
903
904 Examples of illegal filenames are:
905
906  ann.txt    # must end with .ml
907  123.ml     # must begin with alphabetic
908  app!.ml    # must contain alphanumeric or underscore
909  app-foo.ml # must contain alphanumeric or underscore
910  map.ml     # reserved module name
911
912 =head1 FILES
913
914
915
916 =head1 ENVIRONMENT VARIABLES
917
918
919
920 =head1 SEE ALSO
921
922 L<whenjobsd(8)>
923
924 =head1 AUTHOR
925
926 Richard W.M. Jones L<http://people.redhat.com/~rjones/>
927
928 =head1 COPYRIGHT
929
930 Copyright (C) 2012 Red Hat Inc.
931
932 This program is free software; you can redistribute it and/or modify
933 it under the terms of the GNU General Public License as published by
934 the Free Software Foundation; either version 2 of the License, or
935 (at your option) any later version.
936
937 This program is distributed in the hope that it will be useful,
938 but WITHOUT ANY WARRANTY; without even the implied warranty of
939 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
940 GNU General Public License for more details.
941
942 You should have received a copy of the GNU General Public License
943 along with this program; if not, write to the Free Software
944 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.