3
# Copyright 2008-2015 Canonical
5
# This program is free software: you can redistribute it and/or modify
6
# it under the terms of the GNU Affero General Public License as
7
# published by the Free Software Foundation, either version 3 of the
8
# License, or (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU Affero General Public License for more details.
15
# You should have received a copy of the GNU Affero General Public License
16
# along with this program. If not, see <http://www.gnu.org/licenses/>.
18
# For further info, check http://launchpad.net/filesync-server
20
"""Script to start Postgres."""
25
import utilities.localendpoints as local
27
from utilities.utils import os_exec, is_running, get_tmpdir
32
sock_dir = os.path.join(get_tmpdir(), "db1")
33
data_dir = os.path.join(sock_dir, "data")
34
pidfile = os.path.join(data_dir, "postmaster.pid")
36
if is_running("postgres", pidfile, "postgres"):
37
print "Postgres already up & running."
41
for path in ("/usr/lib/postgresql/9.1/bin",
42
"/usr/lib/postgresql/8.4/bin"):
43
if os.path.isdir(path):
48
print "Cannot find valid parent for PGBINDIR"
51
pg_port = local.allocate_ports(1)[0]
52
local.register_local_port("postgres", pg_port)
53
os_exec(os.path.join(pg_bin, "postgres"),
56
"-i", "-h", "127.0.0.1",
59
if __name__ == '__main__':