You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.7 KiB
Kotlin
46 lines
1.7 KiB
Kotlin
package org.domaindrivenarchitecture.provs.framework.extensions.server_software.standalone_server.nginx
|
|
|
|
import org.domaindrivenarchitecture.provs.framework.core.Prov
|
|
import org.domaindrivenarchitecture.provs.framework.core.ProvResult
|
|
import org.domaindrivenarchitecture.provs.framework.core.remote
|
|
import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.createFile
|
|
import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.fileExists
|
|
import org.domaindrivenarchitecture.provs.framework.ubuntu.install.base.aptInstall
|
|
import org.domaindrivenarchitecture.provs.framework.extensions.server_software.standalone_server.nginx.base.NginxConf
|
|
import org.domaindrivenarchitecture.provs.framework.extensions.server_software.standalone_server.nginx.base.createNginxLocationFolders
|
|
import kotlin.system.exitProcess
|
|
|
|
|
|
internal const val configFile = "/etc/nginx/nginx.conf"
|
|
|
|
|
|
fun Prov.provisionNginxStandAlone(config: NginxConf? = null) = requireAll {
|
|
|
|
aptInstall("nginx")
|
|
|
|
createNginxLocationFolders()
|
|
|
|
if (config != null) {
|
|
if (fileExists(configFile)) {
|
|
cmd("sudo mv $configFile $configFile-orig")
|
|
}
|
|
createFile(configFile, config.conf, sudo = true)
|
|
val configCheck = cmd("sudo nginx -t")
|
|
if (configCheck.success) {
|
|
cmd("sudo service nginx restart")
|
|
} else {
|
|
ProvResult(false, err = "Nginx config is incorrect:\n" + configCheck.err)
|
|
}
|
|
} else {
|
|
ProvResult(true) // dummy
|
|
}
|
|
}
|
|
|
|
|
|
fun provisionRemote(vararg args: String) {
|
|
if (args.size != 2) {
|
|
println("Pls specify host and user for remote installation of nginx.")
|
|
exitProcess(1)
|
|
}
|
|
remote(args[0], args[1]).provisionNginxStandAlone()
|
|
} |