这主要是出于好奇。我正在浏览Postgres systemd单元文件,以了解systemd可以做些什么。Postgres有两个系统单元文件。用于代替systemd目标的一种:
# systemd service for managing all PostgreSQL clusters on the system. This
# service is actually a systemd target, but we are using a service since
# targets cannot be reloaded.
[Unit]
Description=PostgreSQL RDBMS
[Service]
Type=oneshot
ExecStart=/bin/true
ExecReload=/bin/true
RemainAfterExit=on
[Install]
WantedBy=multi-user.target
第二个单元文件是由Postgres版本参数化的模板。它通过使用指定将在其他单元文件之前运行
Before=postgresql.service
# systemd service template for PostgreSQL clusters. The actual instances will
# be called "postgresql@version-cluster", e.g. "postgresql@9.3-main". The
# variable %i expands to "version-cluster", %I expands to "version/cluster".
# (%I breaks for cluster names containing dashes.)
[Unit]
Description=PostgreSQL Cluster %i
ConditionPathExists=/etc/postgresql/%I/postgresql.conf
PartOf=postgresql.service
ReloadPropagatedFrom=postgresql.service
Before=postgresql.service
[Service]
Type=forking
# @: use "postgresql@%i" as process name
ExecStart=@/usr/bin/pg_ctlcluster postgresql@%i --skip-systemctl-redirect %i start
ExecStop=/usr/bin/pg_ctlcluster --skip-systemctl-redirect -m fast %i stop
ExecReload=/usr/bin/pg_ctlcluster --skip-systemctl-redirect %i reload
PIDFile=/var/run/postgresql/%i.pid
SyslogIdentifier=postgresql@%i
# prevent OOM killer from choosing the postmaster (individual backends will
# reset the score to 0)
OOMScoreAdjust=-900
# restarting automatically will prevent "pg_ctlcluster ... stop" from working,
# so we disable it here. Also, the postmaster will restart by itself on most
# problems anyway, so it is questionable if one wants to enable external
# automatic restarts.
#Restart=on-failure
# (This should make pg_ctlcluster stop work, but doesn't:)
#RestartPreventExitStatus=SIGINT SIGTERM
[Install]
WantedBy=multi-user.target
我不明白的是,当我运行时,systemd是如何决定要运行哪个版本的Postgres的
systemctl start postgresql
. 当我看到
postgresql.service
> systemctl list-dependencies postgresql
postgresql.service
â ââpostgresql@9.5-main.service
â ââpostgresql@9.5-main.service
â ââsystem.slice
â ââsysinit.target
â ââapparmor.service
â ââbrltty.service
â ââconsole-setup.service
â ââdev-hugepages.mount
â ââdev-mqueue.mount
â ââfriendly-recovery.service
â ââkeyboard-setup.service
â ââkmod-static-nodes.service
â ââlvm2-lvmetad.socket
â ââlvm2-lvmpolld.socket
â ââlvm2-monitor.service
â ââplymouth-read-write.service
â ââplymouth-start.service
â ââproc-sys-fs-binfmt_misc.automount
â ââresolvconf.service
â ââsetvtrgb.service
â ââsys-fs-fuse-connections.mount
â ââsys-kernel-config.mount
我找不到任何文件指定应该使用Postgres 9.5。没有任何其他Postgres单元文件,也没有任何其他文件提及Postgres。这是在带有systemd 229和Postgres 9.5(通过安装)的Ubuntu 16.04上
sudo apt-get install postgresql