Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Client Process Monitor Server
0003  *
0004  * @file cpmsrv.h
0005  */
0006 /* -----------------------------------------------------------------------------
0007  * Enduro/X Middleware Platform for Distributed Transaction Processing
0008  * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved.
0009  * Copyright (C) 2017-2023, Mavimax, Ltd. All Rights Reserved.
0010  * This software is released under one of the following licenses:
0011  * AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
0012  * See LICENSE file for full text.
0013  * -----------------------------------------------------------------------------
0014  * AGPL license:
0015  *
0016  * This program is free software; you can redistribute it and/or modify it under
0017  * the terms of the GNU Affero General Public License, version 3 as published
0018  * by the Free Software Foundation;
0019  *
0020  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
0021  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0022  * PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3
0023  * for more details.
0024  *
0025  * You should have received a copy of the GNU Affero General Public License along 
0026  * with this program; if not, write to the Free Software Foundation, Inc.,
0027  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0028  *
0029  * -----------------------------------------------------------------------------
0030  * A commercial use license is available from Mavimax, Ltd
0031  * contact@mavimax.com
0032  * -----------------------------------------------------------------------------
0033  */
0034 
0035 #ifndef CPMSRV_H
0036 #define CPMSRV_H
0037 
0038 #ifdef  __cplusplus
0039 extern "C" {
0040 #endif
0041 
0042 /*---------------------------Includes-----------------------------------*/
0043 #include <exhash.h>
0044 #include <nstopwatch.h>
0045 #include <ndrstandard.h>
0046 #include <cpm.h>
0047 #include <cconfig.h>
0048 #include <exenv.h>
0049 #include <libndrxconf.h>
0050 /*---------------------------Externs------------------------------------*/
0051 /*---------------------------Macros-------------------------------------*/
0052 
0053 /* Process flags */
0054     
0055 #define CPM_F_AUTO_START         0x00000001     /**< bit for auto start                      */
0056 #define CPM_F_EXTENSIVE_CHECK    0x00000002     /**< do extensive checks for process existance */
0057 #define CPM_F_KILL_LEVEL_LOW     0x00000004     /**< Kill children at -9                      */
0058 #define CPM_F_KILL_LEVEL_HIGH    0x00000008     /**< Kill children at normal shutdown         */
0059     
0060 #define CPM_F_KILL_LEVEL_DEFAULT 0              /**< default kill level                       */
0061     
0062 #define NDRX_CLTTAG                 "NDRX_CLTTAG" /**< Tag format string         */
0063 #define NDRX_CLTSUBSECT             "NDRX_CLTSUBSECT" /**< Subsect format string */
0064 
0065 
0066 #define CLT_WILDCARD                '%'         /**< regexp -> .* */
0067     
0068 #define CLT_STATE_NOTRUN            0   /**< Not running                  */
0069 #define CLT_STATE_STARTING          1   /**< Starting...                  */
0070 #define CLT_STATE_STARTED           2   /**< Started                      */
0071 #define CLT_STATE_WAIT              3   /**< Waiting on group lock        */
0072     
0073 #define CLT_CHK_INTERVAL_DEFAULT    15  /**< Do the checks every 15 sec   */
0074 #define CLT_KILL_INTERVAL_DEFAULT    30  /**< Default kill interval       */
0075     
0076 /* Individual shutdown: */
0077 #define CLT_STEP_INTERVAL           10000 /**<  microseconds for usleep */
0078 #define CLT_STEP_SECOND             CLT_STEP_INTERVAL / 1000000.0f /**< part of second */
0079     
0080 /* Global shutdown: */
0081 #define CLT_STEP_INTERVAL_ALL       300000 /**< microseconds for usleep */
0082 #define CLT_STEP_SECOND_ALL         CLT_STEP_INTERVAL / 1000000.0f /**< part of second */
0083 /*---------------------------Enums--------------------------------------*/
0084 /*---------------------------Typedefs-----------------------------------*/
0085     
0086     
0087 /**
0088  * Configuration info
0089  */
0090 struct cpm_static_info
0091 {
0092     /* Static info: */
0093     char command_line[PATH_MAX+1+CPM_TAG_LEN+CPM_SUBSECT_LEN];
0094     char procname[NDRX_CPM_CMDMIN+1];   /**< process name               */
0095     char log_stdout[PATH_MAX+1];
0096     char log_stderr[PATH_MAX+1];
0097     char wd[PATH_MAX+1];                /**< Working dir                */
0098     char env[PATH_MAX+1];
0099     char cctag[NDRX_CCTAG_MAX+1];
0100     long flags;              /**< flags of the process */
0101     
0102     long rssmax;              /**< resident memory max, -1 no chk       */
0103     long vszmax;              /**< virtual memory max, -1 no chk        */
0104     
0105     long subsectfrom;         /**< sub-section from                     */
0106     long subsectto;           /**< sub-section to                       */
0107     int procgrp_no;           /**< Process group number                 */
0108     
0109     /** list of process specific environment variables */
0110     ndrx_env_list_t *envs;
0111 };
0112 typedef struct cpm_static_info cpm_static_info_t;
0113 
0114 
0115 /**
0116  * Runtime info, pids, statuses, times.
0117  */
0118 struct cpm_dynamic_info
0119 {
0120     /* Dynamic info: */
0121     pid_t pid;              /**< pid of the process             */
0122     int exit_status;        /**< Exit status...                 */
0123     int consecutive_fail;   /**< Number of consecutive fails    */    
0124     int req_state;          /**< requested state                */
0125     int cur_state;          /**< current state                  */
0126     int was_started;        /**< Was process started?           */
0127     
0128     /* TODO: well we could do the PID tests only after slight delay due
0129      * to our signal thread is working, es extra safety net...?
0130      */
0131     int shm_read;           /**< Process was attached from shm  */
0132     time_t stattime;        /**< Status change time             */
0133 };
0134 typedef struct cpm_dynamic_info cpm_dynamic_info_t;
0135 
0136 /**
0137  * Definition of client processes (full command line & all settings)
0138  */
0139 struct cpm_process
0140 {   
0141     char key[CPM_KEY_LEN+1]; /**< tag<FS>subsect */
0142     
0143     char tag[CPM_TAG_LEN+1];
0144     char subsect[CPM_SUBSECT_LEN+1];
0145     
0146     cpm_static_info_t stat;
0147     cpm_dynamic_info_t dyn;
0148     int is_cfg_refresh; /**< Is config refreshed? */
0149 
0150     EX_hash_handle hh;         /**< makes this structure hashable */
0151 };
0152 typedef struct cpm_process cpm_process_t;
0153 
0154 
0155 /**
0156  * Definition of client processes (full command line & all settings)
0157  */
0158 struct cpmsrv_config
0159 {
0160     char *config_file;
0161     short chk_interval; /**< Interval for process checking... */
0162     short kill_interval; /**< Signaling interval */
0163 };
0164 typedef struct cpmsrv_config cpmsrv_config_t;
0165 
0166 /*---------------------------Globals------------------------------------*/
0167 extern cpmsrv_config_t G_config;
0168 extern cpm_process_t *G_clt_config;
0169 extern ndrx_procgroups_t *ndrx_G_procgroups_config;
0170 /*---------------------------Statics------------------------------------*/
0171 /*---------------------------Prototypes---------------------------------*/
0172 extern int load_config(void);
0173 extern cpm_process_t * cpm_get_client_by_pid(pid_t pid);
0174 extern cpm_process_t * cpm_client_get(char *tag, char *subsect);
0175 
0176 extern int cpm_sigchld_init(void);
0177 extern void cpm_sigchld_uninit(void);
0178 
0179 extern void cpm_pidtest(cpm_process_t *c, int *sg_groups);
0180 extern int cpm_kill(cpm_process_t *c);
0181 extern int cpm_killall(void);
0182 extern cpm_process_t * cpm_start_all(void);
0183 extern int cpm_exec(cpm_process_t *c);
0184 extern void cpm_set_cur_time(cpm_process_t *p_cltproc);
0185 extern int ndrx_load_new_env(char *file);
0186 
0187 extern void cpm_cfg_lock(void);
0188 extern void cpm_cfg_unlock(void);
0189 
0190 extern void cpm_lock_config(void);
0191 extern void cpm_unlock_config(void);
0192 
0193 extern int ndrx_cpm_sync_from_shm(void);
0194 
0195 #ifdef  __cplusplus
0196 }
0197 #endif
0198 
0199 #endif  /* CPMSRV_H */
0200 
0201 /* vim: set ts=4 sw=4 et smartindent: */