2017-09-04 5 views
0

これは主に好奇心の質問です。 Postgresのシステムファイルを使って、systemdで何ができるのかを知りました。 Postgresには2つのシステムファイルがあります。システムターゲットの代わりに使用されるもの: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 

2番目の単位ファイルは、Postgresバージョンでパラメータ化されたテンプレートです。それはBefore=postgresql.serviceを使用することにより、他のユニットファイルの前に実行されます指定:systemdには、私はsystemctl start postgresqlを実行したときのPostgresのバージョンを実行するかを決定する方法を私が把握することはできませんどのような

# 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 

です。

> 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を使用する必要があることを指定し、任意のファイルを見つけることができません:私は見postgresql.serviceの依存関係を見てみると、テンプレート、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

関連する問題