2 * $Header: /cvsroot/pgpool/pgpool-II/pcp/pcp_stop_pgpool.c,v 1.3 2008/12/31 10:25:40 t-ishii Exp $
4 * pgpool: a language independent connection pool server for PostgreSQL
5 * written by Tatsuo Ishii
7 * Copyright (c) 2003-2008 PgPool Global Development Group
9 * Permission to use, copy, modify, and distribute this software and
10 * its documentation for any purpose and without fee is hereby
11 * granted, provided that the above copyright notice appear in all
12 * copies and that both that copyright notice and this permission
13 * notice appear in supporting documentation, and that the name of the
14 * author not be used in advertising or publicity pertaining to
15 * distribution of the software without specific, written prior
16 * permission. The author makes no representations about the
17 * suitability of this software for any purpose. It is provided "as
18 * is" without express or implied warranty.
20 * Client program to send "stop pgpool" command.
30 static void usage(void);
31 static void myexit(ErrorCode e);
34 main(int argc, char **argv)
37 char host[MAX_DB_HOST_NAMELEN];
39 char user[MAX_USER_PASSWD_LEN];
40 char pass[MAX_USER_PASSWD_LEN];
44 while ((ch = getopt(argc, argv, "hd")) != -1) {
63 pcp_errorstr(errorcode);
67 timeout = atol(argv[0]);
70 pcp_errorstr(errorcode);
74 if (strlen(argv[1]) >= MAX_DB_HOST_NAMELEN)
77 pcp_errorstr(errorcode);
80 strcpy(host, argv[1]);
83 if (port <= 1024 || port > 65535)
86 pcp_errorstr(errorcode);
90 if (strlen(argv[3]) >= MAX_USER_PASSWD_LEN)
93 pcp_errorstr(errorcode);
96 strcpy(user, argv[3]);
98 if (strlen(argv[4]) >= MAX_USER_PASSWD_LEN)
100 errorcode = INVALERR;
101 pcp_errorstr(errorcode);
104 strcpy(pass, argv[4]);
106 if (strlen(argv[5]) != 1)
108 errorcode = INVALERR;
109 pcp_errorstr(errorcode);
113 if (mode != 's' && mode != 'f' && mode != 'i')
115 errorcode = INVALERR;
116 pcp_errorstr(errorcode);
120 pcp_set_timeout(timeout);
122 if (pcp_connect(host, port, user, pass))
124 pcp_errorstr(errorcode);
128 if (pcp_terminate_pgpool(mode))
130 pcp_errorstr(errorcode);
134 // display something on success?
145 fprintf(stderr, "pcp_stop_pgpool - terminate pgpool-II\n\n");
146 fprintf(stderr, "Usage: pcp_stop_pgpool [-d] timeout hostname port# username password mode\n");
147 fprintf(stderr, "Usage: pcp_stop_pgpool -h\n\n");
148 fprintf(stderr, " -d - enable debug message (optional)\n");
149 fprintf(stderr, " timeout - connection timeout value in seconds. command exits on timeout\n");
150 fprintf(stderr, " hostname - pgpool-II hostname\n");
151 fprintf(stderr, " port# - pgpool-II port number\n");
152 fprintf(stderr, " username - username for PCP authentication\n");
153 fprintf(stderr, " password - password for PCP authentication\n");
154 fprintf(stderr, " mode - shutdown mode\n");
155 fprintf(stderr, " s - smart shutdown f - fast shutdown i - immediate shutdown\n");
156 fprintf(stderr, " -h - print this help\n");