1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
|
// **********************************************************************
//
// Copyright (c) 2001
// Mutable Realms, Inc.
// Huntsville, AL, USA
//
// All Rights Reserved
//
// **********************************************************************
#include <Freeze/Application.h>
#include <IcePack/LocatorI.h>
#include <IcePack/LocatorRegistryI.h>
#include <IcePack/ServerManagerI.h>
#include <IcePack/AdapterManagerI.h>
#include <IcePack/AdminI.h>
#ifndef _WIN32
# include <IcePack/ActivatorI.h>
# include <signal.h>
# include <sys/wait.h>
#endif
#include <util/PlatformUtils.hpp>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
using namespace std;
using namespace Ice;
using namespace Freeze;
using namespace IcePack;
class Server : public Freeze::Application
{
public:
Server(const string& dbEnvName) :
Freeze::Application(dbEnvName)
{
}
void usage();
virtual int runFreeze(int argc, char* argv[], const DBEnvironmentPtr&);
};
#ifndef _WIN32
static void
childHandler(int)
{
wait(0);
}
#endif
int
main(int argc, char* argv[])
{
#ifndef _WIN32
//
// This application forks, so we need a signal handler for child
// termination.
//
struct sigaction action;
action.sa_handler = childHandler;
sigemptyset(&action.sa_mask);
sigaddset(&action.sa_mask, SIGCHLD);
action.sa_flags = 0;
sigaction(SIGCHLD, &action, 0);
#endif
try
{
XMLPlatformUtils::Initialize();
}
catch(const XMLException& e)
{
cout << e.getMessage() << endl;
return EXIT_FAILURE;
}
PropertiesPtr defaultProperties;
try
{
defaultProperties = getDefaultProperties(argc, argv);
StringSeq args = argsToStringSeq(argc, argv);
args = defaultProperties->parseCommandLineOptions("IcePack", args);
stringSeqToArgs(args, argc, argv);
}
catch(const SystemException& ex)
{
cerr << argv[0] << ": " << ex << endl;
return EXIT_FAILURE;
}
//
// Check that IcePack.Data property is set and creates
// subdirectories db and servers if they don't already exist.
//
string dataPath = defaultProperties->getProperty("IcePack.Data");
if(dataPath.empty())
{
cerr << argv[0] << ": property `IcePack.Data' is not set" << endl;
return EXIT_FAILURE;
}
if(dataPath[dataPath.length() - 1] != '/')
{
dataPath += "/";
}
string dbPath = dataPath + "db";
string serversPath = dataPath + "servers";
struct stat filestat;
if(stat(dataPath.c_str(), &filestat) == 0 && S_ISDIR(filestat.st_mode))
{
if(stat(dbPath.c_str(), &filestat) != 0)
{
mkdir(dbPath.c_str(), 0755);
}
if(stat(serversPath.c_str(), &filestat) != 0)
{
mkdir(serversPath.c_str(), 0755);
}
}
else
{
cerr << argv[0] << ": `IcePack.Data' doesn't contain a valid directory path." << endl;
return EXIT_FAILURE;
}
::Server app(dbPath);
int rc = app.main(argc, argv);
XMLPlatformUtils::Terminate();
return rc;
}
void
::Server::usage()
{
cerr << "Usage: " << appName() << " [options]\n";
cerr <<
"Options:\n"
"-h, --help Show this message.\n"
"-v, --version Display the Ice version.\n"
"--nowarn Don't print any security warnings.\n"
;
}
int
::Server::runFreeze(int argc, char* argv[], const DBEnvironmentPtr& dbEnv)
{
PropertiesPtr properties = communicator()->getProperties();
StringSeq args = argsToStringSeq(argc, argv);
args = properties->parseCommandLineOptions("IcePack", args);
args = properties->parseCommandLineOptions("Freeze", args);
stringSeqToArgs(args, argc, argv);
bool nowarn = false;
for(int i = 1; i < argc; ++i)
{
if(strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0)
{
usage();
return EXIT_SUCCESS;
}
else if(strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0)
{
cout << ICE_STRING_VERSION << endl;
return EXIT_SUCCESS;
}
else if(strcmp(argv[i], "--nowarn") == 0)
{
nowarn = true;
}
else
{
cerr << appName() << ": unknown option `" << argv[i] << "'" << endl;
usage();
return EXIT_FAILURE;
}
}
string locatorEndpoints = properties->getProperty("IcePack.Locator.Endpoints");
if(locatorEndpoints.empty())
{
cerr << appName() << ": property `IcePack.Locator.Endpoints' is not set" << endl;
return EXIT_FAILURE;
}
string locatorRegistryEndpoints = properties->getProperty("IcePack.LocatorRegistry.Endpoints");
if(locatorRegistryEndpoints.empty())
{
cerr << appName() << ": property `IcePack.LocatorRegistry.Endpoints' is not set" << endl;
return EXIT_FAILURE;
}
string adminEndpoints = properties->getProperty("IcePack.Admin.Endpoints");
if(!adminEndpoints.empty())
{
if(!nowarn)
{
cerr << appName() << ": warning: administrative endpoints `IcePack.Admin.Endpoints' enabled" << endl;
}
}
string locatorId = properties->getPropertyWithDefault("IcePack.Locator.Identity", "IcePack/locator");
string locatorRegistryId = properties->getPropertyWithDefault("IcePack.LocatorRegistry.Identity",
"IcePack/locatorregistry");
string adminId = properties->getPropertyWithDefault("IcePack.Admin.Identity", "IcePack/admin");
communicator()->getProperties()->setProperty("Ice.Default.Locator", locatorId + ":" + locatorEndpoints);
//
// An internal object adapter for internal objects which are not
// exposed to the outside world. They might be at one point.
//
ObjectAdapterPtr internalAdapter = communicator()->createObjectAdapterWithEndpoints("IcePack.Internal", "");
internalAdapter->setLocator(0);
//
// Creates and register the adapter manager.
//
AdapterManagerPtr adapterManager = new AdapterManagerI(internalAdapter, dbEnv);
AdapterManagerPrx adapterManagerProxy =
AdapterManagerPrx::uncheckedCast(internalAdapter->add(adapterManager,
stringToIdentity("IcePack/adaptermanager")));
//
// Activator and server manager are not supported on Windows yet.
//
ServerManagerPrx serverManagerProxy;
#ifndef _WIN32
ActivatorIPtr activator = new ActivatorI(communicator());
activator->start();
ActivatorPrx activatorProxy = ActivatorPrx::uncheckedCast(internalAdapter->add(activator,
stringToIdentity("IcePack/activator")));
ServerManagerPtr serverManager = new ServerManagerI(internalAdapter, dbEnv, adapterManagerProxy, activatorProxy);
serverManagerProxy =
ServerManagerPrx::uncheckedCast(internalAdapter->add(serverManager,
stringToIdentity("IcePack/servermanager")));
internalAdapter->activate();
#endif
//
// Create the "IcePack.Admin" object adapter and register the
// admin object. The admin object is used by icepackadmin to
// administrate IcePack.
//
ObjectAdapterPtr adminAdapter = communicator()->createObjectAdapterWithEndpoints("IcePack.Admin", adminEndpoints);
AdminPtr admin = new AdminI(communicator(), serverManagerProxy, adapterManagerProxy);
adminAdapter->add(admin, stringToIdentity(adminId));
//
// Create the "IcePack.LocatorRegistry" object adapter and
// registry the locator registry object.
//
// The locator registry object provides an implementation of the
// Ice::LocatorRegistry interface. This interface is used by Ice
// servers to register their object adapters.
//
ObjectAdapterPtr locatorRegistryAdapter =
communicator()->createObjectAdapterWithEndpoints("IcePack.LocatorRegistry", locatorRegistryEndpoints);
locatorRegistryAdapter->setLocator(0);
LocatorRegistryPtr locatorRegistry = new LocatorRegistryI(adapterManagerProxy);
LocatorRegistryPrx locatorRegistryProxy =
LocatorRegistryPrx::uncheckedCast(locatorRegistryAdapter->add(locatorRegistry,
stringToIdentity(locatorRegistryId)));
//
// Create the "IcePack.Locator" object adapter and register the
// locator object.
//
// The locator locator object provides an implementation of the
// Ice::Locator interface. This interface is used by Ice clients
// to locate object adapters and their associated endpoints.
//
LocatorPtr locator = new LocatorI(adapterManagerProxy, locatorRegistryProxy);
ObjectAdapterPtr locatorAdapter = communicator()->createObjectAdapterWithEndpoints("IcePack.Locator",
locatorEndpoints);
locatorAdapter->setLocator(0);
LocatorPrx locatorProxy = LocatorPrx::uncheckedCast(locatorAdapter->add(locator, stringToIdentity(locatorId)));
//
// Set the locator for the admin object adapter.
//
adminAdapter->setLocator(locatorProxy);
//
// Activate the adapters.
//
shutdownOnInterrupt();
adminAdapter->activate();
locatorAdapter->activate();
locatorRegistryAdapter->activate();
communicator()->waitForShutdown();
ignoreInterrupt();
#ifndef _WIN32
//
// Destroy and join with activator.
//
activator->destroy();
activator->getThreadControl().join();
#endif
return EXIT_SUCCESS;
}
|