/******************************************************************************* * 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. *******************************************************************************/ /* * p4dctlerr.cc - definitions of errors for p4dctl */ # include <stdhdrs.h> # include <error.h> # include <errornum.h> # include <strbuf.h> # include "p4dctlerr.h" // // Error numbers are allocated like this: // // Fatal Errors: 001 - 200 // Failed Errors: 201 - 400 // Warnings: 401 - 600 // Info messages: 601 - 800 // Empty messages: 801 - 1000 // // Maximum is 1023 as 10 bits are allocated. // // Fatal errors // Failed command errors ErrorId CtlErr::BadCommand = { ErrorOf( ES_SERVER, 201, E_FAILED, EV_USAGE, 1), "Unrecognised command: %cmd%." }; ErrorId CtlErr::MissingRequiredParm = { ErrorOf( ES_SERVER, 202, E_FAILED, EV_USAGE, 3), "Configuration for %name% %type% is missing required parameter %parm%." }; ErrorId CtlErr::ServerAccessDenied = { ErrorOf( ES_SERVER, 203, E_FAILED, EV_USAGE, 3), "Access to %type% %name% owned by %user% denied." }; ErrorId CtlErr::NoRootServers = { ErrorOf( ES_SERVER, 204, E_FAILED, EV_USAGE, 0), "Servers owned by root are not permitted." }; ErrorId CtlErr::ConfigParseError = { ErrorOf( ES_SERVER, 205, E_FAILED, EV_USAGE, 2), "Syntax error in %configFile% at line %lineNo%." }; ErrorId CtlErr::ChildKilled = { ErrorOf( ES_SERVER, 207, E_FAILED, EV_FAULT, 2), "Child process %pid% exited on signal %signal%." }; ErrorId CtlErr::ChildFailed = { ErrorOf( ES_SERVER, 208, E_FAILED, EV_FAULT, 4), "%name% %type%: '%cmd%' exited with status %status%." }; ErrorId CtlErr::ChildExecFail = { ErrorOf( ES_SERVER, 209, E_FAILED, EV_CONFIG, 1), "Failed to exec() %prog%." }; ErrorId CtlErr::SomeFailedStops = { ErrorOf( ES_SERVER, 210, E_FAILED, EV_FAULT, 0), "Not all servers stopped successfully." }; ErrorId CtlErr::SomeFailedStarts = { ErrorOf( ES_SERVER, 211, E_FAILED, EV_FAULT, 0), "Not all servers started successfully." }; ErrorId CtlErr::UnsafeConfig = { ErrorOf( ES_SERVER, 212, E_FAILED, EV_USAGE, 0), "Not safe to use configuration file or pid location from command line\n" "\twhen running as root." }; ErrorId CtlErr::CheckpointFail = { ErrorOf( ES_SERVER, 213, E_FAILED, EV_FAULT, 1), "Checkpointing %name% server failed. This needs investigation!" }; ErrorId CtlErr::RotateFail = { ErrorOf( ES_SERVER, 214, E_FAILED, EV_FAULT, 1), "Journal rotation for %name% server failed. This needs investigation!" }; ErrorId CtlErr::MissingDir = { ErrorOf( ES_SERVER, 215, E_FAILED, EV_USAGE, 3), "Server %name% %type%: Directory '%dir%' does not exist." }; ErrorId CtlErr::NotDirectory = { ErrorOf( ES_SERVER, 216, E_FAILED, EV_USAGE, 3), "Server %name% %type%: '%dir%' is not a directory." }; ErrorId CtlErr::OwnerNotFound = { ErrorOf( ES_SERVER, 217, E_FAILED, EV_USAGE, 3), "Server %name% %type%: Owner '%owner%' not found." }; // Warnings ErrorId CtlErr::SkippedServer = { ErrorOf( ES_SERVER, 401, E_WARN, EV_USAGE, 3), "Skipped %name% %type% owned by %owner%." }; ErrorId CtlErr::ServerNotRunning = { ErrorOf( ES_SERVER, 402, E_WARN, EV_USAGE, 2), "%name% %type% not running." }; ErrorId CtlErr::AlreadyRunning = { ErrorOf( ES_SERVER, 403, E_WARN, EV_USAGE, 2), "%name% %type% already running." }; ErrorId CtlErr::IgnoreDisabled = { ErrorOf( ES_SERVER, 404, E_WARN, EV_USAGE, 2), "%name% %type% disabled in config file. Ignored." }; // Informational messages ErrorId CtlErr::StartedServer = { ErrorOf( ES_SERVER, 601, E_INFO, EV_USAGE, 2), "Started %name% %type%." }; ErrorId CtlErr::StartedServers = { ErrorOf( ES_SERVER, 602, E_INFO, EV_USAGE, 1), "Started %count% servers." }; ErrorId CtlErr::StoppedServer = { ErrorOf( ES_SERVER, 603, E_INFO, EV_USAGE, 2), "Stopped %name% %type% server." }; ErrorId CtlErr::StoppedServers = { ErrorOf( ES_SERVER, 604, E_INFO, EV_USAGE, 1), "Stopped %count% servers." }; ErrorId CtlErr::ServerRunning = { ErrorOf( ES_SERVER, 605, E_INFO, EV_USAGE, 2), "%name% %type% is running." }; ErrorId CtlErr::KillingServer = { ErrorOf( ES_SERVER, 606, E_INFO, EV_USAGE, 2), "Failed to stop %name% %type% using 'p4 admin stop'. Trying a SIGTERM..." }; ErrorId CtlErr::Checkpointing = { ErrorOf( ES_SERVER, 607, E_INFO, EV_USAGE, 1), "Checkpointing %name% server..." }; ErrorId CtlErr::JnlRotate = { ErrorOf( ES_SERVER, 608, E_INFO, EV_USAGE, 1), "Rotating journal for %name% server..." }; ErrorId CtlErr::NoServersConfigured = { ErrorOf( ES_SERVER, 609, E_INFO, EV_USAGE, 0), "No servers configured." }; ErrorId CtlErr::UsageMain = { ErrorOf( ES_SERVER, 650, E_INFO, EV_USAGE, 0), "\n" "Usage: p4dctl [global flags] <cmd> [flags] [server name]\n" "\n" "Global Flags\n" "------------\n" "\n" "-c <cfg_file> - Path to config file. Default: /etc/perforce/p4dctl.conf\n" "-p <pid_dir> - Path to pid file directory. Default: /var/run\n" "-q - Send output to syslog instead of stdout/stderr\n" "-v <level> - Set debug level to <level> (1-9)\n" "-V - Print version and exit\n" "\n" "Commands\n" "--------\n" "\n" "list - List configured server(s)\n" "start - Start the specified server(s)\n" "stop - Stop the specified server(s)\n" "restart - Restart the specified server(s)\n" "status - Check the status of the specified server(s)\n" "checkpoint - Checkpoint the specified p4d server(s)\n" "journal - Rotate p4d server(s) journal file\n" "env - Query the environment of servers\n" "\n" }; ErrorId CtlErr::UsageStart = { ErrorOf( ES_SERVER, 651, E_INFO, EV_USAGE, 0), "\n" "Usage: p4dctl start [-t <type>] [-o <options>] <server name>\n" " p4dctl start [-t <type>] [-o <options>] -a\n" "\n" "Without the -a flag, starts a specific server; with the -a flag, starts\n" "all configured servers that the running user has permission to start.\n" "\n" "If the -t flag is specified, then only servers of the specified type\n" "will be started.\n" "\n" "If the -o flag is specified, then the specified option is appended to the\n" "arguments passed to the service on start. The option must be quoted if it\n" "consists of multiple arguments.\n" "\n" }; ErrorId CtlErr::UsageStop = { ErrorOf( ES_SERVER, 652, E_INFO, EV_USAGE, 0), "\n" "Usage: p4dctl stop [-t <type>] <server name>\n" " p4dctl stop [-t <type>] -a\n" "\n" "Without the -a flag, stops a specific server; with the -a flag, stops\n" "all configured servers that the running user has permission to stop.\n" "\n" "If the -t flag is specified, then only servers of the specified type\n" "will be stopped.\n" "\n" }; ErrorId CtlErr::UsageRestart = { ErrorOf( ES_SERVER, 653, E_INFO, EV_USAGE, 0), "\n" "Usage: p4dctl restart [-t <type>] [-o <options>] <server name>\n" " p4dctl restart [-t <type>] [-o <options>] -a\n" "\n" "Without the -a flag, restarts a specific server; with the -a flag, restarts\n" "all configured servers that the running user has permission to restart.\n" "\n" "If the -t flag is specified, then only servers of the specified type\n" "will be restarted.\n" "\n" "If the -o flag is specified, then the specified option is appended to the\n" "arguments passed to the service on start. The option must be quoted if it\n" "consists of multiple arguments.\n" "\n" }; ErrorId CtlErr::UsageStatus = { ErrorOf( ES_SERVER, 654, E_INFO, EV_USAGE, 0), "\n" "Usage: p4dctl status [-t <type>] <server name>\n" " p4dctl status [-t <type>] -a\n" "\n" "Without the -a flag, checks a specific server; with the -a flag, checks\n" "all configured servers that the running user has permission to check.\n" "\n" "If the -t flag is specified, then only servers of the specified type\n" "will be checked.\n" "\n" }; ErrorId CtlErr::UsageCheckpoint = { ErrorOf( ES_SERVER, 655, E_INFO, EV_USAGE, 0), "\n" "Usage: p4dctl checkpoint <server name>\n" " p4dctl checkpoint -a\n" "\n" "Without the -a flag, checkpoints a specific p4d server; with the -a flag,\n" "checkpoints all configured p4d servers that the running user has permission\n" "to checkpoint.\n" "\n" }; ErrorId CtlErr::UsageJournal = { ErrorOf( ES_SERVER, 656, E_INFO, EV_USAGE, 0), "\n" "Usage: p4dctl journal <server name>\n" " p4dctl journal -a\n" "\n" "Without the -a flag, rotates the journal of a specific p4d server; with the\n" "-a flag, rotates the journals of all configured p4d servers that the running\n" "user has permission to administer.\n" "\n" }; ErrorId CtlErr::UsageList = { ErrorOf( ES_SERVER, 657, E_INFO, EV_USAGE, 0), "\n" "Usage: p4dctl list [-t <type>]\n" "\n" "Lists all configured servers of the specified type. If <type> is not\n" "specified, lists all servers of all types that the running user has\n" "permission to administer.\n" "\n" }; ErrorId CtlErr::UsageEnv = { ErrorOf( ES_SERVER, 658, E_INFO, EV_USAGE, 0), "\n" "Usage: p4dctl env [-a | <name>] [-t <type>] <var> ...\n" "\n" "Prints the values of variables <var> for each of the servers\n" "matching either the specified <name> or <type> (or all servers\n" "if -a is supplied) provided that the user has permission to access\n" "them.\n" "\n" };
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 16543 | Matt Attaway | Update P4DCTL with code from 15.2 and reorg files | ||
//guest/perforce_software/p4dctl/src/p4dctlerr.cpp | |||||
#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/p4dctlerr.cpp | |||||
#3 | 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 |
||
#2 | 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. |
||
#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. |