~facundo/magicicada-server/better-settings-local

« back to all changes in this revision

Viewing changes to src/backends/db/scripts/dev/start-postgres.py

  • Committer: Magicicada Bot
  • Author(s): Natalia
  • Date: 2016-05-23 12:25:55 UTC
  • mfrom: (60.1.4 clean-storms)
  • Revision ID: magicicada_bot-20160523122555-nol7mgyv60kmkty2
[r=facundo] - Remove all storm-related bits.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python
2
 
 
3
 
# Copyright 2008-2015 Canonical
4
 
# Copyright 2015 Chicharreros (https://launchpad.net/~chicharreros)
5
 
#
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.
10
 
#
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.
15
 
#
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/>.
18
 
#
19
 
# For further info, check  http://launchpad.net/magicicada-server
20
 
 
21
 
"""Script to start Postgres."""
22
 
 
23
 
import os
24
 
import sys
25
 
 
26
 
import utilities.localendpoints as local
27
 
 
28
 
from utilities.utils import os_exec, is_running
29
 
 
30
 
 
31
 
def start():
32
 
    """Start Postgres."""
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")
36
 
 
37
 
    if is_running("postgres", pidfile, "postgres"):
38
 
        print "Postgres already up & running."
39
 
        return 0
40
 
 
41
 
    pg_bin = None
42
 
    for path in ("/usr/lib/postgresql/9.5/bin",):
43
 
        if os.path.isdir(path):
44
 
            pg_bin = path
45
 
            break
46
 
 
47
 
    if pg_bin is None:
48
 
        print "Cannot find valid parent for PGBINDIR"
49
 
        return 1
50
 
 
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"),
54
 
            "-D", data_dir,
55
 
            "-k", sock_dir,
56
 
            "-i", "-h", "127.0.0.1",
57
 
            "-p", str(pg_port))
58
 
 
59
 
if __name__ == '__main__':
60
 
    sys.exit(start())