2017-09-04 44 views
0

這主要是出於好奇的問題。我正在瀏覽Postgres的systemd單元文件,以瞭解systemd可以做些什麼。 Postgres有兩個systemd單元文件。一個用來代替系統目標:Postgres系統單元文件如何確定要運行的Postgres版本?

# 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 "[email protected]", e.g. "[email protected]". 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 "[email protected]%i" as process name 
[email protected]/usr/bin/pg_ctlcluster [email protected]%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 
[email protected]%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依賴我看到有模板,9.5主要的特定實例,這是一個依賴:

> systemctl list-dependencies postgresql 

postgresql.service 
● ├─[email protected] 
● ├─[email protected] 
● ├─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。這是在Ubuntu 16.04上使用systemd 229和Postgres 9.5(通過sudo apt-get install postgresql安裝)。

回答

1

來源:https://www.freedesktop.org/software/systemd/man/systemd.unit.html

"%i" Instance name For instantiated units: this is the string between the "@" character and the suffix of the unit name. 

文件名是[email protected]所以%i = 9.3-main

更新:

實例文件通常作爲一個符號鏈接到模板文件創建,鏈接名稱包括實例標識符

file /run/systemd/generator/postgresql.service.wants/[email protected] 
/run/systemd/generator/postgresql.service.wants/[email protected]: symbolic link to /lib/systemd/system/[email protected] 
+0

你在哪裏看到名爲'postgres @ 9.3-main.service'的文件?正如問題中提到的,除了'postgresql.service'和'postgresql @ .service',我沒有看到任何單元文件。我檢查了'/ lib/systemd/system'和'/ etc/systemd/system'。 – malisper

+0

查看詳細信息以瞭解[email protected]的存儲位置。 – papey

+0

好的。我現在看到該文件。我會看看理解'/ run/systemd/generator'目錄。謝謝! – malisper

相關問題