1 martin 1.5 //%LICENSE////////////////////////////////////////////////////////////////
|
2 martin 1.6 //
|
3 martin 1.5 // Licensed to The Open Group (TOG) under one or more contributor license
4 // agreements. Refer to the OpenPegasusNOTICE.txt file distributed with
5 // this work for additional information regarding copyright ownership.
6 // Each contributor licenses this file to you under the OpenPegasus Open
7 // Source License; you may not use this file except in compliance with the
8 // License.
|
9 martin 1.6 //
|
10 martin 1.5 // Permission is hereby granted, free of charge, to any person obtaining a
11 // copy of this software and associated documentation files (the "Software"),
12 // to deal in the Software without restriction, including without limitation
13 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 // and/or sell copies of the Software, and to permit persons to whom the
15 // Software is furnished to do so, subject to the following conditions:
|
16 martin 1.6 //
|
17 martin 1.5 // The above copyright notice and this permission notice shall be included
18 // in all copies or substantial portions of the Software.
|
19 martin 1.6 //
|
20 martin 1.5 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
21 martin 1.6 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
22 martin 1.5 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
27 martin 1.6 //
|
28 martin 1.5 //////////////////////////////////////////////////////////////////////////
|
29 kumpf 1.1 //
30 //%/////////////////////////////////////////////////////////////////////////////
31
32 #ifndef Pegasus_ServerRunStatus_h
33 #define Pegasus_ServerRunStatus_h
34
|
35 dave.sudlik 1.2 #ifdef PEGASUS_OS_TYPE_WINDOWS
36 #include <windows.h>
37 #endif
|
38 kumpf 1.1 #include <Pegasus/Common/Config.h>
39 #include <Pegasus/Common/String.h>
40 #include <Service/Linkage.h>
41
42 PEGASUS_NAMESPACE_BEGIN
43
|
44 ouyang.jian 1.3 #if defined(PEGASUS_OS_TYPE_WINDOWS)
|
45 kumpf 1.1 typedef int PEGASUS_PID_T;
46 #else
47 typedef pid_t PEGASUS_PID_T;
48 #endif
49
50 /**
51 The ServerRunStatus class is used to manage the run status of a
52 server. It can be used to determine if an instance of the server is
53 already running, to kill a running instance, and to indicate that an
54 instance is being started.
55
56 The implementation varies per platform. On Unix platforms, a PID file
57 is used to record the process ID of the running server. On Windows,
58 an event handle is used and the PID parameters are not meaningful.
59 */
60 class PEGASUS_SERVICE_LINKAGE ServerRunStatus
61 {
62 public:
63
64 /**
65 Constructs a ServerRunStatus instance with the specified server
66 kumpf 1.1 parameters.
67 */
68 ServerRunStatus(
69 const char* serverName,
70 const char* pidFilePath);
71
72 /**
73 Destructs the ServerRunStatus instance. On Windows, this
74 indicates to the system that this instance of the server is no
75 longer running.
76 */
77 ~ServerRunStatus();
78
79 /**
80 Determines whether the server is running, based on the parameters
81 specified in the constructor.
82 */
83 Boolean isServerRunning();
84
85 /**
86 Indicates that this instance of the server is now running.
87 kumpf 1.1 */
88 void setServerRunning();
89
90 /**
91 On platforms that use a PID file, this method allows a parent process
92 ID to be specified. This allows the isServerRunning() method to take
93 the parent process into consideration.
94 */
95 void setParentPid(PEGASUS_PID_T parentPid);
96
97 /**
98 Sends a SIGKILL signal to the running server process on platforms
99 that support signals.
100 */
101 Boolean kill();
102
103 private:
104
105 /**
106 Determines whether the specified process ID is an instance of the
107 server specified in the constructor.
108 kumpf 1.1 */
109 Boolean _isServerProcess(PEGASUS_PID_T pid);
110
111 const char* _serverName;
|
112 kumpf 1.4
113 /**
114 The path to the PID file for this server. The PID of the server
115 process is written to this file by setServerRunning(). The
116 isServerRunning() and kill() methods also use this file.
117 NOTE: The PID file is not used in the Windows implementation.
118 */
|
119 kumpf 1.1 const char* _pidFilePath;
|
120 kumpf 1.4
121 /**
122 Indicates whether this ServerRunStatus instance is for the server that
123 is actually running. A call to setServerRunning() sets this to true.
124 If this flag is true when the ServerRunStatus instance is destructed,
125 the PID file is removed.
126 */
127 Boolean _isRunningServerInstance;
128
|
129 kumpf 1.1 PEGASUS_PID_T _parentPid;
130
131 #ifdef PEGASUS_OS_TYPE_WINDOWS
132 HANDLE _event;
133 Boolean _wasAlreadyRunning;
134 #endif
135 };
136
137 PEGASUS_NAMESPACE_END
138
139 #endif // Pegasus_ServerRunStatus_h
|