3
# Copyright 2008-2015 Canonical
4
# Copyright 2015 Chicharreros (https://launchpad.net/~chicharreros)
6
# This program is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU Affero General Public License as
8
# published by the Free Software Foundation, either version 3 of the
9
# License, or (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU Affero General Public License for more details.
16
# You should have received a copy of the GNU Affero General Public License
17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19
# For further info, check http://launchpad.net/magicicada-server
21
"""Script to start Postgres."""
26
import utilities.localendpoints as local
28
from utilities.utils import os_exec, is_running
33
sock_dir = os.environ.get('PG_HOST', '/dev/shm/pg_magicicada')
34
data_dir = os.path.join(sock_dir, "data")
35
pidfile = os.path.join(data_dir, "postmaster.pid")
37
if is_running("postgres", pidfile, "postgres"):
38
print "Postgres already up & running."
42
for path in ("/usr/lib/postgresql/9.5/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__':