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 + + + + + + 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 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); + " [-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__) + case 'S': + set_starttype(optarg); + break; +#endif case 't': wait_seconds = atoi(optarg); break;