Tests about a simple python3 fastcgi runner using libfcgi and the Python-C API.
python
c
wsgi
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

monitor.h 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright (C) 2019 Weber Yann
  3. *
  4. * This file is part of PyFCGI.
  5. *
  6. * PyFCGI is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * any later version.
  10. *
  11. * PyFCGI 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 Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with PyFCGI. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**@defgroup monitoring Monitoring a running PyFCGI
  20. *
  21. * PyFCGI have the ability to listen on a UDP socket, replying to simple
  22. * queries (or simple stats).
  23. */
  24. #ifndef _MONITOR__H___
  25. #define _MONITOR__H___
  26. #include "config.h"
  27. #include <fcgiapp.h> /* fcgi library; put it first*/
  28. #include <netdb.h>
  29. #include <strings.h>
  30. #include <sys/socket.h>
  31. #include <sys/un.h>
  32. #include <netinet/in.h>
  33. #include <arpa/inet.h>
  34. #define UNIX_SOCKPATH_MAX 108
  35. #define PYFCGI_MONITOR_STREAM_BACKLOG 5
  36. typedef struct pyfcgi_monitor_s pyfcgi_monitor_t;
  37. typedef union pyfcgi_monitor_addr_u pyfcgi_monitor_addr_t;
  38. #include "conf.h"
  39. #include "logger.h"
  40. #include "stats.h"
  41. union pyfcgi_monitor_addr_u
  42. {
  43. struct sockaddr_in in;
  44. struct sockaddr_in6 in6;
  45. struct sockaddr_un un;
  46. };
  47. struct pyfcgi_monitor_s
  48. {
  49. int sockserv;
  50. int sockargs[3];
  51. pyfcgi_monitor_addr_t addr;
  52. };
  53. /**@brief Attempt to init unitialized IPC component
  54. *
  55. * If an error occured it will be logged, and the init should be retry latter.
  56. *
  57. * @note the monitor process uses IPC_WREQS to count requests IPC_SEMST for
  58. * SHM syn and IPC_SHMST for SHM initalization
  59. */
  60. int pyfcgi_monitor_IPC_init();
  61. /**@brief Start the stats server monitoring server
  62. * @return PID of the child process and -1 on error
  63. * @note When called the configuration has to be parsed */
  64. pid_t pyfcgi_spawn_monitor();
  65. /**@brief Main function for socket stats server
  66. *
  67. * Create the socket & bind to indicated address. If bind fails, sleep 30s, then
  68. * exit, in order to retry the whole process
  69. */
  70. void pyfcgi_monitor_loop();
  71. void pyfcgi_monitor_stream_loop();
  72. void pyfcgi_monitor_dgram_loop();
  73. /**@brief Check socket URL validity
  74. * @param const char* the URL to check
  75. * @return -1 if error else 0
  76. * @note Logs error using dprintf(2, ...) because this function will
  77. * be called when checking configuration
  78. */
  79. int pyfcgi_monitor_check_sock(const char*);
  80. /**@brief Parse stored socket URL
  81. * @param const char* the URL to parse
  82. * @param int[3] socket creation arguments
  83. * @param pyfcgi_monitor_addr_t the addr to bind to
  84. * @return 0 if no error else -1
  85. * @todo add support for xxx://[IPV6]:port
  86. */
  87. int pyfcgi_monitor_parse_sock(const char*, int[3], pyfcgi_monitor_addr_t*);
  88. /**@brief Parse an addres:port string in a sockaddr_in
  89. * @param const char* the hostname:port string
  90. * @param int socket family
  91. * @param pyfcgi_monitor_addr_t* the addr pointer
  92. * @param int* if not NULL will be set to choosen domain
  93. * @return 0 if no erro else -1
  94. * @todo add support for xxx://[IPV6]:port
  95. */
  96. int pyfcgi_monitor_parse_inet_addr(const char*, int, pyfcgi_monitor_addr_t*,
  97. int*);
  98. void pyfcgi_monitor_sighandler(int signum);
  99. #endif