我的目录结构如下:
.
├── src/main/java
│ └── my code
├── scripts/install
│ ├── preinst.sh
│ └── postinst.sh
├── scripts/systemd
│ ├── my-app.service
│ └── my-app.timer
├── build.gradle.kts
└── settings.gradle.kts
我的应用作为服务在/etc/systemd/system/my-app.timer
中定义的时间间隔内运行。
我正在将我的应用打包到Debian软件包中进行安装,并希望:
postinst.sh
的工作原理很好,每次都可以执行,但是preinst.sh
脚本似乎从未执行过。
preinst.sh
#!/bin/bash
echo "Stopping my-app.timer"
systemctl stop my-app.timer
postinst.sh
#!/bin/bash
echo "Starting my-app.timer"
systemctl start my-app.timer
build.gradle.kts
tasks.buildDeb {
val deployDir = "/opt/my-app"
val confDir = "/etc/$deployDir"
val config = if (project.properties["config"] == null) "dev" else project.properties["config"]
val systemdDir = "/etc/systemd/system"
packageName = project.name
version = project.version.toString().replace("-SNAPSHOT", "")
user = "root"
group = "root"
// copy to lib
from("$buildDir/libs") {
into(deployDir)
}
// copy to conf
from("$projectDir/conf") {
when (config) {
"dev" -> include("*-dev.properties")
"test" -> include("*-test.properties")
"prod" -> include("*-prod.properties")
}
into(confDir)
}
from("$projectDir/src/test/resources") {
into(confDir)
}
from("$projectDir/scripts/systemd") {
into(systemdDir)
}
preInstall(File("$projectDir/scripts/install/preinst.sh"))
postInstall(File("$projectDir/scripts/install/postinst.sh"))
}
在安装新软件包之前,如何确保my-app.timer
已停止?