Re: [HACKERS] Fw: patch for pg_ctl.c to add windows service start-type
On Thu, Sep 30, 2010 at 04:40, Itagaki Takahiro wrote: > Hi, I have a question about the latest patch. > > On Sun, Aug 22, 2010 at 11:03 PM, Quan Zongliang > wrote: >> New patch attached. How about this? >>> I don't see us ever using anything other than auto or demand. The >>> others aren't for "regular services" > > + 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; > > It accepts only "a" and "auto" for auto, but "au" or "aut" are rejected. > Is is an intended behavior? I think we can use prefix match here because > we use the logic in some places. For example, I think it's modeled on what we allow for the "-m" parameter, and ISTM it's good to keep those consistent. -- Magnus Hagander Me: http://www.hagander.net/ Work: http://www.redpill-linpro.com/ -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers
Re: [HACKERS] Fw: patch for pg_ctl.c to add windows service start-type
Hi, I have a question about the latest patch. On Sun, Aug 22, 2010 at 11:03 PM, Quan Zongliang wrote: > New patch attached. How about this? >> I don't see us ever using anything other than auto or demand. The >> others aren't for "regular services" + 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; It accepts only "a" and "auto" for auto, but "au" or "aut" are rejected. Is is an intended behavior? I think we can use prefix match here because we use the logic in some places. For example, postgres=# SELECT 'tru'::bool, 'fal'::bool; bool | bool --+-- t| f (1 row) -- Itagaki Takahiro -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers
Re: [HACKERS] Fw: patch for pg_ctl.c to add windows service start-type
On Tue, Aug 24, 2010 at 2:05 PM, Quan Zongliang wrote: > Which files need be modified? > sgml, html, and man-page or only sgml? > I am not familiar with this. Only SGML. HTML and man pages are generated from the SGML. -- Magnus Hagander Me: http://www.hagander.net/ Work: http://www.redpill-linpro.com/ -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers
Re: [HACKERS] Fw: patch for pg_ctl.c to add windows service start-type
Which files need be modified? sgml, html, and man-page or only sgml? I am not familiar with this. On Sun, 22 Aug 2010 08:25:59 -0700 David Fetter wrote: > On Sun, Aug 22, 2010 at 10:03:32PM +0800, Quan Zongliang wrote: > > Sure, I agree. > > New patch attached. How about this? > > Docs re-added. Please not to leave these out in future patches. :) > > Cheers, > David. > -- > David Fetter http://fetter.org/ > Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter > Skype: davidfetter XMPP: david.fet...@gmail.com > iCal: webcal://www.tripit.com/feed/ical/people/david74/tripit.ics > > Remember to vote! > Consider donating to Postgres: http://www.postgresql.org/about/donate -- Quan Zongliang -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers
Re: [HACKERS] Fw: patch for pg_ctl.c to add windows service start-type
On Sun, Aug 22, 2010 at 10:03:32PM +0800, Quan Zongliang wrote: > Sure, I agree. > New patch attached. How about this? Docs re-added. Please not to leave these out in future patches. :) Cheers, David. -- David Fetter http://fetter.org/ Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter Skype: davidfetter XMPP: david.fet...@gmail.com iCal: webcal://www.tripit.com/feed/ical/people/david74/tripit.ics Remember to vote! Consider donating to Postgres: http://www.postgresql.org/about/donate diff --git a/doc/src/sgml/ref/pg_ctl-ref.sgml b/doc/src/sgml/ref/pg_ctl-ref.sgml index 20d87bb..ac30320 100644 --- a/doc/src/sgml/ref/pg_ctl-ref.sgml +++ b/doc/src/sgml/ref/pg_ctl-ref.sgml @@ -97,6 +97,12 @@ PostgreSQL documentation -P password -D datadir -w + -S + + a[uto] + d[emand] + + -t seconds -o options @@ -377,6 +383,18 @@ PostgreSQL documentation + + + -S start-type + + + Start type of the system service to register. start-type can + be auto, or demand, or + the first letter of one of these two. If this is omitted, + auto is used. + + + diff --git a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c index 1caec12..f7de2a5 100644 --- a/src/bin/pg_ctl/pg_ctl.c +++ b/src/bin/pg_ctl/pg_ctl.c @@ -121,6 +121,7 @@ static void WINAPI pgwin32_ServiceMain(DWORD, LPTSTR *); 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,7 +1148,7 @@ pgwin32_doRegister(void) if ((hService = CreateService(hSCM, register_servicename, register_servicename, SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS, - SERVICE_AUTO_START, SERVICE_ERROR_NORMAL, + pgctl_start_type, SERVICE_ERROR_NORMAL, pgwin32_CommandLine(true), NULL, NULL, "RPCSS\0", register_username, register_password)) == NULL) { @@ -1586,7 +1587,7 @@ do_help(void) printf(_(" %s killSIGNALNAME 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); +"[-S START-TYPE] [-w] [-t SECS] [-o \"OPTIONS\"]\n"), progname); printf(_(" %s unregister [-N SERVICENAME]\n"), progname); #endif @@ -1627,6 +1628,11 @@ do_help(void) 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 .\n")); @@ -1696,6 +1702,25 @@ set_sig(char *signame) +#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,7 +1797,7 @@ main(int argc, char **argv) /* 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) + 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,6 +1844,11 @@ main(int argc, char **argv) case 's': silent_mode = true; break; +#if defined(WIN32) || defined(__CYGWIN_
Re: [HACKERS] Fw: patch for pg_ctl.c to add windows service start-type
Sure, I agree. New patch attached. How about this? On Fri, 20 Aug 2010 11:21:18 +0200 Magnus Hagander wrote: > On Fri, Aug 20, 2010 at 01:01, Quan Zongliang 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 *** pg_ctl.c.bak2010-04-07 11:48:51.0 +0800 --- pg_ctl.c2010-08-22 20:15:53.37500 +0800 *** *** 121,126 --- 121,127 static void pgwin32_doRunAsService(void); static intCreateRestrictedProcess(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 killSIGNALNAME 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 killSIGNALNAME 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 .\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
Re: [HACKERS] Fw: patch for pg_ctl.c to add windows service start-type
On Fri, Aug 20, 2010 at 01:01, Quan Zongliang 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/ -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers
Re: [HACKERS] Fw: patch for pg_ctl.c to add windows service start-type
I don't know how to edit documents exactly before. Thanks. On Thu, 19 Aug 2010 08:48:53 -0700 David Fetter wrote: > On Thu, Aug 19, 2010 at 10:24:54PM +0800, Quan Zongliang wrote: > > documents attached. html and man-page > > Thanks! > > For future reference, the way to patch docs is by patching the SGML > source. Please find enclosed a patch which incorporates the code > patch you sent with these docs. > > Cheers, > David. > -- > David Fetter http://fetter.org/ > Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter > Skype: davidfetter XMPP: david.fet...@gmail.com > iCal: webcal://www.tripit.com/feed/ical/people/david74/tripit.ics > > Remember to vote! > Consider donating to Postgres: http://www.postgresql.org/about/donate -- Quan Zongliang -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers
Re: [HACKERS] Fw: patch for pg_ctl.c to add windows service start-type
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. On Thu, 19 Aug 2010 16:48:53 -0400 Alvaro Herrera wrote: > Excerpts from David Fetter's message of jue ago 19 16:40:18 -0400 2010: > > On Thu, Aug 19, 2010 at 03:47:43PM -0400, Alvaro Herrera wrote: > > > Excerpts from David Fetter's message of jue ago 19 11:48:53 -0400 2010: > > > > > > > + > > > > + -S > > > class="parameter"> > > > > > > You omitted the start-type inside the tag. Also, the "a" > > > and "d" values seem to be accepted but not documented. > > > > D'oh! Changed patch enclosed. Now in context format :) > > Thanks. > > Another thing -- why is there an enum at all? Seems it'd be > simpler to assign the right value to the variable in the getopt() code > to start with. > > -- > Álvaro Herrera > The PostgreSQL Company - Command Prompt, Inc. > PostgreSQL Replication, Consulting, Custom Development, 24x7 support -- Quan Zongliang -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers
Re: [HACKERS] Fw: patch for pg_ctl.c to add windows service start-type
On Thu, Aug 19, 2010 at 04:48:53PM -0400, Alvaro Herrera wrote: > Excerpts from David Fetter's message of jue ago 19 16:40:18 -0400 2010: > > On Thu, Aug 19, 2010 at 03:47:43PM -0400, Alvaro Herrera wrote: > > > Excerpts from David Fetter's message of jue ago 19 11:48:53 -0400 2010: > > > > > > > + > > > > + -S > > > class="parameter"> > > > > > > You omitted the start-type inside the tag. Also, > > > the "a" and "d" values seem to be accepted but not documented. > > > > D'oh! Changed patch enclosed. Now in context format :) > > Thanks. > > Another thing -- why is there an enum at all? Seems it'd be simpler > to assign the right value to the variable in the getopt() code to > start with. That's a question for the patch author. I was just cleaning up the docs :) Cheers, David. -- David Fetter http://fetter.org/ Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter Skype: davidfetter XMPP: david.fet...@gmail.com iCal: webcal://www.tripit.com/feed/ical/people/david74/tripit.ics Remember to vote! Consider donating to Postgres: http://www.postgresql.org/about/donate -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers
Re: [HACKERS] Fw: patch for pg_ctl.c to add windows service start-type
Excerpts from David Fetter's message of jue ago 19 16:40:18 -0400 2010: > On Thu, Aug 19, 2010 at 03:47:43PM -0400, Alvaro Herrera wrote: > > Excerpts from David Fetter's message of jue ago 19 11:48:53 -0400 2010: > > > > > + > > > + -S > > class="parameter"> > > > > You omitted the start-type inside the tag. Also, the "a" > > and "d" values seem to be accepted but not documented. > > D'oh! Changed patch enclosed. Now in context format :) Thanks. Another thing -- why is there an enum at all? Seems it'd be simpler to assign the right value to the variable in the getopt() code to start with. -- Álvaro Herrera The PostgreSQL Company - Command Prompt, Inc. PostgreSQL Replication, Consulting, Custom Development, 24x7 support -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers
Re: [HACKERS] Fw: patch for pg_ctl.c to add windows service start-type
On Thu, Aug 19, 2010 at 03:47:43PM -0400, Alvaro Herrera wrote: > Excerpts from David Fetter's message of jue ago 19 11:48:53 -0400 2010: > > > + > > + -S > class="parameter"> > > You omitted the start-type inside the tag. Also, the "a" > and "d" values seem to be accepted but not documented. D'oh! Changed patch enclosed. Now in context format :) Cheers, David. -- David Fetter http://fetter.org/ Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter Skype: davidfetter XMPP: david.fet...@gmail.com iCal: webcal://www.tripit.com/feed/ical/people/david74/tripit.ics Remember to vote! Consider donating to Postgres: http://www.postgresql.org/about/donate *** a/doc/src/sgml/ref/pg_ctl-ref.sgml --- b/doc/src/sgml/ref/pg_ctl-ref.sgml *** *** 96,101 PostgreSQL documentation --- 96,107 -U username -P password -D datadir +-S + +a[uto] +d[emand] + + -w -t seconds -o options *** *** 377,382 PostgreSQL documentation --- 383,400 + + + -S start-type + + +Start type of the system service to register. start-type can +be auto, or demand, or +the first letter of one of these two. If this is omitted, +auto is used. + + + *** a/src/bin/pg_ctl/pg_ctl.c --- b/src/bin/pg_ctl/pg_ctl.c *** *** 69,74 typedef enum --- 69,82 RUN_AS_SERVICE_COMMAND } CtlCommand; + + typedef enum + { + PGCTL_START_AUTO, + PGCTL_START_DEMAND + } PgctlWin32StartType; + + #define DEFAULT_WAIT 60 static bool do_wait = false; *** *** 87,92 static char *exec_path = NULL; --- 95,101 static char *register_servicename = "PostgreSQL"; /* FIXME: + version ID? */ static char *register_username = NULL; static char *register_password = NULL; + static PgctlWin32StartType win32_start_type = PGCTL_START_AUTO; static char *argv0 = NULL; static bool allow_core_files = false; *** *** 1132,1137 pgwin32_doRegister(void) --- 1141,1147 { SC_HANDLE hService; SC_HANDLE hSCM = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); + DWORD starttype; if (hSCM == NULL) { *** *** 1145,1153 pgwin32_doRegister(void) exit(1); } 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) { --- 1155,1168 exit(1); } + if (win32_start_type == PGCTL_START_AUTO) + starttype = SERVICE_AUTO_START; + else + starttype = SERVICE_DEMAND_START; + if ((hService = CreateService(hSCM, register_servicename, register_servicename, SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS, ! starttype, SERVICE_ERROR_NORMAL, pgwin32_CommandLine(true), NULL, NULL, "RPCSS\0", register_username, register_password)) == NULL) { *** *** 1586,1592 do_help(void) printf(_(" %s killSIGNALNAME 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 --- 1601,1607 printf(_(" %s killSIGNALNAME 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 do_help(void) --- 1642,1654 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")); + +
Re: [HACKERS] Fw: patch for pg_ctl.c to add windows service start-type
Excerpts from David Fetter's message of jue ago 19 11:48:53 -0400 2010: > + > + -S class="parameter"> You omitted the start-type inside the tag. Also, the "a" and "d" values seem to be accepted but not documented. -- Álvaro Herrera The PostgreSQL Company - Command Prompt, Inc. PostgreSQL Replication, Consulting, Custom Development, 24x7 support -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers
Re: [HACKERS] Fw: patch for pg_ctl.c to add windows service start-type
On Thu, Aug 19, 2010 at 10:24:54PM +0800, Quan Zongliang wrote: > documents attached. html and man-page Thanks! For future reference, the way to patch docs is by patching the SGML source. Please find enclosed a patch which incorporates the code patch you sent with these docs. Cheers, David. -- David Fetter http://fetter.org/ Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter Skype: davidfetter XMPP: david.fet...@gmail.com iCal: webcal://www.tripit.com/feed/ical/people/david74/tripit.ics Remember to vote! Consider donating to Postgres: http://www.postgresql.org/about/donate diff --git a/doc/src/sgml/ref/pg_ctl-ref.sgml b/doc/src/sgml/ref/pg_ctl-ref.sgml index 20d87bb..a4e675e 100644 --- a/doc/src/sgml/ref/pg_ctl-ref.sgml +++ b/doc/src/sgml/ref/pg_ctl-ref.sgml @@ -377,6 +377,18 @@ PostgreSQL documentation + + + -S + + + Start type of the system service to register. start-type can + be auto, or demand, or + the first letter of one of these two. If this is omitted, + auto is used. + + + diff --git a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c index 1caec12..42a8aa9 100644 --- a/src/bin/pg_ctl/pg_ctl.c +++ b/src/bin/pg_ctl/pg_ctl.c @@ -69,6 +69,14 @@ typedef enum RUN_AS_SERVICE_COMMAND } CtlCommand; + +typedef enum +{ + PGCTL_START_AUTO, + PGCTL_START_DEMAND +} PgctlWin32StartType; + + #define DEFAULT_WAIT 60 static bool do_wait = false; @@ -87,6 +95,7 @@ static char *exec_path = NULL; static char *register_servicename = "PostgreSQL"; /* FIXME: + version ID? */ static char *register_username = NULL; static char *register_password = NULL; +static PgctlWin32StartType win32_start_type = PGCTL_START_AUTO; static char *argv0 = NULL; static bool allow_core_files = false; @@ -1132,6 +1141,7 @@ pgwin32_doRegister(void) { SC_HANDLE hService; SC_HANDLE hSCM = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); + DWORD starttype; if (hSCM == NULL) { @@ -1145,9 +1155,14 @@ pgwin32_doRegister(void) exit(1); } + if (win32_start_type == PGCTL_START_AUTO) + starttype = SERVICE_AUTO_START; + else + starttype = SERVICE_DEMAND_START; + if ((hService = CreateService(hSCM, register_servicename, register_servicename, SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS, - SERVICE_AUTO_START, SERVICE_ERROR_NORMAL, + starttype, SERVICE_ERROR_NORMAL, pgwin32_CommandLine(true), NULL, NULL, "RPCSS\0", register_username, register_password)) == NULL) { @@ -1586,7 +1601,7 @@ do_help(void) printf(_(" %s killSIGNALNAME 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); +"[-S START-TYPE] [-w] [-t SECS] [-o \"OPTIONS\"]\n"), progname); printf(_(" %s unregister [-N SERVICENAME]\n"), progname); #endif @@ -1627,6 +1642,13 @@ do_help(void) 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 .\n")); @@ -1696,6 +1718,25 @@ set_sig(char *signame) +#if defined(WIN32) || defined(__CYGWIN__) +static void +set_starttype(char *starttypeopt) +{ + if (strcmp(starttypeopt, "a") == 0 || strcmp(starttypeopt, "auto") == 0) + win32_start_type = PGCTL_START_AUTO; + else if (strcmp(starttypeopt, "d") == 0 || strcmp(starttypeopt, "demand") == 0) + win32_start_type = PGCTL_START_DEMAND; + else + { + write_stderr(_("%s: unrecognized start type \"%s\"\n"), progname, starttypeopt); + do_advice(); + exit(1); + } +} +#endif + + + int main(int argc, char **argv) { @@ -1772,7 +1813,7 @@ main(int argc, char **argv) /* process command-line options */ while (optind < argc) { - while ((c = getopt_
Re: [HACKERS] Fw: patch for pg_ctl.c to add windows service start-type
On Tue, Aug 17, 2010 at 2:58 PM, Quan Zongliang wrote: > > Sorry. > I forget to attach the patch file. Without looking at the details of this patch, it looks reasonable - so please put it on the commitfest page, if you haven't already. It does, however, lack documentation updates - that needs to be done before it can get applied. -- Magnus Hagander Me: http://www.hagander.net/ Work: http://www.redpill-linpro.com/ -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers
[HACKERS] Fw: patch for pg_ctl.c to add windows service start-type
Sorry. I forget to attach the patch file. Begin forwarded message: Date: Mon, 16 Aug 2010 19:49:20 +0800 From: Quan Zongliang To: pgsql-hackers@postgresql.org Subject: patch for pg_ctl.c to add windows service start-type Hi, all I modified pg_ctl.c to add a new option for Windows service start-type. new option is -S [auto|demand] For example, the command can be used under Windows: pg_ctl register -N "s-name" -S auto or pg_ctl register -N "s-name" -S demand The created service will be SERVICE_AUTO_START or SERVICE_DEMAND_START respectively. regards -- Quan Zongliang -- Quan Zongliang pg_ctl.patch Description: Binary data -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers