123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- /*
- * Copyright (C) 2019 Weber Yann
- *
- * This file is part of PyFCGI.
- *
- * PyFCGI is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * any later version.
- *
- * PyFCGI is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with PyFCGI. If not, see <http://www.gnu.org/licenses/>.
- */
- #ifndef __CONF_H___
- #define __CONF_H___
-
- #include <unistd.h>
- #include <getopt.h>
-
- #include "config.h"
- /**@defgroup conf_internal PYFCGI configuration handling
- */
- /**@defgroup conf_glob PYFCGI global (for all process) configurations
- * @see struct_pyfcgi_conf_s
- * @ingroup conf_internal */
-
- #include "logger.h"
-
- /**@defgroup ret_status Function & process return status
- */
- #define PYFCGI_ERR 16
- /**@ingroup ret_status */
- #define PYFCGI_WORKER_FAIL 32
- /**@ingroup ret_status */
- #define PYFCGI_MASTER_FAIL 64
- /**@ingroup ret_status */
- #define PYFCGI_FATAL 128
-
- #define PYFCGI_NAME "spawn-fcgi [OPTIONS] -- pyfcgi"
-
- #define PYFCGI_SHORT_OPT "Ce:E:w:W:m:l:Svh"
-
- #define PYFCGI_LONG_OPT { \
- {"config", required_argument, 0, 'C'},\
- {"pymodule", required_argument, 0, 'e'},\
- {"pyapp", required_argument, 0, 'E'},\
- {"min-worker", required_argument, 0, 'w'},\
- {"max-worker", required_argument, 0, 'W'},\
- {"max-request", required_argument, 0, 'm'},\
- {"log", required_argument, 0, 'L'},\
- {"syslog", no_argument, 0, 'S'},\
- {"pid-file", required_argument, 0, 'P'},\
- {"version", no_argument, 0, 'v'},\
- {"help", no_argument, 0, 'h' },\
- {0, 0, 0, 0}\
- }
-
- #define PYFCGI_OPT_HELP {\
- {"Load options from configuration file", "CONFIG"},\
- {"Search application function in given python module", "MODULE_NAME"},\
- {"Python application entrypoint function name", "FUNC_NAME"},\
- {"Minimum worker in the pool", "INT"},\
- {"Maximum worker in the pool", "INT"},\
- {"Request count after wich the worker is restarted (if 0 never restart)", "INT"},\
- {"Add a logfile using syntax : 'LOGFILE[;FILT][;FMT]'", "LOGGER_SPEC"},\
- {"Use syslog for logging", NULL},\
- {"Create a PID file", "FILENAME"},\
- {"Print PyFCGI and Python version and exit", NULL},\
- {"Display this help and exit", NULL},\
- }
-
- #define PYFCGI_HELP_TEXT "Logger specification format 'LOGFILE[;FILT][;FMT]' with :\n\
- \t- LOGFILE the log file name\n\
- \t- FILT a number (in decimal or hexadicimal 0xXX) indicating wich\n\
- \t facility/level to log\n\
- \t- FMT the logline format in a special markup format using fields between { }\n\
- \t supported fields are :\n\
- \t\t- {datetime} {datetime:SIZE} {datetime:SIZE:FMT} defines a format and a \n\
- \t\t constant length for a datetime field. Default : {datetime:25:%F %T%z}\n\
- \t\t- {level} the loglevel \n\
- \t\t- {facility} the log facility\n\
- \t\t- {pid} the process PID\n\
- \t\t- {ident} the defined ident (set by process)\n\
- \t\t- {msg} the log message (can only appear once)\n\
- You can escape { and } by using {{ and }} and all field names can by\n\
- abbreviated to one character.\n"
-
- #define PYENTRY_DEFAULT_FUN "application"
-
- /**@brief Friendly name for @ref struct pyfcgi_conf_s
- * @see struct pyfcgi_conf_s */
- typedef struct pyfcgi_conf_s pyfcgi_conf_t;
- typedef struct pyfcgi_conf_logger_s pyfcgi_conf_logger_t;
- typedef struct pyfcgi_context_s pyfcgi_context_t;
-
- struct pyfcgi_context_s {
- pid_t pid;
- pid_t ppid;
- char *pidfile;
- };
-
- /**@brief Structure containing configuration
- * @ingroup conf_internal
- * The structure is used for the global @ref pyfcgi_conf variable.
- * @see pyfcgi_conf_t
- */
- struct pyfcgi_conf_s
- {
- /**@brief Entrypoint module name
- * @ingroup conf_glob */
- char *py_entrymod;
- /**@brief Entrypoint function name
- * @ingroup conf_glob */
- char *py_entryfun;
- /**@brief Minimum count worker in pool
- * @ingroup conf_glob */
- int min_wrk;
- /**@brief Maximum count workers in pool
- * @ingroup conf_glob */
- int max_wrk;
- /**@brief Maximum request before a worker restarts (0 for no restart)
- * @ingroup conf_glob */
- int max_reqs;
-
- /**@brief Logger configuration
- * @ingroupe conf_glob */
- pyfcgi_conf_logger_t logs;
-
- /**@brief Context informations */
- pyfcgi_context_t context;
- };
-
-
- /**@brief Configuration globals, inherited from parent to childs */
- pyfcgi_conf_t PyFCGI_conf;
-
- /**@brief Print usage on FD 2 (stdout) */
- void usage();
-
- /**@brief Print pyfcgi & python version on given fd */
- void print_version(int);
-
- /**@brief Init conf with default values */
- void default_conf();
-
- /**@brief Parse arguments and store them in conf
- * @return 0 if no error */
- int parse_args(int argc, char *argv[]);
-
- int parse_optlog(const char*);
-
- #endif
|