mirror of
https://github.com/mangosfour/server.git
synced 2025-12-15 10:37:02 +00:00
[11507] Fixed problem with too later config read in recent added posix daemon support.
Restore read config _after_ option parsing in any cases.
This commit is contained in:
parent
945466934d
commit
6ed4dfe827
3 changed files with 79 additions and 77 deletions
|
|
@ -87,14 +87,7 @@ extern int main(int argc, char **argv)
|
||||||
ACE_Get_Opt cmd_opts(argc, argv, options);
|
ACE_Get_Opt cmd_opts(argc, argv, options);
|
||||||
cmd_opts.long_option("version", 'v');
|
cmd_opts.long_option("version", 'v');
|
||||||
|
|
||||||
#ifndef WIN32 // need call before options for posix daemon
|
char serviceDaemonMode = '\0';
|
||||||
if (!sConfig.SetSource(cfg_file))
|
|
||||||
{
|
|
||||||
sLog.outError("Could not find configuration file %s.", cfg_file);
|
|
||||||
Log::WaitBeforeContinueIfNeed();
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int option;
|
int option;
|
||||||
while ((option = cmd_opts()) != EOF)
|
while ((option = cmd_opts()) != EOF)
|
||||||
|
|
@ -108,24 +101,20 @@ extern int main(int argc, char **argv)
|
||||||
printf("%s\n", _FULLVERSION(REVISION_DATE,REVISION_TIME,REVISION_NR,REVISION_ID));
|
printf("%s\n", _FULLVERSION(REVISION_DATE,REVISION_TIME,REVISION_NR,REVISION_ID));
|
||||||
return 0;
|
return 0;
|
||||||
case 's':
|
case 's':
|
||||||
{
|
{
|
||||||
#ifdef WIN32
|
|
||||||
const char *mode = cmd_opts.opt_arg();
|
const char *mode = cmd_opts.opt_arg();
|
||||||
|
|
||||||
if (!strcmp(mode, "install"))
|
if (!strcmp(mode, "run"))
|
||||||
{
|
serviceDaemonMode = 'r';
|
||||||
if (WinServiceInstall())
|
#ifdef WIN32
|
||||||
sLog.outString("Installing service");
|
else if (!strcmp(mode, "install"))
|
||||||
return 1;
|
serviceDaemonMode = 'i';
|
||||||
}
|
|
||||||
else if (!strcmp(mode, "uninstall"))
|
else if (!strcmp(mode, "uninstall"))
|
||||||
{
|
serviceDaemonMode = 'u';
|
||||||
if (WinServiceUninstall())
|
#else
|
||||||
sLog.outString("Uninstalling service");
|
else if (!strcmp(mode, "stop"))
|
||||||
return 1;
|
serviceDaemonMode = 's';
|
||||||
}
|
#endif
|
||||||
else if (!strcmp(mode, "run"))
|
|
||||||
WinServiceRun();
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sLog.outError("Runtime-Error: -%c unsupported argument %s", cmd_opts.opt_opt(), mode);
|
sLog.outError("Runtime-Error: -%c unsupported argument %s", cmd_opts.opt_opt(), mode);
|
||||||
|
|
@ -134,22 +123,7 @@ extern int main(int argc, char **argv)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#else
|
|
||||||
const char *mode = cmd_opts.opt_arg();
|
|
||||||
if (!strcmp(mode, "run"))
|
|
||||||
startDaemon(120);
|
|
||||||
else if (!strcmp(mode, "stop"))
|
|
||||||
stopDaemon();
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sLog.outError("Runtime-Error: -%c unsupported argument %s", cmd_opts.opt_opt(), mode);
|
|
||||||
usage(argv[0]);
|
|
||||||
Log::WaitBeforeContinueIfNeed();
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
case ':':
|
case ':':
|
||||||
sLog.outError("Runtime-Error: -%c option requires an input argument", cmd_opts.opt_opt());
|
sLog.outError("Runtime-Error: -%c option requires an input argument", cmd_opts.opt_opt());
|
||||||
usage(argv[0]);
|
usage(argv[0]);
|
||||||
|
|
@ -163,13 +137,40 @@ extern int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WIN32 // need call after options for windows service
|
#ifndef WIN32 // posix daemon commands need apply before config read
|
||||||
|
switch (serviceDaemonMode)
|
||||||
|
{
|
||||||
|
case 'r':
|
||||||
|
startDaemon();
|
||||||
|
break;
|
||||||
|
case 's':
|
||||||
|
stopDaemon();
|
||||||
|
break
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!sConfig.SetSource(cfg_file))
|
if (!sConfig.SetSource(cfg_file))
|
||||||
{
|
{
|
||||||
sLog.outError("Could not find configuration file %s.", cfg_file);
|
sLog.outError("Could not find configuration file %s.", cfg_file);
|
||||||
Log::WaitBeforeContinueIfNeed();
|
Log::WaitBeforeContinueIfNeed();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef WIN32 // windows service command need execute after config read
|
||||||
|
switch (serviceDaemonMode)
|
||||||
|
{
|
||||||
|
case 'i':
|
||||||
|
if (WinServiceInstall())
|
||||||
|
sLog.outString("Installing service");
|
||||||
|
return 1;
|
||||||
|
case 'u':
|
||||||
|
if (WinServiceUninstall())
|
||||||
|
sLog.outString("Uninstalling service");
|
||||||
|
return 1;
|
||||||
|
case 'r':
|
||||||
|
WinServiceRun();
|
||||||
|
break;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
sLog.outString( "%s [world-daemon]", _FULLVERSION(REVISION_DATE,REVISION_TIME,REVISION_NR,REVISION_ID) );
|
sLog.outString( "%s [world-daemon]", _FULLVERSION(REVISION_DATE,REVISION_TIME,REVISION_NR,REVISION_ID) );
|
||||||
|
|
|
||||||
|
|
@ -96,17 +96,9 @@ extern int main(int argc, char **argv)
|
||||||
ACE_Get_Opt cmd_opts(argc, argv, options);
|
ACE_Get_Opt cmd_opts(argc, argv, options);
|
||||||
cmd_opts.long_option("version", 'v');
|
cmd_opts.long_option("version", 'v');
|
||||||
|
|
||||||
#ifndef WIN32 // need call before options for posix daemon
|
char serviceDaemonMode = '\0';
|
||||||
if (!sConfig.SetSource(cfg_file))
|
|
||||||
{
|
|
||||||
sLog.outError("Could not find configuration file %s.", cfg_file);
|
|
||||||
Log::WaitBeforeContinueIfNeed();
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int option;
|
int option;
|
||||||
|
|
||||||
while ((option = cmd_opts()) != EOF)
|
while ((option = cmd_opts()) != EOF)
|
||||||
{
|
{
|
||||||
switch (option)
|
switch (option)
|
||||||
|
|
@ -120,36 +112,19 @@ extern int main(int argc, char **argv)
|
||||||
|
|
||||||
case 's':
|
case 's':
|
||||||
{
|
{
|
||||||
#ifdef WIN32
|
|
||||||
const char *mode = cmd_opts.opt_arg();
|
const char *mode = cmd_opts.opt_arg();
|
||||||
|
|
||||||
if (!strcmp(mode, "install"))
|
|
||||||
{
|
|
||||||
if (WinServiceInstall())
|
|
||||||
sLog.outString("Installing service");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
else if (!strcmp(mode, "uninstall"))
|
|
||||||
{
|
|
||||||
if (WinServiceUninstall())
|
|
||||||
sLog.outString("Uninstalling service");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
else if (!strcmp(mode, "run"))
|
|
||||||
WinServiceRun();
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sLog.outError("Runtime-Error: -%c unsupported argument %s", cmd_opts.opt_opt(), mode);
|
|
||||||
usage(argv[0]);
|
|
||||||
Log::WaitBeforeContinueIfNeed();
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
const char *mode = cmd_opts.opt_arg();
|
|
||||||
if (!strcmp(mode, "run"))
|
if (!strcmp(mode, "run"))
|
||||||
startDaemon();
|
serviceDaemonMode = 'r';
|
||||||
|
#ifdef WIN32
|
||||||
|
else if (!strcmp(mode, "install"))
|
||||||
|
serviceDaemonMode = 'i';
|
||||||
|
else if (!strcmp(mode, "uninstall"))
|
||||||
|
serviceDaemonMode = 'u';
|
||||||
|
#else
|
||||||
else if (!strcmp(mode, "stop"))
|
else if (!strcmp(mode, "stop"))
|
||||||
stopDaemon();
|
serviceDaemonMode = 's';
|
||||||
|
#endif
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sLog.outError("Runtime-Error: -%c unsupported argument %s", cmd_opts.opt_opt(), mode);
|
sLog.outError("Runtime-Error: -%c unsupported argument %s", cmd_opts.opt_opt(), mode);
|
||||||
|
|
@ -157,7 +132,6 @@ extern int main(int argc, char **argv)
|
||||||
Log::WaitBeforeContinueIfNeed();
|
Log::WaitBeforeContinueIfNeed();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ':':
|
case ':':
|
||||||
|
|
@ -173,13 +147,40 @@ extern int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WIN32 // need call after options for windows service
|
#ifndef WIN32 // posix daemon commands need apply before config read
|
||||||
|
switch (serviceDaemonMode)
|
||||||
|
{
|
||||||
|
case 'r':
|
||||||
|
startDaemon();
|
||||||
|
break;
|
||||||
|
case 's':
|
||||||
|
stopDaemon();
|
||||||
|
break
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!sConfig.SetSource(cfg_file))
|
if (!sConfig.SetSource(cfg_file))
|
||||||
{
|
{
|
||||||
sLog.outError("Could not find configuration file %s.", cfg_file);
|
sLog.outError("Could not find configuration file %s.", cfg_file);
|
||||||
Log::WaitBeforeContinueIfNeed();
|
Log::WaitBeforeContinueIfNeed();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef WIN32 // windows service command need execute after config read
|
||||||
|
switch (serviceDaemonMode)
|
||||||
|
{
|
||||||
|
case 'i':
|
||||||
|
if (WinServiceInstall())
|
||||||
|
sLog.outString("Installing service");
|
||||||
|
return 1;
|
||||||
|
case 'u':
|
||||||
|
if (WinServiceUninstall())
|
||||||
|
sLog.outString("Uninstalling service");
|
||||||
|
return 1;
|
||||||
|
case 'r':
|
||||||
|
WinServiceRun();
|
||||||
|
break;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
sLog.Initialize();
|
sLog.Initialize();
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#ifndef __REVISION_NR_H__
|
#ifndef __REVISION_NR_H__
|
||||||
#define __REVISION_NR_H__
|
#define __REVISION_NR_H__
|
||||||
#define REVISION_NR "11506"
|
#define REVISION_NR "11507"
|
||||||
#endif // __REVISION_NR_H__
|
#endif // __REVISION_NR_H__
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue