/******************************************************************************* * Copyright (c) 2007, Perforce Software, Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PERFORCE * SOFTWARE, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * DAMAGE. *******************************************************************************/ #ifndef SERVER_H # define SERVER_H enum { CHECK_STOPPED, CHECK_STARTED, CHECK_DENIED, CHECK_DENIED_ROOT, CHECK_FAILED, CHECK_GRANTED, }; enum { SERVER_NONE = 0, SERVER_P4D = 0x0001, SERVER_P4P = 0x0002, SERVER_P4WEB = 0x0004, SERVER_P4FTP = 0x0008, SERVER_P4BROKER = 0x0010, SERVER_P4DTG = 0x0020, SERVER_OTHER = 0x0080, SERVER_ALL = 0x00BF, }; #ifdef __cplusplus class Config; class VarList; class Server { public: Server( const char *name, int type, VarList *settings, VarList *env, const Config *config ); virtual ~Server(); // // Get the server's name // StrPtr & Name() { return name; } // // Get the owner's uid // uid_t OwnerUid() { return owner_uid; } // // Get the Owner's name // StrPtr * Owner() { return &owner; } // // Get the name for servers of this type // StrPtr & Label() { return label; } // // Get the type id for this server // int Type() { return type; } // // Check if this server is of a given type // int KindOf( int t ) { return t & type; } // // Check the server's configuration // virtual int IsValid( Error *e, int full=1 ) = 0; // // Merge a VarList of settings into this server's config, // without overriding any local settings // void MergeSettings( VarList *s ); // // Check that the current user has the right to work with // this server // int CheckAccess( Error *e ); // // Exec the binary to start the server. Returns non-zero if the // server is started // virtual int Start( StrPtr extraArgs, Error *e ); // // Shut down the running server. Returns non-zero on error // virtual int Stop( Error *e ); // // Check whether or not the server is running. Returns non-zero // if the server is alive. // virtual int Running( Error *e ); // // Extra text to show in listings for this server type // virtual void ExtraText( StrBuf &extra ) {}; // // Returns true if the server is enabled // int Enabled() { return enabled; } // // Test if this server uses SSL // virtual int SSLEnabled() { return 0; } // // Direct access to the server's environment. Returns // NULL if var is not defined. // StrPtr * GetVar( StrPtr &var ); // // Debugging // virtual void Dump(); protected: // // Compute the pid file for this server // void PidFile( StrBuf &buf ); // // Write pid file // void SavePid( pid_t pid, Error *e ); // // Load pid from file // pid_t LoadPid( Error *e ); // // Remove pid file // void CleanPid(); // // Load the user's data from the passwd file // void LoadUserData( Error *e ); // // Create a child process running as the server's owner, optionally // making the child a daemon by detaching from the controlling terminal // etc. Returns 0 to the child, -1 on fork() failure, and the pid of // the child to the parent. The child process's environment is set // up using the global variables and the server-specific variables. // pid_t CreateChild( int daemon, int quiet, Error *e ); // // Run a command in a subprocess optionally waiting for it // to complete. // int RunCommand( const char *cmd, CmdLine *args, pid_t &pid, int daemon, int silent, Error *e ); // // Run a Perforce command using our API // int RunP4Command( const char *cmd, CmdLine &args, Error *e); // // Set the process name for the server // virtual void SetProcessName( StrBuf &procName ) = 0; // // Extract command line args for a server // void ExtractArgs( CmdLine &cmdline ); // // Check that a path exists and is a directory // int CheckDirectory( StrPtr *d, Error *e ); // // Check that a service owner exists // int CheckOwner( StrPtr &o, Error *e ); // // Update internal config from settings // virtual void UpdateFromSettings(); // // Debug level // int Debug(); protected: StrBuf name; StrBuf label; StrBuf binary; StrBuf args; StrBuf owner; StrBuf owner_home; StrBuf owner_shell; uid_t owner_uid; uid_t owner_gid; VarList * env; VarList * settings; int umask; int type; int enabled; const Config * global_config; VarArray * childEnv; }; // // Subclass for things that are specific to P4D servers // class P4D : public Server { public: P4D( const char *name, VarList *settings, VarList *env, const Config *config ); virtual int IsValid( Error *e, int full=1 ); virtual int Stop( Error *e ); virtual int Running( Error *e ); virtual void SetProcessName( StrBuf &procName ); virtual void ExtraText( StrBuf &extra ); virtual int SSLEnabled(); void Checkpoint( int compress, Error *e ); void RotateJournal( int compress, Error *e ); protected: virtual void UpdateFromSettings(); private: void RunP4Info( Error *e ); void RunP4AdminStop( Error *e ); StrBuf prefix; }; // // Subclass for things that are specific to Proxy servers // class P4P : public Server { public: P4P( const char *name, VarList *settings, VarList *env, const Config *config ) : Server( name, SERVER_P4P, settings, env, config ) { label = "p4p"; } virtual int IsValid( Error *e, int full=1 ); virtual int Running( Error *e ); virtual int SSLEnabled(); virtual void SetProcessName( StrBuf &procName ); virtual void ExtraText( StrBuf &extra ); }; // // Subclass for things that are specific to P4Web Servers // class P4Web : public Server { public: P4Web( const char *name, VarList *settings, VarList *env, const Config *config ) : Server( name, SERVER_P4WEB, settings, env, config ) { label = "p4web"; } virtual int IsValid( Error *e, int full=1 ); virtual void SetProcessName( StrBuf &procName ); virtual void ExtraText( StrBuf &extra ); }; // // Subclass for things that are specific to P4FTP Servers // class P4Ftp : public Server { public: P4Ftp( const char *name, VarList *settings, VarList *env, const Config *config ) : Server( name, SERVER_P4FTP, settings, env, config ) { label = "p4ftpd"; } virtual int Start( StrPtr extraArgs, Error *e ); virtual int IsValid( Error *e, int full=1 ); virtual void SetProcessName( StrBuf &procName ); virtual void ExtraText( StrBuf &extra ); }; // // Subclass for things that are specific to Brokers // class P4Broker : public Server { public: P4Broker( const char *name, VarList *settings, VarList *env, const Config *config ) : Server( name, SERVER_P4BROKER, settings, env, config ) { label = "p4broker"; } virtual int IsValid( Error *e, int full=1 ); virtual void SetProcessName( StrBuf &procName ); virtual void ExtraText( StrBuf &extra ); }; // // Subclass for things that are specific to the P4DTG // class P4Dtg : public Server { public: P4Dtg( const char *name, VarList *settings, VarList *env, const Config *config ) : Server( name, SERVER_P4DTG, settings, env, config ) { label = "p4dtg"; } virtual int Start( StrPtr extraArgs, Error *e ); virtual int Stop( Error *e ); virtual int IsValid( Error *e, int full=1 ); virtual void SetProcessName( StrBuf &procName ); virtual void ExtraText( StrBuf &extra ); }; // // Subclass for starting arbitrary processes within our framework // class OtherServer : public Server { public: OtherServer( const char *name, VarList *settings, VarList *env, const Config *config ); virtual int IsValid( Error *e, int full=1 ); virtual void SetProcessName( StrBuf &procName ); virtual void ExtraText( StrBuf &extra ); protected: virtual void UpdateFromSettings(); private: StrBuf port; }; #endif /* __cplusplus */ #endif
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#3 | 16543 | Matt Attaway | Update P4DCTL with code from 15.2 and reorg files | ||
#2 | 10658 | Jason Gibson |
Update P4DCTL from internal Perforce tree. Note that this change does not bring the internal Jam files and deletes the existing builds, leaving that as a future task. Changes include: ################################################################################ Added support for a -o option which allows command line arguments to be passed directly to the service being started. ################################################################################ Support for P4DTG in P4DCTL. Example config: p4dtg test { Execute = /usr/local/share/p4dtg-2010.2.452775/p4dtg-repl Owner = perforce Environment { P4DTGROOT = /p4/dtg P4DTGMAPPING = local } } ################################################################################ Move p4dctl's default configuration file (and the only one that is considered safe to use) to '/etc/perforce/p4dctl.conf', and also move the directory that gets included by default to '/etc/perforce/p4dctl.conf.d'. ################################################################################ Make p4dctl provide LANG and LC_ALL environment variables to child processes. These both default to 'C'. They can be overridden in either global or server-specific environment blocks, but given that 2014.2 relies on LANG, it's better if that is set than missing. ################################################################################ Make p4dctl status exit with a code of 1 if any of the servers that it attempts to check are not running. For automation support ################################################################################ Change syntax of p4dctl config files so as to more clearly differentiate between 'settings' that p4dctl understands and environment variables to be set for the child processes. The old style syntax looked like this: p4d main { Owner = perforce Execute = /usr/local/bin/p4d P4ROOT = /home/perforce/p4-main P4JOURNAL = journal P4PORT = 1666 PATH = /bin:/usr/bin:/usr/local/bin } Where the only thing that differentiated the two was a convention on the use of case. Anything p4dctl didn't understand would be set as an environment variable. Now, we're separating the environment into a dedicated block, so p4dctl can flag up early if it encounters settings it doesn't know about. The new syntax looks like this: p4d main { Owner = perforce Execute = /usr/local/bin/p4d Environment { P4ROOT = /home/perforce/p4-main P4JOURNAL = journal P4PORT = 1666 PATH = /bin:/usr/bin:/usr/local/bin } } ################################################################################ A new command in p4dctl that allows you to query the environment for any configured server. For example: list all p4d's with their Name, port and root: $ p4dctl env -a -t p4d Name P4PORT P4ROOT Name=p4d-master P4PORT=ssl:1666 P4ROOT=/var/lib/perforce/p4d-master Find the P4ROOT of a known Perforce server and set P4ROOT in your environment: $ eval `p4dctl env -t p4d p4d-master P4ROOT` ################################################################################ Manpages for p4dctl and its config file. ################################################################################ Add 'list' command to p4dctl. Lists configured servers visible to the current user. Lists useful information about all the standard Perforce Server types. |
||
#1 | 8907 | Matt Attaway |
Branch Tony Smith's p4dctl tool into perforce_software area p4dctl is a tool that helps admins to manage multiple Perforce servers. This tool is used by the Perforce Linux packages to help manage servers. |
||
//guest/tony_smith/perforce/p4dctl/src/server.h | |||||
#10 | 8326 | Tony Smith |
Some significant updates to p4dctl. 1. Support for interacting with SSL enabled servers 2. New command 'list' to list configured servers p4dctl [ options ] list [ -t type ] -a p4dctl [ options ] list [ -t type ] servername 3. New command 'env' to allow you to fetch arbitrary settings from a configured server in a form suitable for use with 'eval'. p4dctl [ options ] env [ -t type ] -a var [ var... ] p4dctl [ options ] env [ -t type ] servername var [ var... ] 4. Supply a new manpage for p4dctl |
||
#9 | 8172 | Tony Smith |
Update p4dctl with a few fixes and enhancements: 1. New 'Enable=(true|false)' flag for servers so you can temporarily prevent servers from starting. 2. Ensure exit status is correct when commands partially fail. For example, start now exits with non-zero status if there are some failures. 3. Remove debug printf() that was left over from the change that introduced include files. |
||
#8 | 7996 | Tony Smith |
Add support for checkpoint and journal prefixes - configured in the server block. For example: Prefix = /some/disk/p4backup |
||
#7 | 7995 | Tony Smith |
Support for P4FTP servers listening on privileged ports. Limited to P4Ftp services only, if the P4FTPPORT is less than 1024, then the service will be started as root, and the '-u <user>' flag added automatically to the P4FTP commandline. |
||
#6 | 7830 | Tony Smith |
Bug fixes to previous change. Now broker support works properly. Updated the linux26x86 prebuilt binary |
||
#5 | 7828 | Tony Smith |
Add support for the broker to p4dctl andupdate version file. Simplified the code, and removed some ugly duplication which was bothering me. |
||
#4 | 7184 | Tony Smith |
Fix bug that prevented globally defined environment variables from being overridden by local definitions. The diffs here are a little large because the most sensible way to do this was to switch to using dictionaries for building the environment vars (to make replacing values easy), and then convert them to a VarArray later in a format that can be used as an environ pointer. |
||
#3 | 6285 | Tony Smith |
Add support for starting arbitrary daemons through this framework using configuration entries like this: other <name> { Execute = <binary> Owner = <username> [ Port = <listen port (if any)> ] [ Umask = <umask> ] PATH = "/usr/bin: etc. etc." } |
||
#2 | 6152 | Tony Smith |
Add support for configuring the umask with which Perforce services should run to p4dctl. If unspecified, the default umask is 022. |
||
#1 | 5945 | Tony Smith |
Release p4dctl, a program for starting/stopping Perforce services on Unix operating systems. Similar to, and developed in concert with, Sven Erik Knop's p4dcfg. For example: p4dctl start -a Can start multiple P4D, P4P, P4Web, or P4FTP servers in one easy command line. It can be executed by root, or by the 'owners' of the configured services and it maintains pidfiles no matter who uses it (so they remain accurate). An init script using p4dctl will typically just use: p4dctl start -a p4dctl stop -a p4dctl restart -a And check the exit status. |