]> git.ipfire.org Git - thirdparty/squid.git/blob - src/mgr/BasicActions.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / mgr / BasicActions.cc
1 /*
2 * DEBUG: section 16 Cache Manager API
3 *
4 */
5
6 #include "squid.h"
7 #include "base/TextException.h"
8 #include "CacheManager.h"
9 #include "mgr/ActionCreator.h"
10 #include "mgr/ActionProfile.h"
11 #include "mgr/BasicActions.h"
12 #include "mgr/Registration.h"
13 #include "protos.h"
14 #include "SquidConfig.h"
15 #include "Store.h"
16
17 Mgr::IndexAction::Pointer
18 Mgr::IndexAction::Create(const Command::Pointer &cmd)
19 {
20 return new IndexAction(cmd);
21 }
22
23 Mgr::IndexAction::IndexAction(const Command::Pointer &aCmd): Action(aCmd)
24 {
25 debugs(16, 5, HERE);
26 }
27
28 void
29 Mgr::IndexAction::dump(StoreEntry* entry)
30 {
31 debugs(16, 5, HERE);
32 }
33
34 Mgr::MenuAction::Pointer
35 Mgr::MenuAction::Create(const Command::Pointer &cmd)
36 {
37 return new MenuAction(cmd);
38 }
39
40 Mgr::MenuAction::MenuAction(const Command::Pointer &aCmd): Action(aCmd)
41 {
42 debugs(16, 5, HERE);
43 }
44
45 void
46 Mgr::MenuAction::dump(StoreEntry* entry)
47 {
48 debugs(16, 5, HERE);
49 Must(entry != NULL);
50
51 typedef CacheManager::Menu::const_iterator Iterator;
52 const CacheManager::Menu& menu = CacheManager::GetInstance()->menu();
53
54 for (Iterator a = menu.begin(); a != menu.end(); ++a) {
55 storeAppendPrintf(entry, " %-22s\t%-32s\t%s\n",
56 (*a)->name, (*a)->desc,
57 CacheManager::GetInstance()->ActionProtection(*a));
58 }
59 }
60
61 Mgr::ShutdownAction::Pointer
62 Mgr::ShutdownAction::Create(const Command::Pointer &cmd)
63 {
64 return new ShutdownAction(cmd);
65 }
66
67 Mgr::ShutdownAction::ShutdownAction(const Command::Pointer &aCmd): Action(aCmd)
68 {
69 debugs(16, 5, HERE);
70 }
71
72 void
73 Mgr::ShutdownAction::dump(StoreEntry* entry)
74 {
75 debugs(16, DBG_CRITICAL, "Shutdown by Cache Manager command.");
76 shut_down(SIGTERM);
77 }
78
79 Mgr::ReconfigureAction::Pointer
80 Mgr::ReconfigureAction::Create(const Command::Pointer &cmd)
81 {
82 return new ReconfigureAction(cmd);
83 }
84
85 Mgr::ReconfigureAction::ReconfigureAction(const Command::Pointer &aCmd):
86 Action(aCmd)
87 {
88 debugs(16, 5, HERE);
89 }
90
91 void
92 Mgr::ReconfigureAction::dump(StoreEntry* entry)
93 {
94 debugs(16, DBG_IMPORTANT, "Reconfigure by Cache Manager command.");
95 storeAppendPrintf(entry, "Reconfiguring Squid Process ....");
96 reconfigure(SIGHUP);
97 }
98
99 Mgr::RotateAction::Pointer
100 Mgr::RotateAction::Create(const Command::Pointer &cmd)
101 {
102 return new RotateAction(cmd);
103 }
104
105 Mgr::RotateAction::RotateAction(const Command::Pointer &aCmd): Action(aCmd)
106 {
107 debugs(16, 5, HERE);
108 }
109
110 void
111 Mgr::RotateAction::dump(StoreEntry* entry)
112 {
113 debugs(16, DBG_IMPORTANT, "Rotate Logs by Cache Manager command.");
114 storeAppendPrintf(entry, "Rotating Squid Process Logs ....");
115 #if defined(_SQUID_LINUX_THREADS_)
116 rotate_logs(SIGQUIT);
117 #else
118 rotate_logs(SIGUSR1);
119 #endif
120 }
121
122 Mgr::OfflineToggleAction::Pointer
123 Mgr::OfflineToggleAction::Create(const Command::Pointer &cmd)
124 {
125 return new OfflineToggleAction(cmd);
126 }
127
128 Mgr::OfflineToggleAction::OfflineToggleAction(const Command::Pointer &aCmd):
129 Action(aCmd)
130 {
131 debugs(16, 5, HERE);
132 }
133
134 void
135 Mgr::OfflineToggleAction::dump(StoreEntry* entry)
136 {
137 Config.onoff.offline = !Config.onoff.offline;
138 debugs(16, DBG_IMPORTANT, "offline_mode now " << (Config.onoff.offline ? "ON" : "OFF") << " by Cache Manager request.");
139
140 storeAppendPrintf(entry, "offline_mode is now %s\n",
141 Config.onoff.offline ? "ON" : "OFF");
142 }
143
144 void
145 Mgr::RegisterBasics()
146 {
147 RegisterAction("index", "Cache Manager Interface", &Mgr::IndexAction::Create, 0, 1);
148 RegisterAction("menu", "Cache Manager Menu", &Mgr::MenuAction::Create, 0, 1);
149 RegisterAction("offline_toggle", "Toggle offline_mode setting", &Mgr::OfflineToggleAction::Create, 1, 1);
150 RegisterAction("shutdown", "Shut Down the Squid Process", &Mgr::ShutdownAction::Create, 1, 1);
151 RegisterAction("reconfigure", "Reconfigure Squid", &Mgr::ReconfigureAction::Create, 1, 1);
152 RegisterAction("rotate", "Rotate Squid Logs", &Mgr::RotateAction::Create, 1, 1);
153 }