我有一个Java应用程序(称为hello-world.jar
,可以通过一个看起来像这样的服务单元(称为hello-world.service
)启动它:
[Unit]
Description=Run hello-world jar
[Service]
WorkingDirectory=/apps/jar
ExecStart=/usr/bin/java -Xms128m -Xmx256m -jar hello-world.jar --spring.config.location=file:/apps/jar/hello-world.properties
User=jarapps
Type=simple
Restart=on-failure
RestartSec=10
如您所见,我的Java应用程序可以接收一个外部application.properties文件(例如hello-world.properties
)
问题:假设我的application.properties(即hello-world.properties
)文件是动态修改和更新的,我想用新的属性重新启动Java应用程序。
ATTEMPT:我尝试使用看起来像这样的路径单元(称为hello-world.path
):
[Unit]
Description=Check for changes in hello-world config
[Path]
PathModified=/apps/jar/hello-world.properties
[Install]
WantedBy=multi-user.target
但是,这不会重新启动我的服务。我怀疑这是因为路径单元只会激活服务单元,这意味着它将启动服务,而不会重新启动它。
更改文件后,如何动态重新启动(而不只是启动)我的服务?
修改文件后尝试。
systemctl daemon-reload
systemctl restart hello-world.service