mirror of
https://github.com/unrealircd/unrealircd.git
synced 2026-06-12 17:14:46 +02:00
implementing multi service support
This commit is contained in:
@@ -1824,3 +1824,29 @@ MOTDs
|
||||
- Fixed typo in new module build switch
|
||||
- Added a Config -advanced prompt for --with-moduleswhich=
|
||||
- Small fix in s_conf.c and Velcro
|
||||
- Implementing #0003239 suggested by Siyavash, patched by Trocotronic, patch
|
||||
details:
|
||||
added -n parameter to unreal.exe. So, if you want, you could specify a
|
||||
name of service. It will receive all command. For example:
|
||||
|
||||
unreal install -n Deimos
|
||||
|
||||
It will install a service called UnrealIRCd-Deimos. Then, the configfile
|
||||
must be named unrealircd-deimos.conf. This way gave you chance to install
|
||||
more than one service on the same machine using only one installation.
|
||||
|
||||
unreal start -n Deimos // it will start service with
|
||||
unrealircd-deimos.conf file
|
||||
unreal uninstall -n Deimos
|
||||
|
||||
Although, -n parameter is optional, so you can use "unreal install" as
|
||||
usual.
|
||||
|
||||
If you run service from console (double click to wircd.exe for example),
|
||||
it will only start one service, main service, called UnrealIRCd (install
|
||||
without -n). If you only install services with name (-n), double click will
|
||||
start wircd.exe as usual (window mode).
|
||||
-n will affect to all command (install, uninstall, start, stop, etc)
|
||||
|
||||
Remember to use different listening ports (or interfaces) on every
|
||||
unrealircd-*.conf files.
|
||||
|
||||
@@ -200,7 +200,11 @@
|
||||
* these are only the recommened names and paths. Change as needed.
|
||||
* You must define these to something, even if you don't really want them.
|
||||
*/
|
||||
#ifndef _WIN32
|
||||
#define CPATH "unrealircd.conf" /* server configuration file */
|
||||
#else
|
||||
extern char CPATH[262];
|
||||
#endif
|
||||
#define MPATH "ircd.motd" /* server MOTD file */
|
||||
#define SMPATH "ircd.smotd" /* short MOTD file */
|
||||
#define RPATH "ircd.rules" /* server rules file */
|
||||
|
||||
+3
-1
@@ -105,6 +105,7 @@ FARPROC lpfnOldWndProc;
|
||||
HMENU hContext;
|
||||
OSVERSIONINFO VerInfo;
|
||||
char OSName[256];
|
||||
char CPATH[262];
|
||||
#ifdef USE_LIBCURL
|
||||
extern char *find_loaded_remote_include(char *url);
|
||||
#endif
|
||||
@@ -216,13 +217,14 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
|
||||
VerInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
|
||||
GetVersionEx(&VerInfo);
|
||||
GetOSName(VerInfo, OSName);
|
||||
strlcpy(CPATH, "unrealircd.conf", sizeof(CPATH));
|
||||
if (VerInfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
|
||||
{
|
||||
SC_HANDLE hService, hSCManager = OpenSCManager(NULL, NULL, GENERIC_EXECUTE);
|
||||
StartServiceCtrlDispatcher(DispatchTable);
|
||||
if ((hService = OpenService(hSCManager, "UnrealIRCd", GENERIC_EXECUTE)))
|
||||
{
|
||||
int save_err = 0;
|
||||
StartServiceCtrlDispatcher(DispatchTable);
|
||||
if (GetLastError() == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT)
|
||||
{
|
||||
SERVICE_STATUS status;
|
||||
|
||||
+6
-2
@@ -100,7 +100,7 @@ VOID WINAPI ServiceMain(DWORD dwArgc, LPTSTR *lpszArgv)
|
||||
{
|
||||
WSADATA WSAData;
|
||||
DWORD error = 0;
|
||||
char path[MAX_PATH], *folder;
|
||||
char path[MAX_PATH], *folder, *c;
|
||||
|
||||
IsService = TRUE;
|
||||
|
||||
@@ -117,9 +117,13 @@ VOID WINAPI ServiceMain(DWORD dwArgc, LPTSTR *lpszArgv)
|
||||
folder = strrchr(path, '\\');
|
||||
*folder = 0;
|
||||
chdir(path);
|
||||
|
||||
_snprintf(CPATH, sizeof(CPATH)-1, "%s.conf", lpszArgv[0]);
|
||||
for (c = CPATH; !BadPtr(c); c++)
|
||||
*c = tolower(*c);
|
||||
|
||||
/* Register the service controller */
|
||||
IRCDStatusHandle = RegisterServiceCtrlHandler("UnrealIRCd", IRCDCtrlHandler);
|
||||
IRCDStatusHandle = RegisterServiceCtrlHandler(lpszArgv[0], IRCDCtrlHandler);
|
||||
|
||||
VerInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
|
||||
GetVersionEx(&VerInfo);
|
||||
|
||||
+33
-15
@@ -27,7 +27,8 @@ UCHANGESERVICECONFIG2 uChangeServiceConfig2;
|
||||
|
||||
#define IRCD_SERVICE_CONTROL_REHASH 128
|
||||
void show_usage() {
|
||||
fprintf(stderr, "unreal start|stop|rehash|restart|install|uninstall|config <option> <value>");
|
||||
fprintf(stderr, "unreal start|stop|rehash|restart|install|uninstall|config [-n name] <option> <value>");
|
||||
fprintf(stderr, "\n-n parameter specifies the name of the service. It is useful if you want to install more than one service on the same machine\n");
|
||||
fprintf(stderr, "\nValid config options:\nstartup auto|manual\n");
|
||||
if (VerInfo.dwMajorVersion == 5)
|
||||
fprintf(stderr, "crashrestart delay\n");
|
||||
@@ -41,13 +42,30 @@ char *show_error(DWORD code) {
|
||||
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
char *bslash;
|
||||
char *bslash, sname[257], *opt = NULL, *value = NULL;
|
||||
VerInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
|
||||
GetVersionEx(&VerInfo);
|
||||
if (argc < 2) {
|
||||
show_usage();
|
||||
return -1;
|
||||
}
|
||||
strcpy(sname, "UnrealIRCd");
|
||||
if (argc > 2)
|
||||
{
|
||||
if (!strcmp(argv[2], "-n"))
|
||||
{
|
||||
if (argc < 4)
|
||||
{
|
||||
show_usage();
|
||||
return -1;
|
||||
}
|
||||
_snprintf(sname, sizeof(sname)-1, "UnrealIRCd-%s", argv[3]);
|
||||
if (argc > 4)
|
||||
opt = argv[4];
|
||||
if (argc > 5)
|
||||
value = argv[5];
|
||||
}
|
||||
}
|
||||
hAdvapi = LoadLibrary("advapi32.dll");
|
||||
uChangeServiceConfig2 = (UCHANGESERVICECONFIG2)GetProcAddress(hAdvapi, "ChangeServiceConfig2A");
|
||||
if (!stricmp(argv[1], "install")) {
|
||||
@@ -65,7 +83,7 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
strcpy(binpath,path);
|
||||
strcat(binpath, "\\wircd.exe");
|
||||
hService = CreateService(hSCManager, "UnrealIRCd", "UnrealIRCd",
|
||||
hService = CreateService(hSCManager, sname, sname,
|
||||
SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS,
|
||||
SERVICE_AUTO_START, SERVICE_ERROR_NORMAL, binpath,
|
||||
NULL, NULL, NULL, NULL, NULL);
|
||||
@@ -85,7 +103,7 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
else if (!stricmp(argv[1], "uninstall")) {
|
||||
SC_HANDLE hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
|
||||
SC_HANDLE hService = OpenService(hSCManager, "UnrealIRCd", DELETE);
|
||||
SC_HANDLE hService = OpenService(hSCManager, sname, DELETE);
|
||||
if (DeleteService(hService))
|
||||
printf("UnrealIRCd NT Service successfully uninstalled");
|
||||
else
|
||||
@@ -96,7 +114,7 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
else if (!stricmp(argv[1], "start")) {
|
||||
SC_HANDLE hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
|
||||
SC_HANDLE hService = OpenService(hSCManager, "UnrealIRCd", SERVICE_START);
|
||||
SC_HANDLE hService = OpenService(hSCManager, sname, SERVICE_START);
|
||||
if (StartService(hService, 0, NULL))
|
||||
printf("UnrealIRCd NT Service successfully started");
|
||||
else
|
||||
@@ -108,7 +126,7 @@ int main(int argc, char *argv[]) {
|
||||
else if (!stricmp(argv[1], "stop")) {
|
||||
SERVICE_STATUS status;
|
||||
SC_HANDLE hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
|
||||
SC_HANDLE hService = OpenService(hSCManager, "UnrealIRCd", SERVICE_STOP);
|
||||
SC_HANDLE hService = OpenService(hSCManager, sname, SERVICE_STOP);
|
||||
ControlService(hService, SERVICE_CONTROL_STOP, &status);
|
||||
printf("UnrealIRCd NT Service successfully stopped");
|
||||
CloseServiceHandle(hService);
|
||||
@@ -118,7 +136,7 @@ int main(int argc, char *argv[]) {
|
||||
else if (!stricmp(argv[1], "restart")) {
|
||||
SERVICE_STATUS status;
|
||||
SC_HANDLE hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
|
||||
SC_HANDLE hService = OpenService(hSCManager, "UnrealIRCd", SERVICE_STOP|SERVICE_START);
|
||||
SC_HANDLE hService = OpenService(hSCManager, sname, SERVICE_STOP|SERVICE_START);
|
||||
ControlService(hService, SERVICE_CONTROL_STOP, &status);
|
||||
if (StartService(hService, 0, NULL))
|
||||
printf("UnrealIRCd NT Service successfully restarted");
|
||||
@@ -129,37 +147,37 @@ int main(int argc, char *argv[]) {
|
||||
else if (!stricmp(argv[1], "rehash")) {
|
||||
SERVICE_STATUS status;
|
||||
SC_HANDLE hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
|
||||
SC_HANDLE hService = OpenService(hSCManager, "UnrealIRCd", SERVICE_USER_DEFINED_CONTROL);
|
||||
SC_HANDLE hService = OpenService(hSCManager, sname, SERVICE_USER_DEFINED_CONTROL);
|
||||
ControlService(hService, IRCD_SERVICE_CONTROL_REHASH, &status);
|
||||
printf("UnrealIRCd NT Service successfully rehashed");
|
||||
}
|
||||
else if (!stricmp(argv[1], "config")) {
|
||||
SERVICE_STATUS status;
|
||||
SC_HANDLE hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
|
||||
SC_HANDLE hService = OpenService(hSCManager, "UnrealIRCd",
|
||||
SC_HANDLE hService = OpenService(hSCManager, sname,
|
||||
SERVICE_CHANGE_CONFIG|SERVICE_START);
|
||||
if (argc < 3) {
|
||||
if (!opt) {
|
||||
show_usage();
|
||||
return -1;
|
||||
}
|
||||
if (!stricmp(argv[2], "startup")) {
|
||||
if (!stricmp(opt, "startup")) {
|
||||
if (ChangeServiceConfig(hService, SERVICE_NO_CHANGE,
|
||||
!stricmp(argv[3], "auto") ? SERVICE_AUTO_START
|
||||
value && !stricmp(value, "auto") ? SERVICE_AUTO_START
|
||||
: SERVICE_DEMAND_START, SERVICE_NO_CHANGE,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL))
|
||||
printf("UnrealIRCd NT Service configuration changed");
|
||||
else
|
||||
printf("UnrealIRCd NT Service configuration change failed - %s", show_error(GetLastError()));
|
||||
}
|
||||
else if (!stricmp(argv[2], "crashrestart") && VerInfo.dwMajorVersion == 5) {
|
||||
else if (!stricmp(opt, "crashrestart") && VerInfo.dwMajorVersion == 5) {
|
||||
SERVICE_FAILURE_ACTIONS hFailActions;
|
||||
SC_ACTION hAction;
|
||||
memset(&hFailActions, 0, sizeof(hFailActions));
|
||||
if (argc >= 4) {
|
||||
if (value) {
|
||||
hFailActions.dwResetPeriod = 30;
|
||||
hFailActions.cActions = 1;
|
||||
hAction.Type = SC_ACTION_RESTART;
|
||||
hAction.Delay = atoi(argv[3])*60000;
|
||||
hAction.Delay = atoi(value)*60000;
|
||||
hFailActions.lpsaActions = &hAction;
|
||||
if (uChangeServiceConfig2(hService, SERVICE_CONFIG_FAILURE_ACTIONS,
|
||||
&hFailActions))
|
||||
|
||||
Reference in New Issue
Block a user