/ man / daemon.sh.3
daemon.sh.3
  1  .if n.ad l
  2  .nh
  3  
  4  .TH daemon.sh 1 "2018-10-10" "shellman 0.4.1" "User Commands"
  5  
  6  .SH "NAME"
  7  daemon.sh \- Provide functions to ease creation of daemon scripts.
  8  
  9  .SH "DESCRIPTION"
 10  Simple consumers:
 11  
 12  Multiple consumers can consume the same directory.
 13  Each time a consumer wants to process a file, it tries to lock it.
 14  To lock it, it tries to create a directory named after the sha256 sum of
 15  the file name (file being a regular file or a directory).
 16  If the lock fails, it means the file is being processed by another consumer,
 17  and the consumer continue to the next file.
 18  If the lock succeeds, the consumer process the file, move the file,
 19  and then remove the lock.
 20  If all files in the directory are locked, consumers wait a certain amount of
 21  time before trying again to process files.
 22  If the directory is empty, consumers wait a certain amount of time before
 23  listing it again.
 24  
 25  Chained-consumers:
 26  
 27  Multiple directories can each be consumed by several consumers (note: a
 28  consumer consumes one and only one directory). The processed files transit
 29  from one directory to another, until they finally land in a not-consumed
 30  directory. In each directory, they are processed accordingly to what the
 31  consumers for this directory are doing (example: filter video files ->
 32  extract audio -> reencode to specific format -> normalize to N decibels ->
 33  move to final music folder).
 34  For a particular directory, consumers behave exactly like simple consumers,
 35  except for the following:
 36  
 37  In addition to setting a lock for the current directory
 38  when processing a file, consumers also set a lock (with the
 39  potential post-process name of the file) for the next directory in the
 40  chain. This is done to avoid files being processed by the next consumers
 41  before the files are completely moved to the next directory.
 42  
 43  .SH "ENVIRONMENT VARIABLES"
 44  .TP
 45  .B CONSUMED_DIR
 46  Path to directory to consume.
 47  .TP
 48  .B WAIT_WHEN_EMPTY
 49  Time to wait (in seconds) when consumed directory is empty.
 50  .TP
 51  .B WAIT_WHEN_LOCKED
 52  Time to wait (in seconds) when all items in consumed directory are locked.
 53  
 54  .SH "FUNCTIONS"
 55  .IP "\fBsha STRING\fR" 4
 56  Compute sha256sum of string.
 57  
 58  .I Arguments
 59      \fBSTRING\fR - String to compute sum for.
 60  
 61  .IP "\fBconsumer_lock NAME [DIR]\fR" 4
 62  Lock the given item thanks to its name.
 63  
 64  .I Arguments
 65      \fBNAME\fR - Name of the item to lock.
 66      \fBDIR \fR - Directory in which to create the lock (default to data).
 67  
 68  .IP "\fBconsumer_unlock NAME [DIR]\fR" 4
 69  Unlock the given item thanks to its name.
 70  
 71  .I Arguments
 72      \fBNAME\fR - Name of the item to unlock.
 73      \fBDIR \fR - Directory in which to remove the lock (default to data).
 74  
 75  .IP "\fBconsumer_locked NAME [DIR]\fR" 4
 76  Test if NAME is locked.
 77  
 78  .I Arguments
 79      \fBNAME\fR - Name of the item to test.
 80      \fBDIR \fR - Directory in which to check the lock (default to data).
 81  
 82  .IP "\fBconsumer_unlocked NAME [DIR]\fR" 4
 83  Test if NAME is unlocked.
 84  
 85  .I Arguments
 86      \fBNAME\fR - Name of the item to test.
 87      \fBDIR \fR - Directory in which to check the lock (default to data).
 88  
 89  .IP "\fBconsumer_get FILE\.\.\.\fR" 4
 90  Lock then move each given file into consumed directory.
 91  
 92  .I Arguments
 93      \fBFILE\fR - Single or multiple files to move into consumed directory.
 94  
 95  .IP "\fBconsumer_send DAEMON FILE\.\.\.\fR" 4
 96  Lock then move each given file to consumed directory of DAEMON.
 97  
 98  .I Arguments
 99      \fBDAEMON\fR - The daemon to send the files to (into its consumed directory).
100      \fBFILE  \fR - Single or multiple files to move into consumed directory.
101  
102  .IP "\fBconsumer_location\fR" 4
103  Return the path to the consumed directory.
104  
105  .IP "\fBconsumer_empty [DIR]\fR" 4
106  Test if consumed directory is empty.
107  
108  .I Arguments
109      \fBDIR\fR - Directory to check (default to consumed directory).
110  
111  .IP "\fBconsumer_consume NAME\fR" 4
112  Consume (process) file identified by NAME. You must rewrite this function.
113  
114  .I Arguments
115      \fBNAME\fR - Name of the file/folder to process.