Changeset 1855

Show
Ignore:
Timestamp:
22/09/2007 00:52:08 (16 months ago)
Author:
chris
Message:

Add "-h" and "/?" options to display usage in Daemon.

Extend usage info with service commands in BackupDaemon?.

Disable useless -D, -V and -k options on Windows.

Location:
box/chris/general
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • box/chris/general/bin/bbackupd/BackupDaemon.cpp

    r1854 r1855  
    3838        #include <process.h> 
    3939#endif 
     40 
     41#include <iostream> 
    4042 
    4143#include "Configuration.h" 
     
    210212// 
    211213// -------------------------------------------------------------------------- 
    212 const char *BackupDaemon::DaemonBanner() const 
    213 { 
    214 #ifndef NDEBUG 
    215         // Don't display banner in debug builds 
    216         return 0; 
    217 #else 
     214std::string BackupDaemon::DaemonBanner() const 
     215{ 
    218216        return BANNER_TEXT("Backup Client"); 
     217} 
     218 
     219void BackupDaemon::Usage() 
     220{ 
     221        this->Daemon::Usage(); 
     222 
     223#ifdef WIN32 
     224        std::cout << 
     225        "  -s         Run as a Windows Service, for internal use only\n" 
     226        "  -i         Install Windows Service (you may want to specify a config file)\n" 
     227        "  -r         Remove Windows Service\n" 
     228        "  -S <name>  Service name for -i and -r options\n"; 
    219229#endif 
    220230} 
  • box/chris/general/bin/bbackupd/BackupDaemon.h

    r1854 r1855  
    7070        void Run(); 
    7171        virtual const char *DaemonName() const; 
    72         virtual const char *DaemonBanner() const; 
     72        virtual std::string DaemonBanner() const; 
     73        virtual void Usage(); 
    7374        const ConfigurationVerify *GetConfigVerify() const; 
    7475 
  • box/chris/general/bin/bbstored/BackupStoreDaemon.cpp

    r1784 r1855  
    9494// 
    9595// -------------------------------------------------------------------------- 
    96 const char *BackupStoreDaemon::DaemonBanner() const 
    97 { 
    98 #ifndef NDEBUG 
    99         // Don't display banner in debug builds 
    100         return 0; 
    101 #else 
     96std::string BackupStoreDaemon::DaemonBanner() const 
     97{ 
    10298        return BANNER_TEXT("Backup Store Server"); 
    103 #endif 
    10499} 
    105100 
  • box/chris/general/bin/bbstored/BackupStoreDaemon.h

    r1381 r1855  
    5757         
    5858        virtual const char *DaemonName() const; 
    59         virtual const char *DaemonBanner() const; 
     59        virtual std::string DaemonBanner() const; 
    6060 
    6161        const ConfigurationVerify *GetConfigVerify() const; 
  • box/chris/general/lib/server/Daemon.cpp

    r1850 r1855  
    2323        #include <ws2tcpip.h> 
    2424#endif 
     25 
     26#include <iostream> 
    2527 
    2628#include "Daemon.h" 
     
    5254          mRunInForeground(false), 
    5355          mKeepConsoleOpenAfterFork(false), 
    54           mHaveConfigFile(false) 
     56          mHaveConfigFile(false), 
     57          mAppName(DaemonName()) 
    5558{ 
    5659        if(spDaemon != NULL) 
     
    100103std::string Daemon::GetOptionString() 
    101104{ 
    102         return "c:DFqvVt:Tk"; 
     105        return "c:" 
     106        #ifndef WIN32 
     107                "DFk" 
     108        #endif 
     109                "hqvVt:T"; 
     110} 
     111 
     112void Daemon::Usage() 
     113{ 
     114        std::cout <<  
     115        DaemonBanner() << "\n" 
     116        "\n" 
     117        "Usage: " << mAppName << " [options] [config file]\n" << 
     118        "\n" 
     119        "Options:\n" 
     120        "  -c <file>  Use the specified configuration file. If -c is omitted, the last\n" 
     121        "             argument is the configuration file\n" 
     122#ifndef WIN32 
     123        "  -D         Debugging mode, do not fork, one process only, one client only\n" 
     124        "  -F         Do not fork into background, but fork to serve multiple clients\n" 
     125        "  -k         Keep console open after fork, keep writing log messages to it\n" 
     126#endif 
     127        "  -q         Run more quietly, reduce verbosity level by one, can repeat\n" 
     128        "  -v         Run more verbosely, increase verbosity level by one, can repeat\n" 
     129        "  -V         Run at maximum verbosity\n" 
     130        "  -t <tag>   Tag console output with specified marker\n" 
     131        "  -T         Timestamp console output\n"; 
    103132} 
    104133 
     
    125154                break; 
    126155 
     156#ifndef WIN32 
    127157                case 'D': 
    128158                { 
     
    134164                { 
    135165                        mRunInForeground = true; 
     166                } 
     167                break; 
     168 
     169                case 'k': 
     170                { 
     171                        mKeepConsoleOpenAfterFork = true; 
     172                } 
     173                break; 
     174#endif 
     175 
     176                case 'h': 
     177                { 
     178                        Usage(); 
     179                        return 2; 
    136180                } 
    137181                break; 
     
    181225                break; 
    182226 
    183                 case 'k': 
    184                 { 
    185                         mKeepConsoleOpenAfterFork = true; 
    186                 } 
    187                 break; 
    188  
    189227                case '?': 
    190228                { 
     
    220258        // Find filename of config file 
    221259        mConfigFileName = DefaultConfigFile; 
     260        mAppName = argv[0]; 
    222261 
    223262        #ifdef NDEBUG 
     
    226265        mLogLevel = Log::INFO; // need an int to do math with 
    227266        #endif 
     267 
     268        if (argc == 2 && strcmp(argv[1], "/?") == 0) 
     269        { 
     270                Usage(); 
     271                return 2; 
     272        } 
    228273 
    229274        signed int c; 
     
    284329        // Banner (optional) 
    285330        { 
    286                 const char *banner = DaemonBanner(); 
    287                 if(banner != 0) 
    288                 { 
    289                         BOX_NOTICE(banner); 
    290                 } 
     331                #ifndef NDEBUG 
     332                BOX_NOTICE(DaemonBanner()); 
     333                #endif 
    291334        } 
    292335 
     
    672715// 
    673716// -------------------------------------------------------------------------- 
    674 const char *Daemon::DaemonBanner() const 
    675 { 
    676         return 0; 
     717std::string Daemon::DaemonBanner() const 
     718{ 
     719        return "Generic daemon using the Box Application Framework"; 
    677720} 
    678721 
  • box/chris/general/lib/server/Daemon.h

    r1852 r1855  
    5151 
    5252        virtual const char *DaemonName() const; 
    53         virtual const char *DaemonBanner() const; 
     53        virtual std::string DaemonBanner() const; 
    5454        virtual const ConfigurationVerify *GetConfigVerify() const; 
     55        virtual void Usage(); 
    5556         
    5657        bool StopRun() {return mReloadConfigWanted | mTerminateWanted;} 
     
    8889        int mLogLevel; // need an int to do math with 
    8990        static Daemon *spDaemon; 
     91        std::string mAppName; 
    9092}; 
    9193