postgresql: add systemd service file
authorPeter Seiderer <ps.report@gmx.net>
Tue, 20 May 2014 21:16:51 +0000 (23:16 +0200)
committerThomas Petazzoni <thomas.petazzoni@free-electrons.com>
Sat, 10 Jan 2015 18:04:31 +0000 (19:04 +0100)
[Thomas: indent using tabs.]

Signed-off-by: Peter Seiderer <ps.report@gmx.net>
Reviewed-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
package/postgresql/postgresql.mk
package/postgresql/postgresql.service [new file with mode: 0644]

index ea663a2fec7c27847bc31eb096a0ab280eea12fa..e53b9ddb26b21a7324069c12fd4bf368612ee7ca 100644 (file)
@@ -69,4 +69,12 @@ define POSTGRESQL_INSTALL_INIT_SYSV
                $(TARGET_DIR)/etc/init.d/S50postgresql
 endef
 
+define POSTGRESQL_INSTALL_INIT_SYSTEMD
+       $(INSTALL) -D -m 644 package/postgresql/postgresql.service \
+               $(TARGET_DIR)/etc/systemd/system/postgresql.service
+       mkdir -p $(TARGET_DIR)/etc/systemd/system/multi-user.target.wants
+       ln -fs ../postgresql.service \
+               $(TARGET_DIR)/etc/systemd/system/multi-user.target.wants/postgresql.service
+endef
+
 $(eval $(autotools-package))
diff --git a/package/postgresql/postgresql.service b/package/postgresql/postgresql.service
new file mode 100644 (file)
index 0000000..4a96258
--- /dev/null
@@ -0,0 +1,24 @@
+[Unit]
+Description=PostgreSQL database server
+After=network.target
+
+[Service]
+Type=forking
+
+# start timeout disabled because initdb may run a little
+# longer (eg. 5 minutes on RaspberryPi)
+TimeoutStartSec=0
+
+User=postgres
+Group=postgres
+
+SyslogIdentifier=postgres
+PIDFile=/var/lib/pgsql/postmaster.pid
+
+ExecStartPre=/bin/sh -c "if [ ! -f /var/lib/pgsql/PG_VERSION ]; then /usr/bin/pg_ctl initdb -D /var/lib/pgsql; fi"
+ExecStart=/usr/bin/pg_ctl start -D /var/lib/pgsql -w -l /var/lib/pgsql/logfile
+ExecReload=/usr/bin/pg_ctl reload -D /var/lib/pgsql
+ExecStop=/usr/bin/pg_ctl stop -D /var/lib/pgsql -m fast
+
+[Install]
+WantedBy=multi-user.target