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