X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain.cpp;h=c2c499fbbc205503ed42da278f585dfbc60c1ad1;hb=14fff12d9df0ee30e2df4bf9d22c2e83065816df;hp=8746da2b165db1df909f1c838d615b298c8e935e;hpb=b9c3763a932cebaa015a27fe111017f6f34dfbaa;p=fms.git diff --git a/src/main.cpp b/src/main.cpp index 8746da2..c2c499f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,21 +1,121 @@ #include "../include/global.h" #include "../include/commandthread.h" +#include "../include/threadcontroller.h" #include +#include +#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[]) { + bool daemon=false; + #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(); + daemon=true; + } + #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 + + if(daemon==false) + { + 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 +127,14 @@ 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); + LogFile::Instance()->WriteLog(LogFile::LOGLEVEL_DEBUG,"FMS wants to shutdown"); - ShutdownThreads(threads); - - ShutdownNetwork(); - - LogFile::Instance()->WriteLog(LogFile::LOGLEVEL_INFO,"FMS shutdown"); - LogFile::Instance()->WriteNewLine(); - - return 0; + Shutdown(); }