Skip to contentSkip to conversation

postgresql: add systemd service file

PATCH New Peter Seiderer 3 participants 5 messages May 20, 2014 – Jan 10, 2015

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 postgresql: add systemd service file

---
Changes v1 -> v2:
- add '-w' (wait) to pg_ctl start command (to ensure pid file generation)

---
 package/postgresql/postgresql.mk      |  8 ++++++++
 package/postgresql/postgresql.service | 24 ++++++++++++++++++++++++
 2 files changed, 32 insertions(+)
 create mode 100644 package/postgresql/postgresql.service
package/postgresql/postgresql.mk +8 -0
index b331737..cf4700a 100644
@@ -58,4 +58,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))
package/postgresql/postgresql.service new file +24 -0
new file mode 100644
index 0000000..4a96258
@@ -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
Signature · 1 line
1.8.1.4
#1 lore raw

PATCH v2 1/1 postgresql: add systemd service file

Eric,

As our systemd person, could you review this patch, and give your comments and/or Acked-by/Reviewed-by as appropriate?

Thanks,

Thomas

Quoted 58 lines · Peter Seiderer

---
Changes v1 -> v2:
- add '-w' (wait) to pg_ctl start command (to ensure pid file generation)

---
 package/postgresql/postgresql.mk      |  8 ++++++++
 package/postgresql/postgresql.service | 24 ++++++++++++++++++++++++
 2 files changed, 32 insertions(+)
 create mode 100644 package/postgresql/postgresql.service
package/postgresql/postgresql.mk +8 -0
index b331737..cf4700a 100644
@@ -58,4 +58,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))
package/postgresql/postgresql.service new file +24 -0
new file mode 100644
index 0000000..4a96258
@@ -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
Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
#2 lore raw

PATCH v2 1/1 postgresql: add systemd service file

Eric,

Another ping about this patch :-)

Thanks,

Thomas

Quoted 71 lines · Thomas Petazzoni

Eric,

As our systemd person, could you review this patch, and give your comments and/or Acked-by/Reviewed-by as appropriate?

Thanks,

Thomas

Quoted 58 lines · Peter Seiderer

---
Changes v1 -> v2:
- add '-w' (wait) to pg_ctl start command (to ensure pid file generation)

---
 package/postgresql/postgresql.mk      |  8 ++++++++
 package/postgresql/postgresql.service | 24 ++++++++++++++++++++++++
 2 files changed, 32 insertions(+)
 create mode 100644 package/postgresql/postgresql.service
package/postgresql/postgresql.mk +8 -0
index b331737..cf4700a 100644
@@ -58,4 +58,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))
package/postgresql/postgresql.service new file +24 -0
new file mode 100644
index 0000000..4a96258
@@ -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
Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
#3 lore raw

PATCH v2 1/1 postgresql: add systemd service file

In reply to Peter Seiderer
Quoted 1 line · Peter Seiderer

Looks good. It has two things that aren't present in the sysvinit start script,
though:

- the -w option mentioned below;

- the Reload option (sysvinit just restarts).

But both are a good idea.

Regards,
Arnout

Quoted 58 lines

---
Changes v1 -> v2:
- add '-w' (wait) to pg_ctl start command (to ensure pid file generation)

---
 package/postgresql/postgresql.mk      |  8 ++++++++
 package/postgresql/postgresql.service | 24 ++++++++++++++++++++++++
 2 files changed, 32 insertions(+)
 create mode 100644 package/postgresql/postgresql.service
package/postgresql/postgresql.mk +8 -0
index b331737..cf4700a 100644
@@ -58,4 +58,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))
package/postgresql/postgresql.service new file +24 -0
new file mode 100644
index 0000000..4a96258
@@ -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
Signature · 6 lines
Arnout Vandecappelle                          arnout at mind be
Senior Embedded Software Architect            +32-16-286500
Essensium/Mind                                http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium           BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7CB5 E4CC 6C2E EFD4 6E3D A754 F963 ECAB 2450 2F1F
#4 lore raw

PATCH v2 1/1 postgresql: add systemd service file

In reply to Peter Seiderer

Dear Peter Seiderer,

package/postgresql/postgresql.mk define POSTGRESQL_INSTALL_INIT_SYSV · line 67

Quoted 7 lines · Peter Seiderer
package/postgresql/postgresql.mk +7 -0
+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

Tabs should have been used instead of spaces for indentation. I've fixed that up, and committed.

Thanks!

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com