X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmain.cpp;h=17d6b6757f2c0721018713f9f69592d4a208dc11;hb=f60495a029c54358f82956482fe203fe2b7b5b23;hp=8746da2b165db1df909f1c838d615b298c8e935e;hpb=b9c3763a932cebaa015a27fe111017f6f34dfbaa;p=fms.git diff --git a/src/main.cpp b/src/main.cpp index 8746da2..17d6b67 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,21 +1,113 @@ #include "../include/global.h" #include "../include/commandthread.h" +#include "../include/threadcontroller.h" #include +#include +#include + +#ifdef _WIN32 + #include "../include/fmsservice.h" +#else + #include "../include/fmsdaemon.h" +#endif #ifdef XMEM #include #endif -int main() +int main(int argc, char *argv[]) { #ifdef XMEM xmem_disable_print(); #endif - std::vector threads; + // check arguments + if(argc>1) + { + #ifndef _WIN32 + if(argv[1] && strncmp(argv[1],"-d",2)==0) + { + Daemonize(); + } + #else + if(argv[1] && strncmp(argv[1],"-i",2)==0) + { + if(ServiceIsInstalled()) + { + std::cout << "FMS Service is already installed" << std::endl; + } + else + { + if(ServiceInstall()) + { + std::cout << "FMS Service Installed" << std::endl; + } + else + { + std::cout << "Error installing FMS Service" << std::endl; + } + } + return 0; + } + else if(argv[1] && strncmp(argv[1],"-u",2)==0) + { + if(ServiceIsInstalled()) + { + if(ServiceUninstall()) + { + std::cout << "FMS Service uninstalled" << std::endl; + } + else + { + std::cout << "There was a problem uninstalling the service" << std::endl; + } + } + else + { + std::cout << "FMS Service is not currently installed" << std::endl; + } + return 0; + } + else if(argv[1] && strncmp(argv[1],"-s",2)==0) + { + if(ServiceStart()) + { + } + else + { + std::cout << "FMS Service could not be started at this time" << std::endl; + } + return 0; + } + #endif + } + + signal(SIGINT,SigHandler); + signal(SIGTERM,SigHandler); + signal(SIGABRT,SigHandler); +#ifdef _WIN32 + signal(SIGBREAK,SigHandler); +#endif + + std::cout << "FMS Running in console mode." << std::endl; + std::cout << "Use the administration pages, or CTRL+C to exit" << std::endl << std::endl; + std::cout << "Available command line arguments:" << std::endl; +#ifdef _WIN32 + std::cout << "-i\tinstall service" << std::endl; + std::cout << "-u\tuninstall service" << std::endl; +#else + std::cout << "-d\trun as daemon" << std::endl; +#endif + + MainFunction(); + + return 0; +} +void MainFunction() +{ srand(time(NULL)); SetupDB(); @@ -27,21 +119,12 @@ int main() LogFile::Instance()->WriteLog(LogFile::LOGLEVEL_INFO,"FMS startup v"FMS_VERSION); + ThreadController::Instance()->StartThreads(); - StartThreads(threads); - - - //ZThread::Thread commandthread(new CommandThread()); - PThread::Thread commandthread(new CommandThread()); - commandthread.Join(); - + do + { + PThread::Sleep(1000); + }while(!wantshutdown); - ShutdownThreads(threads); - - ShutdownNetwork(); - - LogFile::Instance()->WriteLog(LogFile::LOGLEVEL_INFO,"FMS shutdown"); - LogFile::Instance()->WriteNewLine(); - - return 0; + Shutdown(); }