*** pgsql_init.8d83e5030d44/src/bin/pg_ctl/pg_ctl.c 2009-09-17 21:42:20.865268360 +0200 --- /export/home/zk200664/work/mercurial/pgsql_init/src/bin/pg_ctl/pg_ctl.c 2009-09-17 21:15:04.630265322 +0200 *************** *** 57,62 **** --- 57,63 ---- typedef enum { NO_COMMAND = 0, + INIT_COMMAND, START_COMMAND, STOP_COMMAND, RESTART_COMMAND, *************** *** 100,105 **** --- 101,107 ---- static void do_help(void); static void set_mode(char *modeopt); static void set_sig(char *signame); + static void do_init(void); static void do_start(void); static void do_stop(void); static void do_restart(void); *************** *** 615,620 **** --- 617,655 ---- } static void + do_init(void) + { + char pg_initdb[MAXPGPATH]; + char cmd[MAXPGPATH]; + int ret; + + if ((ret = find_other_exec(argv0, "initdb", "initdb (PostgreSQL) " PG_VERSION "\n", + pg_initdb)) < 0) + + { + write_stderr(_("%s: could not find initdb\n"), + progname); + exit(1); + } + + if (post_opts == NULL) + post_opts = ""; + + if (!silent_mode) + snprintf(cmd, MAXPGPATH, SYSTEMQUOTE "\"%s\" %s%s" SYSTEMQUOTE, + pg_initdb, pgdata_opt, post_opts); + else + snprintf(cmd, MAXPGPATH, SYSTEMQUOTE "\"%s\" %s%s > \"%s\"" SYSTEMQUOTE, + pg_initdb, pgdata_opt, post_opts, DEVNULL); + + if ( system(cmd) != 0 ) + { + write_stderr(_("%s: database initialization failed.\n"), progname); + exit(1); + } + } + + static void do_start(void) { pgpid_t pid; *************** *** 694,700 **** progname, exitcode); exit(1); } - if (old_pid != 0) { pg_usleep(1000000); --- 729,734 ---- *************** *** 1535,1540 **** --- 1569,1575 ---- printf(_("%s is a utility to start, stop, restart, reload configuration files,\n" "report the status of a PostgreSQL server, or signal a PostgreSQL process.\n\n"), progname); printf(_("Usage:\n")); + printf(_(" %s init [-D DATADIR] [-s] [-o \"OPTIONS\"]\n"), progname); printf(_(" %s start [-w] [-t SECS] [-D DATADIR] [-s] [-l FILENAME] [-o \"OPTIONS\"]\n"), progname); printf(_(" %s stop [-W] [-t SECS] [-D DATADIR] [-s] [-m SHUTDOWN-MODE]\n"), progname); printf(_(" %s restart [-w] [-t SECS] [-D DATADIR] [-s] [-m SHUTDOWN-MODE]\n" *************** *** 1567,1573 **** #endif printf(_(" -l, --log FILENAME write (or append) server log to FILENAME\n")); printf(_(" -o OPTIONS command line options to pass to postgres\n" ! " (PostgreSQL server executable)\n")); printf(_(" -p PATH-TO-POSTGRES normally not necessary\n")); printf(_("\nOptions for stop or restart:\n")); printf(_(" -m SHUTDOWN-MODE can be \"smart\", \"fast\", or \"immediate\"\n")); --- 1602,1608 ---- #endif printf(_(" -l, --log FILENAME write (or append) server log to FILENAME\n")); printf(_(" -o OPTIONS command line options to pass to postgres\n" ! " (PostgreSQL server executable) or initdb\n")); printf(_(" -p PATH-TO-POSTGRES normally not necessary\n")); printf(_("\nOptions for stop or restart:\n")); printf(_(" -m SHUTDOWN-MODE can be \"smart\", \"fast\", or \"immediate\"\n")); *************** *** 1824,1830 **** exit(1); } ! if (strcmp(argv[optind], "start") == 0) ctl_command = START_COMMAND; else if (strcmp(argv[optind], "stop") == 0) ctl_command = STOP_COMMAND; --- 1859,1867 ---- exit(1); } ! if (strcmp(argv[optind], "init") == 0) ! ctl_command = INIT_COMMAND; ! else if (strcmp(argv[optind], "start") == 0) ctl_command = START_COMMAND; else if (strcmp(argv[optind], "stop") == 0) ctl_command = STOP_COMMAND; *************** *** 1921,1926 **** --- 1958,1966 ---- switch (ctl_command) { + case INIT_COMMAND: + do_init(); + break; case STATUS_COMMAND: do_status(); break;