1 /** @file 2 3 Definitions for the LocalManager class. 4 5 @section license License 6 7 Licensed to the Apache Software Foundation (ASF) under one 8 or more contributor license agreements. See the NOTICE file 9 distributed with this work for additional information 10 regarding copyright ownership. The ASF licenses this file 11 to you under the Apache License, Version 2.0 (the 12 "License"); you may not use this file except in compliance 13 with the License. You may obtain a copy of the License at 14 15 http://www.apache.org/licenses/LICENSE-2.0 16 17 Unless required by applicable law or agreed to in writing, software 18 distributed under the License is distributed on an "AS IS" BASIS, 19 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 See the License for the specific language governing permissions and 21 limitations under the License. 22 */ 23 24 #pragma once 25 26 #include <string> 27 28 #include "BaseManager.h" 29 #include "records/I_RecHttp.h" 30 #include "tscore/I_Version.h" 31 32 #include <syslog.h> 33 #if TS_HAS_WCCP 34 #include <wccp/Wccp.h> 35 #endif 36 #if HAVE_EVENTFD 37 #include <sys/eventfd.h> 38 #endif 39 40 class Alarms; 41 class FileManager; 42 43 enum ManagementPendingOperation { 44 MGMT_PENDING_NONE, // Do nothing 45 MGMT_PENDING_RESTART, // Restart TS and TM 46 MGMT_PENDING_BOUNCE, // Restart TS 47 MGMT_PENDING_STOP, // Stop TS 48 MGMT_PENDING_DRAIN, // Drain TS 49 MGMT_PENDING_IDLE_RESTART, // Restart TS and TM when TS is idle 50 MGMT_PENDING_IDLE_BOUNCE, // Restart TS when TS is idle 51 MGMT_PENDING_IDLE_STOP, // Stop TS when TS is idle 52 MGMT_PENDING_IDLE_DRAIN, // Drain TS when TS is idle from new connections 53 MGMT_PENDING_UNDO_DRAIN, // Recover TS from drain 54 }; 55 56 class LocalManager : public BaseManager 57 { 58 public: 59 explicit LocalManager(bool proxy_on, bool listen); 60 ~LocalManager(); 61 62 void initAlarm(); 63 void initCCom(const AppVersionInfo &version, FileManager *files, int mcport, char *addr, int rsport); 64 void initMgmtProcessServer(); 65 void pollMgmtProcessServer(); 66 void handleMgmtMsgFromProcesses(MgmtMessageHdr *mh); 67 void sendMgmtMsgToProcesses(int msg_id, const char *data_str); 68 void sendMgmtMsgToProcesses(int msg_id, const char *data_raw, int data_len); 69 void sendMgmtMsgToProcesses(MgmtMessageHdr *mh); 70 71 void signalFileChange(const char *var_name); 72 void signalEvent(int msg_id, const char *data_str); 73 void signalEvent(int msg_id, const char *data_raw, int data_len); 74 void signalAlarm(int alarm_id, const char *desc = nullptr, const char *ip = nullptr); 75 76 void processEventQueue(); 77 bool startProxy(const char *onetime_options); 78 void listenForProxy(); 79 void bindUdpProxyPort(HttpProxyPort &); 80 void bindTcpProxyPort(HttpProxyPort &); 81 void closeProxyPorts(); 82 83 void mgmtCleanup(); 84 void mgmtShutdown(); 85 void processShutdown(bool mainThread = false); 86 void processRestart(); 87 void processBounce(); 88 void processDrain(int to_drain = 1); 89 void rollLogFiles(); 90 void clearStats(const char *name = nullptr); 91 void hostStatusSetDown(const char *marshalled_req, int len); 92 void hostStatusSetUp(const char *marshalled_req, int len); 93 94 bool processRunning(); 95 96 bool run_proxy; 97 bool listen_for_proxy; 98 bool proxy_recoverable = true; // false if traffic_server cannot recover with a reboot 99 time_t manager_started_at; 100 time_t proxy_started_at = -1; 101 int proxy_launch_count = 0; 102 bool proxy_launch_outstanding = false; 103 ManagementPendingOperation mgmt_shutdown_outstanding = MGMT_PENDING_NONE; 104 time_t mgmt_shutdown_triggered_at; 105 time_t mgmt_drain_triggered_at; 106 int proxy_running = 0; 107 HttpProxyPort::Group m_proxy_ports; 108 // Local inbound addresses to bind, if set. 109 IpAddr m_inbound_ip4; 110 IpAddr m_inbound_ip6; 111 112 int process_server_timeout_secs; 113 int process_server_timeout_msecs; 114 115 char *absolute_proxy_binary; 116 char *proxy_name; 117 char *proxy_binary; 118 std::string proxy_options; // These options should persist across proxy reboots 119 char *env_prep; 120 121 int process_server_sockfd = ts::NO_FD; 122 int watched_process_fd = ts::NO_FD; 123 #if HAVE_EVENTFD 124 int wakeup_fd = ts::NO_FD; // external trigger to stop polling 125 #endif 126 pid_t proxy_launch_pid = -1; 127 128 Alarms *alarm_keeper = nullptr; 129 FileManager *configFiles = nullptr; 130 131 pid_t watched_process_pid = -1; 132 133 int syslog_facility = LOG_DAEMON; 134 135 #if TS_HAS_WCCP 136 wccp::Cache wccp_cache; 137 #endif 138 private: 139 }; /* End class LocalManager */ 140 141 extern LocalManager *lmgmt; 142