Skip to content
This repository was archived by the owner on Dec 2, 2020. It is now read-only.

Commit be98dd1

Browse files
committed
Kill stale pidfiles before starting the service
If you kill postgres badly, it leaves a `postmaster.pid` file lying around which prevents the service from starting later. This gets in the way of development, causes confusion, and *burns battery* as launchd tries again and again to start postgres. There are potential consequences to this in the case of a corrupt database, but they're so unlikely that I much prefer to err on the side of convenience for a developer machine.
1 parent bc9c26b commit be98dd1

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

manifests/service.pp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
}
1717

1818
$nc = "nc -z ${host} ${port}"
19+
$pidfile = "${datadir}/postmaster.pid"
1920

2021
if $::operatingsystem == 'Darwin' {
2122
service { 'com.boxen.postgresql':
@@ -30,6 +31,13 @@
3031
creates => "${datadir}/PG_VERSION",
3132
}
3233

34+
->
35+
exec { 'kill-stale-postgres-pidfile':
36+
# Remove the pidfile, unless there's a postgres process running
37+
command => "rm -f ${pidfile}",
38+
unless => "ps -p `head -1 ${pidfile}` | grep postgres",
39+
}
40+
3341
->
3442
service { $service:
3543
ensure => $svc_ensure,

0 commit comments

Comments
 (0)