1 | # |
---|
2 | # Copyright (c) 2004-2007 - Consultas, PKG.fr |
---|
3 | # |
---|
4 | # This file is part of A2P. |
---|
5 | # |
---|
6 | # A2P is free software; you can redistribute it and/or modify |
---|
7 | # it under the terms of the GNU General Public License as published by |
---|
8 | # the Free Software Foundation; either version 2 of the License, or |
---|
9 | # (at your option) any later version. |
---|
10 | # |
---|
11 | # A2P is distributed in the hope that it will be useful, |
---|
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | # GNU General Public License for more details. |
---|
15 | # |
---|
16 | # You should have received a copy of the GNU General Public License |
---|
17 | # along with A2P; if not, write to the Free Software |
---|
18 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
19 | # |
---|
20 | # $Id: Globals.pm 3 2007-10-18 16:20:19Z guillaume $ |
---|
21 | # |
---|
22 | |
---|
23 | package A2P::Globals ; |
---|
24 | |
---|
25 | use strict ; |
---|
26 | use Time::HiRes qw( gettimeofday ) ; |
---|
27 | use A2P::Init ; |
---|
28 | |
---|
29 | BEGIN { |
---|
30 | use Exporter (); |
---|
31 | |
---|
32 | our ( $VERSION, $SERVICE, @ISA, @EXPORT, @EXPORT_OK, @SHARED ); |
---|
33 | |
---|
34 | $VERSION = sprintf "%s", q$Rev: 1162 $ =~ /(\d[0-9.]+)\s+/ ; |
---|
35 | $SERVICE = defined($ENV{'LOCKID'}) ? 1 : 0 ; |
---|
36 | |
---|
37 | @ISA = qw(Exporter); |
---|
38 | |
---|
39 | # Export every constants |
---|
40 | @EXPORT = qw( |
---|
41 | %means &QUIT &PING &_INIT &NOMOREFILE $Progname $StdoutFile |
---|
42 | &DONE $MUSTQUIT $LISTENER &TODO $maintid $do_file $A2P_SYS_CONF |
---|
43 | &A2P_RPM_VERSION %STATS &UPSTAT @SHARED &_UPDATE $SYSLOG &TIMESTAT |
---|
44 | &MAXSTAT &MAXMINSTAT @AbortTime $AFPNAME_REGEX &DOWNSTAT |
---|
45 | ); |
---|
46 | |
---|
47 | # List of thread shared and updatable variables to export |
---|
48 | # DEV2 |
---|
49 | @SHARED = qw( |
---|
50 | $NO_SYSLOG_DEBUG $AFPSPOOL $USLEEP $AFP2PRINT_PATH $ARCH_DEBUG |
---|
51 | $SHMDIR $ERRORSPOOL $DONESPOOL $LOGOPATH $ARCH_SCENARIO $PCL_RESOLUTION |
---|
52 | $MAXTASK $DESTIDFILE $COMPRESSFILES $DONTZIPPDF $PURGEFILES $DO_PING |
---|
53 | $PARALLELE_VALIDATION $DVILJ $ZIPOPTIONS $LOCKID $NODEBUG_MOD_LIST |
---|
54 | $MINFOLDERCOUNT $MAXFOLDERCOUNT $ARCH_REMHOST_TEST $ARCH_REMPORT_TEST |
---|
55 | $ARCH_REMHOST_TLOG $ARCH_REMPORT_TLOG $ARCH_REMHOST_PROD $PNGCOMPRESSION |
---|
56 | $MAIL_BIN $ALERT_MAILS $ERROR_MAILS $LOGFILENAME $SPOOL_PREFIX |
---|
57 | $LOGFILE_VS_SYSLOG $ARCH_ENABLED $USE_PCLCMD $LOGFILE_PURGE $KEEP_AFPJOB |
---|
58 | $COM_BURST $SCAN_SPOOL $MAX_BACKLOG $WAIT_ON_PREFIX $MAXRETRYTIMER |
---|
59 | $CLIENT_TIMEOUT $START_LOGGER $NODEBUG_SUB_LIST $CONV_STATUS_TIMING |
---|
60 | $KEEP_STATS $STATS_FOLDER $MAXFILES_BY_ZIPCMD $SYSLOG_PATH |
---|
61 | $KEEP_JOBSTATUS $DONT_PRINT $FORCE_DESTID $SPOOL_TIMER $GIFTOPCL |
---|
62 | $AGREGATE_PRINT $BACKEND_FACTOR $SERVICE_TMP $COM_LOCKING $MAXJOBS |
---|
63 | $SERVICE_DEBUG $STDOUT_DEBUG $MAX_BUFFER_SIZE $DEBUG_IN_FILE |
---|
64 | $ADDTEX_DEBUG $TEX_PAGEDEF_DEBUG $TEX_OVERLAY_DEBUG $TEX_SEGMENT_DEBUG |
---|
65 | $TEX_SHOW_SEGMENT $ADVANCED_DEBUGGING $ARCH_REMPORT_PROD |
---|
66 | $KEEP_DYNAMIC_JOB_LOG $JOB_DUMP_ON_ERROR $JOIN_ZIP_ON_ERROR |
---|
67 | $CLEAN_OPTIMIZATION $DYNAMIC_USLEEP $MAX_DYNAMIC_USLEEP $MAX_CONV_RATE |
---|
68 | $ADDTEX_DOCINFO $ADDPCL_JOBNAME $ADDPCL_USERNAME $ONLY_DO_PDF |
---|
69 | $MAXCONNECTIONS $USE_TCPIP_SOCKET $USE_TCPIP_PORT $USE_ONLY_LOOPBACK |
---|
70 | $AUTHORIZED_HOST $ESERVICE_ENABLED $ESERVICE_CONF $CONVERT_CONTENT_FILE |
---|
71 | $CLOSE_CONNECTIONS $ENABLE_DTD_VALIDATION $DOCSFILE $STATUS_DB_MAXAGE |
---|
72 | $DOCUMENTS_CORRECTION_ENABLED $DBI_DSN $DBI_USER $DBI_PASSWD |
---|
73 | $A2PDB_TABLE_PREFIX $STATSFILE_MAXAGE $STATUS_MAXAGE $DO_CONVERT |
---|
74 | $FROM_CONVERT $TO_CONVERT $STATS_COMMIT_SKIP $MAX_CACHED_DB $MAX_LINES |
---|
75 | $RECONNECT_TIMER $STATUS_CACHE_MAXAGE $MAX_CACHED_STATUS $JOBS_COUNTDOWN |
---|
76 | $ENABLE_SPLITTER $BACKEND_RETRY $BACKEND_RETRYTIMEOUT $AUTO_SPLIT_MAX |
---|
77 | $DO_DB_OPTIMIZATION |
---|
78 | ); |
---|
79 | |
---|
80 | # Add here to @SHARED some parameters only used in init script not to |
---|
81 | # initialize |
---|
82 | push @SHARED , qw( |
---|
83 | $AFP2PRINT_USER $PERL $A2P_SYS_CONF $NICE $SERVICE_PROG $PRINTLIB_PATH |
---|
84 | $TEXSPOOL |
---|
85 | ); |
---|
86 | |
---|
87 | # Add shared to export list |
---|
88 | push @EXPORT , @SHARED ; |
---|
89 | |
---|
90 | @EXPORT_OK = qw( &UpdateSharedEnv &get_default_lockid ); |
---|
91 | } |
---|
92 | our @SHARED ; |
---|
93 | our $SYSLOG ; |
---|
94 | our $SERVICE; |
---|
95 | |
---|
96 | # Defaults only used in bash scripts |
---|
97 | our $AFP2PRINT_USER = 'afp2print' ; |
---|
98 | our $PERL = '/usr/bin/perl' ; |
---|
99 | our $NICE = 'nice --5' ; |
---|
100 | our $SERVICE_PROG = '$AFP2PRINT_PATH/a2p.pl' ; |
---|
101 | our $PRINTLIB_PATH = '$AFP2PRINT_PATH/printlib' ; |
---|
102 | our $TEXSPOOL = '' ; |
---|
103 | |
---|
104 | ################################################################################ |
---|
105 | ## Threads shared variables ## |
---|
106 | ## Each one would be re-initialized by Init function as needed ## |
---|
107 | ################################################################################ |
---|
108 | # DEV: When adding shared variable, dev lines must be added at: |
---|
109 | # DEV1: its 'our' definition with eventually its default value |
---|
110 | # DEV2: and also, it must be inserted in SHARED list (see BEGIN block) |
---|
111 | |
---|
112 | # DEV1 |
---|
113 | |
---|
114 | # This is a constant to be update during rpm packaging |
---|
115 | sub A2P_RPM_VERSION () { '1.024' } |
---|
116 | |
---|
117 | # NO_LOGFILE is to be greater than 0 to output log to a file and to syslog |
---|
118 | # Default to 0 to not have logfile |
---|
119 | our $LOGFILE_VS_SYSLOG = 0 ; |
---|
120 | our $LOGFILE_PURGE = 0 ; |
---|
121 | our $LOGFILENAME = "/var/log/a2p.debug" ; |
---|
122 | |
---|
123 | # NO_SYSLOG_DEBUG is to be greater than 0 to not send any Debug to syslog |
---|
124 | # Default to 0 to always debug service start (not critical) |
---|
125 | our $NO_SYSLOG_DEBUG = 0 ; |
---|
126 | |
---|
127 | # SERVICE_DEBUG can be disabled to avoid debugging when service is shutting down |
---|
128 | our $SERVICE_DEBUG = 1 ; |
---|
129 | |
---|
130 | # SYSLOG_PATH is the standard socket where to send syslog message to system |
---|
131 | our $SYSLOG_PATH = "/dev/log" ; # Unix dfault |
---|
132 | our $STDOUT_DEBUG = 0 ; # Send debug to standard console output if set |
---|
133 | our $DEBUG_IN_FILE = 0 ; # To avoid sending debugging to syslog |
---|
134 | # ADVANCED_DEBUGGING should not be used in configuration but can be dynamically |
---|
135 | # be set by sending signal 12 (USR2) to a thread, see details in A2P::Signal |
---|
136 | our $ADVANCED_DEBUGGING = 0 ; # To activate some online debugging |
---|
137 | |
---|
138 | # KEEP_DYNAMIC_JOB_LOG keeps job info that will be only available in the mail |
---|
139 | # sent to the ERRORS_MAIL list when an AlertError rises. |
---|
140 | our $KEEP_DYNAMIC_JOB_LOG = 1 ; |
---|
141 | # Set it to 0 to desactivate |
---|
142 | # Set it a greater value than 1 to also keep debugging messages |
---|
143 | |
---|
144 | our $JOB_DUMP_ON_ERROR = 1 ; # By default make a job dump in the error mail |
---|
145 | our $JOIN_ZIP_ON_ERROR = 1 ; # By default add zip when exist to dumped job |
---|
146 | |
---|
147 | # By default, we could keep some few last log messages, |
---|
148 | # used for job debugging on error and mailed report |
---|
149 | our $MAX_BACKLOG = 10 ; |
---|
150 | |
---|
151 | # TeX info insertion enabled mostly for PDF Title and Creator |
---|
152 | our $ADDTEX_DOCINFO = 1 ; |
---|
153 | |
---|
154 | # PCL5 info insertion can be forced for all produced PCL otherwise it should be |
---|
155 | # enabled by DESTID in desti configuration file |
---|
156 | our $ADDPCL_JOBNAME = 0 ; |
---|
157 | our $ADDPCL_USERNAME = 0 ; |
---|
158 | |
---|
159 | # TeX debugging for TeX validation only |
---|
160 | our $ADDTEX_DEBUG = 0 ; # Set alone, it outputs font names in TeX output |
---|
161 | # ADDTEX_DEBUG must be true to use these following |
---|
162 | our $TEX_PAGEDEF_DEBUG = 0 ; # Show PAGEDEF frame and page off-set used |
---|
163 | our $TEX_OVERLAY_DEBUG = 0 ; # Show OVERLAY frames and page off-set used |
---|
164 | our $TEX_SEGMENT_DEBUG = 0 ; # Show SEGMENT frames and page off-set used |
---|
165 | our $TEX_SHOW_SEGMENT = 1 ; # Remove SEGMENT |
---|
166 | |
---|
167 | # Do we should start a logger thread |
---|
168 | our $START_LOGGER = 1 ; |
---|
169 | |
---|
170 | # KEEP_STATS actives conversion statistics if set to 1 |
---|
171 | our $KEEP_STATS = 1 ; |
---|
172 | our $STATS_FOLDER = "/apps/afp2print/stats" ; |
---|
173 | |
---|
174 | # KEEP_JOBSTATUS can be set to 0 to disable keeping job status |
---|
175 | our $KEEP_JOBSTATUS = 1 ; |
---|
176 | |
---|
177 | # This is the max number of com to manage in one loop |
---|
178 | our $COM_BURST = 5 ; |
---|
179 | # This set the use of locking feature during communication between processes |
---|
180 | # It can be imply a performance issue but also a stability issue if disabled |
---|
181 | our $COM_LOCKING = 0 ; # Not useful with new comm scheme |
---|
182 | our $MAX_BUFFER_SIZE = 65536 ; |
---|
183 | |
---|
184 | # DEBUG_MOD_LIST is to be populated with module or file name to not debug |
---|
185 | # DEBUG_SUB_LIST is to be populated with subfunction name to not debug |
---|
186 | # This comportement can be inversed by inserting the '!' char at beginning |
---|
187 | our $NODEBUG_MOD_LIST = "" ; |
---|
188 | our $NODEBUG_SUB_LIST = "" ; |
---|
189 | |
---|
190 | # DO_PINGPONG is to be greater than 0 to ping threads periodictly |
---|
191 | our $DO_PING = 1 ; |
---|
192 | |
---|
193 | # AFPSPOOL is the spool directory where AFPDS file will be expected |
---|
194 | our $AFPSPOOL = '/apps/afp2print/afpspool' ; |
---|
195 | |
---|
196 | # SCAN_SPOOL should be disabled for a validation service which don't need |
---|
197 | # to scan the spool. It will also disable SpoolManager launch. |
---|
198 | our $SCAN_SPOOL = 1 ; |
---|
199 | # SPOOL_TIMER is the number of seconds between 2 checks in spool when idle |
---|
200 | our $SPOOL_TIMER = 5 ; |
---|
201 | # SPOOL_PREFIX is to tune de prefix selection in the spool (NOT case sensitive) |
---|
202 | our $SPOOL_PREFIX = "TRANS ARCHI" ; |
---|
203 | # WAIT_ON_PREFIX could be set to activate the wait on prefix locking |
---|
204 | our $WAIT_ON_PREFIX = 0 ; |
---|
205 | |
---|
206 | # USLEEP is the time in microsecond to sleep in thread loops |
---|
207 | our $USLEEP = 50000 ; |
---|
208 | # DYNAMIC_USLEEP set USLEEP to dynamic mode |
---|
209 | our $DYNAMIC_USLEEP = 1 ; |
---|
210 | our $MAX_DYNAMIC_USLEEP = 1_000_000 ; # Max USLEEP in dynamic mode (in ms) |
---|
211 | |
---|
212 | # CLEAN_OPTIMIZATION can be disable to force new job creation only after |
---|
213 | # previous jobs have been cleaned |
---|
214 | our $CLEAN_OPTIMIZATION = 1 ; |
---|
215 | |
---|
216 | # This is the default project path installation |
---|
217 | our $AFP2PRINT_PATH = '/apps/afp2print' ; |
---|
218 | |
---|
219 | # SHMDIR default to "/dev/shm" to optimize throughput as be done in memory |
---|
220 | our $SHMDIR = '/dev/shm' ; |
---|
221 | |
---|
222 | # SERVICE_TMP is the path where to use temporary files |
---|
223 | our $SERVICE_TMP = '/tmp/.a2p' ; |
---|
224 | |
---|
225 | # ERRORSPOOL is the spool directory where failed conversion files will be moved |
---|
226 | our $ERRORSPOOL = '/apps/afp2print/spool/error' ; |
---|
227 | |
---|
228 | # DONESPOOL is the spool directory where done conversion files will be moved |
---|
229 | our $DONESPOOL = '/apps/afp2print/spool/done' ; |
---|
230 | |
---|
231 | # LOGOPATH must point to the segment library |
---|
232 | our $LOGOPATH = '/apps/afp2print/printlib/seglib' ; |
---|
233 | |
---|
234 | # MAXTASK is set to the number of concurrent conversion to process |
---|
235 | our $MAXTASK = 1 ; |
---|
236 | |
---|
237 | # MAXJOBS is set to the maximum AFP jobs we can process at a time |
---|
238 | our $MAXJOBS = 1 ; |
---|
239 | |
---|
240 | # MAXCONNECTIONS is the maximum concurrent connections that we be accepted by |
---|
241 | # any Listener |
---|
242 | our $MAXCONNECTIONS = 10 ; |
---|
243 | |
---|
244 | # By default Listener won't listen on TCP/IP socket |
---|
245 | our $USE_TCPIP_SOCKET = 0 ; |
---|
246 | our $USE_TCPIP_PORT = 6400 ; |
---|
247 | # By default TCP/IP server will listen only on the localhost (127.0.0.1) |
---|
248 | our $USE_ONLY_LOOPBACK = 1 ; |
---|
249 | # Even if listening over internet we only accept connection from just localhost |
---|
250 | # by default. Set it to "0.0.0.0" or "any" to accept from any host |
---|
251 | our $AUTHORIZED_HOST = "127.0.0.1" ; |
---|
252 | |
---|
253 | # MAX_CONV_RATE is used to limit the conversion rate on big job. It is the |
---|
254 | # maximum number of conversion to do during one second, and it is really used |
---|
255 | # only with AFP job with more than this value of sub jobs |
---|
256 | # Default MAX_CONV_RATE=20 means AFP jobs with more than 20 sub-jobs will have |
---|
257 | # their TeX conversion limited to not exceed 20 sub-jobs created for each second |
---|
258 | # This should be used to avoid processes communication saturation |
---|
259 | # Remark: - if set to 0, conversion will slow down to reach one conversion by |
---|
260 | # USLEEP interval |
---|
261 | # - it is disabled with negative value |
---|
262 | our $MAX_CONV_RATE = -1 ; |
---|
263 | |
---|
264 | # BACKEND_FACTOR must be greater than 0 and define the numbre of processes |
---|
265 | # (multiplied by MAXTASK) that will be used to call command on the system and |
---|
266 | # this defined also the number of ARchiver processes |
---|
267 | # Exemple: |
---|
268 | # - If MAXTASK = 1 and BACKEND_FACTOR = 3 (this is the default) |
---|
269 | # 3 BackEnd processes will be managed |
---|
270 | # 3 Archiver will be also managed if ARCH_ENABLED is set |
---|
271 | # - If MAXTASK = 2 and BACKEND_FACTOR = 5 |
---|
272 | # 10 BackEnd processes will be managed |
---|
273 | # 10 Archiver will be also managed if ARCH_ENABLED is set |
---|
274 | our $BACKEND_FACTOR = 3 ; |
---|
275 | # Maximum number of retries when command fails |
---|
276 | our $BACKEND_RETRY = 10 ; |
---|
277 | # Maximum number of seconds when command fails to really set the command failed |
---|
278 | our $BACKEND_RETRYTIMEOUT = 30 ; |
---|
279 | |
---|
280 | # DESTIDFILE is the configuration file for print configuration |
---|
281 | our $DESTIDFILE = '/etc/afp2print/destid.conf' ; |
---|
282 | |
---|
283 | # DOCSFILE is the configuration file for print correction by document |
---|
284 | our $DOCSFILE = '/etc/afp2print/documents.conf' ; |
---|
285 | |
---|
286 | # DOCUMENTS_CORRECTION_ENABLED can be set to 1 to enable automatic by Documents |
---|
287 | # scaling and off-set correction. A flag by DestId can be used to enable/disable |
---|
288 | # the correction for a specific DestId. |
---|
289 | # When set greater than 1, the flag by DestId is ignored and correction is |
---|
290 | # forced and only if correction exists for a Document |
---|
291 | our $DOCUMENTS_CORRECTION_ENABLED = 0 ; |
---|
292 | |
---|
293 | # DONTZIPPDF must be set to '1' to keep PDF files not compressed in zip file |
---|
294 | # Only used if COMPRESSFILES is set to 1 |
---|
295 | our $DONTZIPPDF = 0 ; |
---|
296 | |
---|
297 | # DONT_PRINT is set to 1 to skip lpr command |
---|
298 | # FORCE_DESTID can be used as in validation, exemple set it to "LINDEC" in conf |
---|
299 | our $DONT_PRINT = 0 ; |
---|
300 | our $FORCE_DESTID = "" ; |
---|
301 | |
---|
302 | # AGREGATE_PRINT is set to 0 to force print immediatly and not agregate PCL5 to |
---|
303 | # only do one PCL5 by DESTID |
---|
304 | our $AGREGATE_PRINT = 1 ; |
---|
305 | |
---|
306 | # PARALLELE_VALIDATION: Set it to: |
---|
307 | # - 1 to duplicate AFP incoming flux to validation mode and destinations |
---|
308 | # - 2 to only use validation mode and destination printers |
---|
309 | our $PARALLELE_VALIDATION = 0 ; |
---|
310 | |
---|
311 | # the dvilj variant to run taken from dvihp script |
---|
312 | our $DVILJ = 'dvipcl5' ; |
---|
313 | |
---|
314 | # the zip option environment for optimizing compression |
---|
315 | our $ZIPOPTIONS = 'DjJqXm' ; |
---|
316 | our $MAXFILES_BY_ZIPCMD = 1 ; |
---|
317 | # COMPRESSFILES must be set to compression level desired for backup files in |
---|
318 | # DONESPOOL and ERRORSPOOL, value can be 0 to 9 (see 'zip' command man) |
---|
319 | our $COMPRESSFILES = 0 ; |
---|
320 | |
---|
321 | # PURGEFILES is set to 1 when we don't need to keep any file after processing |
---|
322 | our $PURGEFILES = 0 ; |
---|
323 | |
---|
324 | # MINFOLDERCOUNT is the minimum spool file number under which we will repopulate |
---|
325 | # the spool file cache |
---|
326 | our $MINFOLDERCOUNT = 10 ; |
---|
327 | # MAXFOLDERCOUNT is the maximum spool files to keep in our known file cache |
---|
328 | our $MAXFOLDERCOUNT = 100 ; |
---|
329 | # MAXRETRYTIMER is the time in ms to keep a cached available file |
---|
330 | # in memory before retrying to lock it |
---|
331 | our $MAXRETRYTIMER = 500 ; |
---|
332 | |
---|
333 | # CONV_STATUS_TIMING is the time in second after which a status conversion must |
---|
334 | # be provided to inform clients |
---|
335 | our $CONV_STATUS_TIMING = 30 ; |
---|
336 | |
---|
337 | # KEEP_AFPJOB is set to 1 when PARALLELE_VALIDATION is 0 if we want to keep AFP |
---|
338 | # version of each job. In that case, an AFPDS file is splitted in as many job |
---|
339 | # that it contains. This is the default if PARALLELE_VALIDATION is set to 1 or 2 |
---|
340 | our $KEEP_AFPJOB = 1 ; |
---|
341 | |
---|
342 | # Mailing variables for alerts and errors |
---|
343 | our $MAIL_BIN = "/usr/lib/sendmail" ; |
---|
344 | # ALERT_MAILS will receive a short mail with only job in ABTERM in the subject |
---|
345 | our $ALERT_MAILS = "" ; |
---|
346 | # ERROR_MAILS will receive a mail with knowns errors in the body |
---|
347 | our $ERROR_MAILS = "" ; |
---|
348 | |
---|
349 | # CLient time-out is the max time we can expect for a response from listener |
---|
350 | our $CLIENT_TIMEOUT = 300 ; |
---|
351 | |
---|
352 | # Some variable used for archivage processing |
---|
353 | our $ARCH_REMHOST_TEST = '127.0.0.1' ; |
---|
354 | our $ARCH_REMPORT_TEST = 2222 ; |
---|
355 | our $ARCH_REMHOST_TLOG = '127.0.0.1' ; |
---|
356 | our $ARCH_REMPORT_TLOG = 2222 ; |
---|
357 | our $ARCH_REMHOST_PROD = '127.0.0.1' ; |
---|
358 | our $ARCH_REMPORT_PROD = 2222 ; |
---|
359 | our $ARCH_DEBUG = 0 ; |
---|
360 | # ARCH_ENABLED: Can be set to from 0 to 99 |
---|
361 | # to get ARCH_ENABLED * BACKEND_FACTOR Archiver processes |
---|
362 | # ARCH_ENABLED: Set to greater than 99 to activate an archivage simulation: |
---|
363 | # - if = 100 than archivage call returns true each time |
---|
364 | # - else greater, it returns randomly false when random(value) > 99 |
---|
365 | # (so greater value produces more false case) |
---|
366 | our $ARCH_ENABLED = 2 ; |
---|
367 | # ARCH_SCENARIO: 1 = separate binary file, 3 = xml embedded |
---|
368 | our $ARCH_SCENARIO = 1 ; |
---|
369 | |
---|
370 | # ESERVICE designs Electronic Service it can only be activated with AFP flux |
---|
371 | # telling about RC 200,201,202 and replaces the ARCH step when enabled |
---|
372 | our $ESERVICE_ENABLED = 0 ; |
---|
373 | # ESERVICE_ENABLED: Can be set to from 0 to 99 |
---|
374 | # to get ESERVICE_ENABLED * BACKEND_FACTOR EService processes |
---|
375 | # ESERVICE_ENABLED: Set to greater than 99 to activate an e-service simulation: |
---|
376 | # - if = 100 than e-service call returns true each time |
---|
377 | # - else greater, it returns randomly false when random(value) > 99 |
---|
378 | # (so greater value produces more false case) |
---|
379 | our $ESERVICE_CONF = '/etc/afp2print/e-service.conf' ; |
---|
380 | |
---|
381 | # By default client request sockets are closed when processed |
---|
382 | our $CLOSE_CONNECTIONS = 1 ; |
---|
383 | |
---|
384 | # CONVERT_CONTENT_FILE must be true to convert RC201-RC202 content from EBCDIC |
---|
385 | our $CONVERT_CONTENT_FILE = 1 ; |
---|
386 | |
---|
387 | # DO_CONVERT is set or not to activate AFP conversion with from_to perl API |
---|
388 | our $DO_CONVERT = 1 ; |
---|
389 | # The following defines which encoding to use with from_to perl API |
---|
390 | our $FROM_CONVERT = 'cp1047' ; |
---|
391 | our $TO_CONVERT = 'latin1' ; |
---|
392 | |
---|
393 | # ENABLE_DTD_VALIDATION can be set to 0 or 1 to disable |
---|
394 | # or activate DTD validation on XML requests |
---|
395 | our $ENABLE_DTD_VALIDATION= 0 ; |
---|
396 | |
---|
397 | # ONLY_DO_PDF can be set to avoid the steps 4 to 10 only used with printing and |
---|
398 | # online archivage. This is used essentialy to only handle PDF generation and |
---|
399 | # get better performance in this case. |
---|
400 | our $ONLY_DO_PDF = 0 ; |
---|
401 | |
---|
402 | # DBI variables with default connection on local mysql serveur and db a2p |
---|
403 | our $DBI_DSN = 'DBI:mysql:database=a2p;host=localhost;port=3306' ; |
---|
404 | our $DBI_USER = '' ; # Set to Progname (a2p-stat,...) if not set |
---|
405 | our $DBI_PASSWD = '' ; # Connection should failed if not configured |
---|
406 | |
---|
407 | # Time to force reconnection to DB for a2p-stat and a2p-status services |
---|
408 | our $RECONNECT_TIMER = 3600 ; |
---|
409 | |
---|
410 | # A2PDB_PREFIX can be set if you need to install stats or/and status tables in |
---|
411 | # a database with conflicting table names |
---|
412 | our $A2PDB_TABLE_PREFIX = '' ; |
---|
413 | |
---|
414 | # Set maximum amount of values that can be cached in memory during DB usage |
---|
415 | our $MAX_CACHED_DB = 10000 ; |
---|
416 | # Set maximum lines to read by a2p-stat in each statistics file at each loop |
---|
417 | our $MAX_LINES = 100 ; |
---|
418 | |
---|
419 | # By default don't do DBA job by ourself |
---|
420 | our $DO_DB_OPTIMIZATION = 0 ; |
---|
421 | |
---|
422 | # STATSFILE_MAXAGE is only used by statistics service to delete statistics file |
---|
423 | # for which the age in DAYs is greater than this value |
---|
424 | our $STATSFILE_MAXAGE = 70 ; |
---|
425 | # Default value keeps at least 2 months of statistics files |
---|
426 | |
---|
427 | # STATUS_MAXAGE is used as peremption timer for status information in DBM files |
---|
428 | # By default it should be disabled, and only activated in a2p-status service |
---|
429 | # Only DONE status can be deleted automatically as it is redondant |
---|
430 | # with statistics informations. Unit is milli-second. |
---|
431 | our $STATUS_MAXAGE = 3600000 ; # Clean after one hour |
---|
432 | # But we are checking Progname later below and set it to 1h on *-status name |
---|
433 | our $STATUS_CACHE_MAXAGE = 60000 ; # 1 minute |
---|
434 | # Default value keeps 1 hour of status |
---|
435 | # MAX_CACHED_STATUS set the max number of status we can keep in cache. If this |
---|
436 | # maximum is reached, the older DONE status will be released |
---|
437 | our $MAX_CACHED_STATUS = 1000 ; |
---|
438 | # STATUS_DB_MAXAGE represents the max time to keep a status in jobs_status table |
---|
439 | our $STATUS_DB_MAXAGE = 24 ; # Time in hours |
---|
440 | |
---|
441 | # A boolean to enable/disable the AFPDS splitting code |
---|
442 | our $ENABLE_SPLITTER = 1 ; |
---|
443 | # A number of jobs on which use an auto-split |
---|
444 | our $AUTO_SPLIT_MAX = 100 ; |
---|
445 | |
---|
446 | # A value to force a2p to quit when this number of jobs has been processed |
---|
447 | our $JOBS_COUNTDOWN = 0 ; |
---|
448 | |
---|
449 | # STATS_COMMIT_SKIP is only used by statistics to skip some commit, when loading |
---|
450 | # statistics files to get better performance |
---|
451 | our $STATS_COMMIT_SKIP = 100 ; |
---|
452 | # But commit will be forced if none has been done since 10 seconds |
---|
453 | |
---|
454 | # GIFTOPCL is the command chain to use for GIF to PCL conversion |
---|
455 | # The first %d will be replaced by the width of the image to scale to |
---|
456 | # The second %d will be replaced by the resolution to be used for PCL format |
---|
457 | our $GIFTOPCL = 'giftopnm | pnmscalefixed -width=%d | ppmtopgm ' . |
---|
458 | '| pgmtopbm -d8 | pbmtolj -resolution %d -packbits -float -noreset' ; |
---|
459 | # Dont't use delta compression with pbmtolj as the result is wrong with texts |
---|
460 | |
---|
461 | # PNGCOMPRESSION could be from 0 for no compression to 9 for maximum compression |
---|
462 | # of included PNG resources in PDF generated files |
---|
463 | our $PNGCOMPRESSION = 9 ; |
---|
464 | |
---|
465 | # PCL_RESOLUTION is the default resolution to use for PCL resource conversion |
---|
466 | our $PCL_RESOLUTION = 600 ; |
---|
467 | |
---|
468 | # LOCKID is just an identifier to be able to run the service on the same spool |
---|
469 | our $LOCKID = &get_default_lockid() ; |
---|
470 | |
---|
471 | sub get_default_lockid { |
---|
472 | my $lockid = "a2p-service" ; |
---|
473 | if ( -e '/proc/sys/kernel/hostname' and ! $SERVICE ) { |
---|
474 | open *HOSTNAME , '<', "/proc/sys/kernel/hostname" |
---|
475 | or die "Can't read hostname from kernel: $!"; |
---|
476 | $lockid = <HOSTNAME> ; |
---|
477 | close HOSTNAME ; |
---|
478 | } else { |
---|
479 | $lockid = $SERVICE ? $ENV{'LOCKID'} : qx/hostname -s/ ; |
---|
480 | } |
---|
481 | chomp $lockid ; |
---|
482 | $lockid = $1 if ( $lockid =~ /^([^.]+)/ ); |
---|
483 | $lockid = uc( $lockid ); |
---|
484 | return $lockid ; |
---|
485 | } |
---|
486 | |
---|
487 | our $MUSTQUIT = 0 ; # Shared flagged to stop immediatly |
---|
488 | |
---|
489 | # Should we use \special command specific to dvipcl5 instead of |
---|
490 | # Integrating files containing PCL5 commands |
---|
491 | our $USE_PCLCMD = 1 ; |
---|
492 | |
---|
493 | ################################################################################ |
---|
494 | ## Optimized shared constants ## |
---|
495 | ################################################################################ |
---|
496 | # These common constants are arbitrary values |
---|
497 | sub QUIT () { 0xEFEF }; # Constant passed in request queues |
---|
498 | sub PING () { 0x0FF0 }; # Constant passed to ping a thread |
---|
499 | sub _INIT () { 0xF000 }; # Constant passed to update thread env |
---|
500 | sub _UPDATE () { 0xF001 }; # Constant passed to directly update shared var |
---|
501 | sub TODO () { 0x8888 }; # Constant passed to ask job to a thread |
---|
502 | sub DONE () { 0xFFF0 }; # Constant to say job is done |
---|
503 | sub NOMOREFILE () { 99 }; # Constant to say when no file are found in spool |
---|
504 | |
---|
505 | our %means = ( |
---|
506 | QUIT , "QUIT", |
---|
507 | PING , "PING", |
---|
508 | _INIT , "INIT", |
---|
509 | _UPDATE , "Direct UPDATE", |
---|
510 | TODO , "TODO", |
---|
511 | DONE , "DONE", |
---|
512 | NOMOREFILE , "NO MORE FILE" |
---|
513 | ); |
---|
514 | |
---|
515 | # Regex used in SpoolManager and Converter to compute AFPNAME |
---|
516 | our $AFPNAME_REGEX = |
---|
517 | qr/(?i:LINUX\.|TEMP\.)*([-0-9a-zA-Z_.]+)(?i:\.afp|\.afpds)?$/ ; |
---|
518 | |
---|
519 | ################################################################################ |
---|
520 | ## System shared values ## |
---|
521 | ################################################################################ |
---|
522 | # Prepare process short name, extracting basename without extension |
---|
523 | our $Progname ; |
---|
524 | if (!defined($Progname)) { |
---|
525 | ( $Progname ) = $ARGV[0] =~ m|.*/([^/.]+)(\.[^/.]+)?$| |
---|
526 | if (defined($ARGV[0])); |
---|
527 | ( $Progname ) = $0 =~ m|.*/([^/.]+)(\.[^/.]+)?$| |
---|
528 | unless (defined($Progname)); |
---|
529 | $Progname = "a2p" unless (defined($Progname)); |
---|
530 | } |
---|
531 | |
---|
532 | die "Can't starting process without Progname defined" |
---|
533 | unless (defined($Progname)); |
---|
534 | |
---|
535 | our $maintid = 0 ; |
---|
536 | our $do_file = 0 ; |
---|
537 | our %STATS = () ; |
---|
538 | our @AbortTime = () ; |
---|
539 | |
---|
540 | sub DOWNSTAT { |
---|
541 | my $what = shift ; |
---|
542 | my $down = @_ ? shift : 1 ; |
---|
543 | unless (defined($STATS{$what})) { $STATS{$what} = 0 } |
---|
544 | $STATS{$what} -= $down ; |
---|
545 | } |
---|
546 | |
---|
547 | sub UPSTAT { |
---|
548 | my $what = shift ; |
---|
549 | my $plus = @_ ? shift : 1 ; |
---|
550 | unless (defined($STATS{$what})) { $STATS{$what} = 0 } |
---|
551 | $STATS{$what} += $plus ; |
---|
552 | } |
---|
553 | |
---|
554 | my %chrono = () ; |
---|
555 | sub TIMESTAT { |
---|
556 | my @timing = &gettimeofday() ; |
---|
557 | my $what = 'TIMING-' . $_[0] ; |
---|
558 | if (defined($chrono{$what}) and @{$chrono{$what}}) { |
---|
559 | &MAXSTAT($what,( $timing[0] - ${$chrono{$what}}[0] ) * 1_000_000 |
---|
560 | + ( $timing[1] - ${$chrono{$what}}[1] )); |
---|
561 | $chrono{$what} = [] ; |
---|
562 | |
---|
563 | } else { |
---|
564 | $chrono{$what} = [ @timing ] ; |
---|
565 | } |
---|
566 | } |
---|
567 | |
---|
568 | sub MAXSTAT { |
---|
569 | my $max = $_[0] . '-MAX' ; |
---|
570 | $STATS{(!defined($STATS{$max}) or $_[1] > $STATS{$max}) ? $max : $_[0]} |
---|
571 | = $_[1] ; |
---|
572 | } |
---|
573 | |
---|
574 | sub MAXMINSTAT { |
---|
575 | my $min = $_[0] . '-MIN' ; |
---|
576 | $STATS{(!defined($STATS{$min}) or ! $STATS{$min} |
---|
577 | or ( $_[1] and $_[1] < $STATS{$min})) ? $min : $_[0]} = $_[1] |
---|
578 | if (&MAXSTAT(@_) == $_[1]); |
---|
579 | } |
---|
580 | |
---|
581 | # Update LOGFILENAME default |
---|
582 | $LOGFILENAME = $SHMDIR . '/' . $Progname . '.log' unless $LOGFILENAME ; |
---|
583 | |
---|
584 | our $LISTENER = $SERVICE_TMP . '/' . $Progname . '-listener' ; |
---|
585 | |
---|
586 | # This authorizes to get thread compilation errors when debugging |
---|
587 | our $StdoutFile = "/var/run/$Progname.debug" ; |
---|
588 | # But it should be really set to /dev/null for a service |
---|
589 | $StdoutFile = "/dev/null" if ( ! -e $StdoutFile ); |
---|
590 | |
---|
591 | # A2P_SYS_CONF has its defaults should come from a2p.sh script |
---|
592 | our $A2P_SYS_CONF = defined($ENV{'A2P_SYS_CONF'}) ? |
---|
593 | $ENV{'A2P_SYS_CONF'} : "/etc/afp2print/afpds2tex.conf" ; |
---|
594 | |
---|
595 | if ($SERVICE) { |
---|
596 | # Initialize Init module |
---|
597 | &Init( "$A2P_SYS_CONF" , "/etc/afp2print/" . $Progname . ".conf" ); |
---|
598 | |
---|
599 | my @FIRSTENV = &Init( map { $_ => eval $_ } @SHARED ); |
---|
600 | |
---|
601 | # Now we can evaluate our %ENV |
---|
602 | map { eval $_ } @FIRSTENV ; |
---|
603 | |
---|
604 | my $debugenv = 0 ; # Set to one to got ENV debugging while updating conf |
---|
605 | sub UpdateSharedEnv { |
---|
606 | # Compute shared variable |
---|
607 | map { |
---|
608 | my ( $key ) = $_ =~ /^[\$](.*)$/ ; |
---|
609 | if ($key and defined($ENV{$key})) { |
---|
610 | my $quote = $ENV{$key} =~ /^\d+$/ ? "\"\"" : "\"'\"" ; |
---|
611 | eval "$_ = \$ENV{$key}" ; |
---|
612 | } |
---|
613 | } @SHARED ; |
---|
614 | |
---|
615 | # Update some other ENV |
---|
616 | $ENV{TEXMFOUTPUT} = $SHMDIR if ( defined($SHMDIR) and -d $SHMDIR ); |
---|
617 | |
---|
618 | # Debug env if needed |
---|
619 | if ($debugenv) { |
---|
620 | my %HASH = %ENV ; |
---|
621 | $debugenv ++ while ( -e "/tmp/$Progname-ENV-$debugenv" ); |
---|
622 | open( *LOG, '>', "/tmp/$Progname-ENV-$debugenv" ) |
---|
623 | or return ; |
---|
624 | map { |
---|
625 | my ( $key ) = $_ =~ /^[\$](.*)$/ ; |
---|
626 | print LOG scalar(localtime), ", $0: $_ => ", |
---|
627 | defined($ENV{$key}) ? "ENV='$ENV{$key}'" : "ENV=undef", |
---|
628 | " vs '", eval $_ , "'\n" ; |
---|
629 | delete $HASH{$key}; |
---|
630 | } @SHARED ; |
---|
631 | map { |
---|
632 | print LOG scalar(localtime), ", $0: ENV $_ = $ENV{$_}\n" |
---|
633 | } keys( %HASH ); |
---|
634 | map { |
---|
635 | print LOG scalar(localtime), ", $0: FIRSTENV => $_ \n" |
---|
636 | } @FIRSTENV ; |
---|
637 | close(LOG); |
---|
638 | } |
---|
639 | } |
---|
640 | |
---|
641 | &UpdateSharedEnv ; |
---|
642 | } |
---|
643 | |
---|
644 | 1; |
---|