Skip to content

Commit

Permalink
Structure to build a Debian package (#7)
Browse files Browse the repository at this point in the history
* Structure to build a Debian package

* Fix reference to GH issue

* Add missing .PHONY target

* Bring back (un)install targets
  • Loading branch information
marcoalmeida authored Nov 28, 2017
1 parent 1500d9a commit cd1bd87
Show file tree
Hide file tree
Showing 16 changed files with 201 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ pgdoctor_test

# IDEs
.idea

debian/pgdoctor
debian/pgdoctor.debhelper.log
12 changes: 8 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@ $(BIN): main.c $(OBJECTS)
$(CC) -c $(CFLAGS) $< -o $@

install: $(BIN)
install -m 0755 $(BIN) $(PREFIX)
install -m 0600 $(CFG_FILE) /etc
install -D -m 0755 $(BIN) $(DESTDIR)$(PREFIX)/$(BIN)
install -D -m 0600 $(CFG_FILE) $(DESTDIR)/etc/$(CFG_FILE)

uninstall:
rm -f $(PREFIX)/$(BIN)
rm -f /etc/$(CFG_FILE)
rm -f $(DESTDIR)$(PREFIX)/$(BIN)
rm -f $(DESTDIR)/etc/$(CFG_FILE)

.PHONY: debian
debian:
dpkg-buildpackage -uc -us

clean:
rm -fr $(BIN) $(BIN_TEST) *.o
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
pgDoctor
========

Simple, lightweight web service to perform health checks on PostgreSQL instances.
Simple, lightweight, web service used to define and run custom health checks on PostgreSQL
instances.


## Dependencies
Expand Down Expand Up @@ -55,8 +56,8 @@ is created under `/etc/pgdoctor.cfg`. Each setting is preceded by a comment desc
### Target PostgreSQL instance
| Parameter | Description | Default |
| ------------- |-------------|-----|
| `pg_host` | Host name of the instance | `localhost` |
| `pg_port` | Port on which the server is listening | 5432 |
| `pg_host` | Host name of the instance pgDoctor will connect to | `localhost` |
| `pg_port` | Port on which the target server is listening | 5432 |
| `pg_user` | User to connect with | `postgres` |
| `pg_password` | Password to use with `pg_user` | *empty* |
| `pg_database` | Name of the database to connect to | `postgres` |
Expand Down
5 changes: 5 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pgdoctor (0.2.0) unstable; urgency=medium

* Initial Release. Closes: #4

-- Marco Almeida <mfa@thumbtack.com> Thu, 23 Nov 2017 21:45:40 -0800
1 change: 1 addition & 0 deletions debian/compat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
9
15 changes: 15 additions & 0 deletions debian/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Source: pgdoctor
Section: Databases
Priority: optional
Maintainer: Marco Almeida <mfa@thumbtack.com>
Build-Depends: debhelper (>= 9), libpq-dev (>= 9.4), libmicrohttpd-dev
Standards-Version: 3.9.8
Homepage: https://github.com/thumbtack/pgdoctor
Vcs-Git: https://github.com/thumbtack/pgdoctor.git

Package: pgdoctor
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}, postgresql-9.4 | postgresql-9.6
Description: Custom health checks for PostgreSQL
pgDoctor is a simple, lightweight, web service used to define and run custom
health checks on PostgreSQL instances.
23 changes: 23 additions & 0 deletions debian/copyright
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: pgdoctor
Source: https://github.com/thumbtack/pgdoctor

Files: *
Copyright: 2014-2017 Marco Almeida <mfa@thumbtack.com>
License: Apache-2.0

License: Apache-2.0
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
.
http://www.apache.org/licenses/LICENSE-2.0
.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
.
On Debian systems, the complete text of the Apache License, Version 2.0
can be found in "/usr/share/common-licenses/Apache-2.0".
3 changes: 3 additions & 0 deletions debian/files
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pgdoctor-dbgsym_0.2.0_amd64.ddeb debug extra
pgdoctor_0.2.0_amd64.buildinfo Databases optional
pgdoctor_0.2.0_amd64.deb Databases optional
3 changes: 3 additions & 0 deletions debian/install
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pgdoctor usr/bin/
pgdoctor.cfg etc/
pgdoctor.service etc/systemd/system/
93 changes: 93 additions & 0 deletions debian/pgdoctor.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
.\" Hey, EMACS: -*- nroff -*-
.\" (C) Copyright 2014-2017 Marco Almeida <mfa@thumbtack.com>,
.\"
.\" First parameter, NAME, should be all caps
.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
.\" other parameters are allowed: see man(7), man(1)
.TH pgDoctor 1 "2017"
.\" Please adjust this date whenever revising the manpage.
.\"
.\" Some roff macros, for reference:
.\" .nh disable hyphenation
.\" .hy enable hyphenation
.\" .ad l left justify
.\" .ad b justify to both left and right margins
.\" .nf disable filling
.\" .fi enable filling
.\" .br insert line break
.\" .sp <n> insert n+1 empty lines
.\" for manpage-specific macros, see man(7)
.SH NAME
pgdoctor \- Custom health checks for PostgreSQL
.SH SYNOPSIS
.B pgdoctor
.RI [ filename ]
.SH DESCRIPTION
This manual page documents briefly the
.B pgdoctor
service.
.PP
.\" TeX users may be more comfortable with the \fB<whatever>\fP and
.\" \fI<whatever>\fP escape sequences to invode bold face and italics,
.\" respectively.
\fBpgdoctor\fP is a simple, lightweight, web service used to define
and run custom health checks on PostgreSQL instances.
.SH FILES
The only (optional) argument \fBpgdoctor\fP accepts if the
configuration file for runtime configuration options. It defaults to
\fB/etc/pgdoctor.cfg\fP.
.SH RUNTIME CONFIGURATION
.TP
.B http_port
Port to listen on; defaults to \fI8071\fP
.TP
.B syslog_facility
Syslog facility (local) to messages log to; defaults to \fIlocal7\fP
.TP
.B pg_host
Host name of the instance \fBpgDoctor\fP will connect to; defaults to
\fIlocalhost\fP
.TP
.B pg_gport
Port on which the target server is listening; defaults to \fI5432\fP
.TP
.B pg_user
User to connect with; defaults to \fIpostgres\fP
.TP
.B pg_password
Password to use with pg_user; defaults to \fIempty\fP
.TP
.B pg_database
Name of the database to connect to; defaults to \fIpostgres\fP
.TP
.B pg_connection_timeout
Timeout (seconds) when connecting to PostgreSQL; defaults by \fI3\fP
.TP
.B pg_max_replication_lag
Maximum acceptable delay (seconds) on streaming replication; defaults
to \fI-1\fP (disabled)
.SH EXAMPLES \(em CUSTOM HEALTH CHECKS
Each of the following two SQL queries defines a custom health check
that will succeed if and only if it is executed without any errors
(notice the mandatory double quotes):
.IP
.nf
"SELECT 1"
.fi
.IP
.nf
"SELECT NOW()"
.fi
.P
The next one, more complex, custom health check includes a condition
on the result of the SQL query (which must be exactly \fIone\fP
field):
.IP
.nf
"SELECT on_rotation FROM maintenance WHERE hostname = 'production-replica3'" = "1"
.fi
.P
This check will succeed if and only if the value of the returned field
\fBon_rotation\fP equals \fB1\fP.
.SH SEE ALSO
.BR https://github.com/thumbtack/pgdoctor
1 change: 1 addition & 0 deletions debian/pgdoctor.manpages
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
debian/pgdoctor.1
3 changes: 3 additions & 0 deletions debian/pgdoctor.substvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
shlibs:Depends=libc6 (>= 2.4), libmicrohttpd12 (>= 0.9.50), libpq5
misc:Depends=
misc:Pre-Depends=
25 changes: 25 additions & 0 deletions debian/rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/make -f
# See debhelper(7) (uncomment to enable)
# output every command that modifies files on the build system.
#export DH_VERBOSE = 1


# see FEATURE AREAS in dpkg-buildflags(1)
#export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# see ENVIRONMENT in dpkg-buildflags(1)
# package maintainers to append CFLAGS
#export DEB_CFLAGS_MAINT_APPEND = -Wall -pedantic
# package maintainers to append LDFLAGS
#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed


%:
dh $@


# dh_make generated override targets
# This is example for Cmake (See https://bugs.debian.org/641051 )
#override_dh_auto_configure:
# dh_auto_configure -- # -DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH)

1 change: 1 addition & 0 deletions debian/source/format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.0 (native)
2 changes: 1 addition & 1 deletion pgdoctor.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pg_host = localhost
pg_port = 5432
pg_user = postgres
pg_password =
pg_database = thumbtack
pg_database = postgres
# timeout (in seconds) when connecting to the PostgreSQL server
pg_connection_timeout = 3
# maximum acceptable delay on a streaming replica (use -1 to disable)
Expand Down
12 changes: 12 additions & 0 deletions pgdoctor.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description=Unit for pgDoctor
After=postgresql.service
Requires=postgresql.service

[Service]
TimeoutStartSec=0
Type=simple
ExecStart=/usr/bin/pgdoctor

[Install]
WantedBy=multi-user.target

0 comments on commit cd1bd87

Please sign in to comment.