Sure, I agree.
New patch attached. How about this?
On Fri, 20 Aug 2010 11:21:18 +0200
Magnus Hagander <[email protected]> wrote:
> On Fri, Aug 20, 2010 at 01:01, Quan Zongliang <[email protected]> wrote:
> > Because Windows's CreateService has serial start-type:
> > SERVICE_AUTO_START
> > SERVICE_BOOT_START
> > SERVICE_DEMAND_START
> > SERVICE_DISABLED
> > SERVICE_SYSTEM_START
> >
> > Although all of them are not useful for pg service.
> > I think it is better to use enum.
>
> I don't see us ever using anything other than auto or demand. The
> others aren't for "regular services", except for "disabled". And
> adding a disabled service makes no sense :-) So I'm with Alvaro, I
> think it's a good idea to simplify that.
>
>
> --
> Magnus Hagander
> Me: http://www.hagander.net/
> Work: http://www.redpill-linpro.com/
--
Quan Zongliang <[email protected]>
*** pg_ctl.c.bak 2010-04-07 11:48:51.000000000 +0800
--- pg_ctl.c 2010-08-22 20:15:53.375000000 +0800
***************
*** 121,126 ****
--- 121,127 ----
static void pgwin32_doRunAsService(void);
static int CreateRestrictedProcess(char *cmd, PROCESS_INFORMATION
*processInfo, bool as_service);
+ static DWORD pgctl_start_type = SERVICE_AUTO_START;
static SERVICE_STATUS status;
static SERVICE_STATUS_HANDLE hStatus = (SERVICE_STATUS_HANDLE) 0;
static HANDLE shutdownHandles[2];
***************
*** 1147,1153 ****
if ((hService = CreateService(hSCM, register_servicename,
register_servicename,
SERVICE_ALL_ACCESS,
SERVICE_WIN32_OWN_PROCESS,
!
SERVICE_AUTO_START, SERVICE_ERROR_NORMAL,
pgwin32_CommandLine(true),
NULL, NULL, "RPCSS\0", register_username, register_password)) ==
NULL)
{
--- 1148,1154 ----
if ((hService = CreateService(hSCM, register_servicename,
register_servicename,
SERVICE_ALL_ACCESS,
SERVICE_WIN32_OWN_PROCESS,
!
pgctl_start_type, SERVICE_ERROR_NORMAL,
pgwin32_CommandLine(true),
NULL, NULL, "RPCSS\0", register_username, register_password)) ==
NULL)
{
***************
*** 1586,1592 ****
printf(_(" %s kill SIGNALNAME PID\n"), progname);
#if defined(WIN32) || defined(__CYGWIN__)
printf(_(" %s register [-N SERVICENAME] [-U USERNAME] [-P PASSWORD]
[-D DATADIR]\n"
! " [-w] [-t SECS] [-o \"OPTIONS\"]\n"),
progname);
printf(_(" %s unregister [-N SERVICENAME]\n"), progname);
#endif
--- 1587,1593 ----
printf(_(" %s kill SIGNALNAME PID\n"), progname);
#if defined(WIN32) || defined(__CYGWIN__)
printf(_(" %s register [-N SERVICENAME] [-U USERNAME] [-P PASSWORD]
[-D DATADIR]\n"
! " [-S START-TYPE] [-w] [-t SECS] [-o
\"OPTIONS\"]\n"), progname);
printf(_(" %s unregister [-N SERVICENAME]\n"), progname);
#endif
***************
*** 1627,1632 ****
--- 1628,1640 ----
printf(_(" -N SERVICENAME service name with which to register
PostgreSQL server\n"));
printf(_(" -P PASSWORD password of account to register PostgreSQL
server\n"));
printf(_(" -U USERNAME user name of account to register PostgreSQL
server\n"));
+ printf(_(" -S START-TYPE service start type to register PostgreSQL
server,\n"
+ " can be auto or demand\n"));
+
+ printf(_("\nStart types are:\n"));
+ printf(_(" auto service start automatically during system
startup\n"));
+ printf(_(" demand service start on demand\n"));
+
#endif
printf(_("\nReport bugs to <[email protected]>.\n"));
***************
*** 1696,1701 ****
--- 1704,1728 ----
+ #if defined(WIN32) || defined(__CYGWIN__)
+ static void
+ set_starttype(char *starttypeopt)
+ {
+ if (strcmp(starttypeopt, "a") == 0 || strcmp(starttypeopt, "auto") == 0)
+ pgctl_start_type = SERVICE_AUTO_START;
+ else if (strcmp(starttypeopt, "d") == 0 || strcmp(starttypeopt,
"demand") == 0)
+ pgctl_start_type = SERVICE_DEMAND_START;
+ else
+ {
+ write_stderr(_("%s: unrecognized start type \"%s\"\n"),
progname, starttypeopt);
+ do_advice();
+ exit(1);
+ }
+ }
+ #endif
+
+
+
int
main(int argc, char **argv)
{
***************
*** 1772,1778 ****
/* process command-line options */
while (optind < argc)
{
! while ((c = getopt_long(argc, argv, "cD:l:m:N:o:p:P:st:U:wW",
long_options, &option_index)) != -1)
{
switch (c)
{
--- 1799,1805 ----
/* process command-line options */
while (optind < argc)
{
! while ((c = getopt_long(argc, argv, "cD:l:m:N:o:p:P:sS:t:U:wW",
long_options, &option_index)) != -1)
{
switch (c)
{
***************
*** 1819,1824 ****
--- 1846,1856 ----
case 's':
silent_mode = true;
break;
+ #if defined(WIN32) || defined(__CYGWIN__)
+ case 'S':
+ set_starttype(optarg);
+ break;
+ #endif
case 't':
wait_seconds = atoi(optarg);
break;
--
Sent via pgsql-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers