X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain.cpp;h=9fefa8fa2ba217ddf6c63b87d7ba56db5fb4bf2d;hb=df316253862dc50e8e5a790d9634ef90be37badb;hp=3e135a07167787b7d5469790400320f4ac2100be;hpb=c7fcb4c4bc5012a584add81a9509fc1f84c3c688;p=fms.git diff --git a/src/main.cpp b/src/main.cpp index 3e135a0..9fefa8f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,48 +1,135 @@ #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[]) { + 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(); SetupDefaultOptions(); - SetupLogFile(); SetupNetwork(); 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(); }