2020-12-29 23:56:10 -05:00
|
|
|
package ps
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"strconv"
|
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
"github.com/dokku/dokku/plugins/common"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// ReportSingleApp is an internal function that displays the ps report for one or more apps
|
2021-02-01 22:23:05 -05:00
|
|
|
func ReportSingleApp(appName string, format string, infoFlag string) error {
|
2020-12-29 23:56:10 -05:00
|
|
|
if err := common.VerifyAppName(appName); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
flags := map[string]common.ReportFunc{
|
2025-03-09 04:26:47 -04:00
|
|
|
"--deployed": reportDeployed,
|
|
|
|
|
"--processes": reportProcesses,
|
|
|
|
|
"--ps-can-scale": reportCanScale,
|
|
|
|
|
"--ps-restart-policy": reportRestartPolicy,
|
|
|
|
|
"--ps-computed-procfile-path": reportComputedProcfilePath,
|
|
|
|
|
"--ps-global-procfile-path": reportGlobalProcfilePath,
|
|
|
|
|
"--ps-procfile-path": reportProcfilePath,
|
|
|
|
|
"--restore": reportRestore,
|
|
|
|
|
"--running": reportRunningState,
|
|
|
|
|
"--global-stop-timeout-seconds": reportGlobalStopTimeoutSeconds,
|
|
|
|
|
"--computed-stop-timeout-seconds": reportComputedStopTimeoutSeconds,
|
|
|
|
|
"--stop-timeout-seconds": reportStopTimeoutSeconds,
|
2020-12-29 23:56:10 -05:00
|
|
|
}
|
|
|
|
|
|
2020-12-30 00:38:07 -05:00
|
|
|
extraFlags := addStatusFlags(appName, infoFlag)
|
|
|
|
|
for flag, fn := range extraFlags {
|
|
|
|
|
flags[flag] = fn
|
2020-12-29 23:56:10 -05:00
|
|
|
}
|
|
|
|
|
|
2021-01-07 01:34:05 -05:00
|
|
|
flagKeys := []string{}
|
|
|
|
|
for flagKey := range flags {
|
|
|
|
|
flagKeys = append(flagKeys, flagKey)
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-29 23:56:10 -05:00
|
|
|
trimPrefix := false
|
|
|
|
|
uppercaseFirstCharacter := true
|
2020-12-30 00:37:43 -05:00
|
|
|
infoFlags := common.CollectReport(appName, infoFlag, flags)
|
2021-02-01 22:23:05 -05:00
|
|
|
return common.ReportSingleApp("ps", appName, infoFlag, infoFlags, flagKeys, format, trimPrefix, uppercaseFirstCharacter)
|
2020-12-29 23:56:10 -05:00
|
|
|
}
|
|
|
|
|
|
2020-12-30 00:38:07 -05:00
|
|
|
func addStatusFlags(appName string, infoFlag string) map[string]common.ReportFunc {
|
|
|
|
|
flags := map[string]common.ReportFunc{}
|
|
|
|
|
|
|
|
|
|
if infoFlag != "" && !strings.HasPrefix(infoFlag, "--status-") {
|
|
|
|
|
return flags
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
scheduler := common.GetAppScheduler(appName)
|
|
|
|
|
if scheduler != "docker-local" {
|
|
|
|
|
return flags
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
containerFiles := common.ListFilesWithPrefix(common.AppRoot(appName), "CONTAINER.")
|
|
|
|
|
for _, filename := range containerFiles {
|
|
|
|
|
// See https://github.com/golang/go/wiki/CommonMistakes#using-goroutines-on-loop-iterator-variables
|
|
|
|
|
containerFilePath := filename
|
|
|
|
|
process := strings.TrimPrefix(filename, fmt.Sprintf("%s/CONTAINER.", common.AppRoot(appName)))
|
|
|
|
|
|
|
|
|
|
flags[fmt.Sprintf("--status-%s", process)] = func(appName string) string {
|
|
|
|
|
containerID := common.ReadFirstLine(containerFilePath)
|
|
|
|
|
containerStatus, _ := common.DockerInspect(containerID, "{{ .State.Status }}")
|
|
|
|
|
|
|
|
|
|
if containerStatus == "" {
|
|
|
|
|
containerStatus = "missing"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return fmt.Sprintf("%s (CID: %s)", containerStatus, containerID[0:11])
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return flags
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-29 23:56:10 -05:00
|
|
|
func reportCanScale(appName string) string {
|
|
|
|
|
canScale := "false"
|
|
|
|
|
if canScaleApp(appName) {
|
|
|
|
|
canScale = "true"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return canScale
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-21 21:45:46 -04:00
|
|
|
func reportComputedProcfilePath(appName string) string {
|
|
|
|
|
value := reportProcfilePath(appName)
|
|
|
|
|
if value == "" {
|
|
|
|
|
value = reportGlobalProcfilePath(appName)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return value
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func reportGlobalProcfilePath(appName string) string {
|
|
|
|
|
return common.PropertyGetDefault("ps", "--global", "procfile-path", "Procfile")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func reportProcfilePath(appName string) string {
|
|
|
|
|
return common.PropertyGetDefault("ps", appName, "procfile-path", "")
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-29 23:56:10 -05:00
|
|
|
func reportDeployed(appName string) string {
|
|
|
|
|
deployed := "false"
|
|
|
|
|
if common.IsDeployed(appName) {
|
|
|
|
|
deployed = "true"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return deployed
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func reportProcesses(appName string) string {
|
|
|
|
|
count, err := getProcessCount(appName)
|
|
|
|
|
if err != nil {
|
|
|
|
|
count = -1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return strconv.Itoa(count)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func reportRestartPolicy(appName string) string {
|
|
|
|
|
policy, _ := getRestartPolicy(appName)
|
|
|
|
|
if policy == "" {
|
|
|
|
|
policy = DefaultProperties["restart-policy"]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return policy
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func reportRestore(appName string) string {
|
2024-03-14 01:18:28 -04:00
|
|
|
results, _ := common.CallPlugnTrigger(common.PlugnTriggerInput{
|
|
|
|
|
Trigger: "config-get",
|
|
|
|
|
Args: []string{appName, "DOKKU_APP_RESTORE"},
|
|
|
|
|
})
|
|
|
|
|
restore := results.StdoutContents()
|
2020-12-29 23:56:10 -05:00
|
|
|
if restore == "0" {
|
|
|
|
|
restore = "false"
|
|
|
|
|
} else {
|
|
|
|
|
restore = "true"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return restore
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func reportRunningState(appName string) string {
|
|
|
|
|
return getRunningState(appName)
|
|
|
|
|
}
|
2025-03-09 04:26:47 -04:00
|
|
|
|
|
|
|
|
func reportComputedStopTimeoutSeconds(appName string) string {
|
|
|
|
|
value := reportStopTimeoutSeconds(appName)
|
|
|
|
|
if value == "" {
|
|
|
|
|
value = reportGlobalStopTimeoutSeconds(appName)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return value
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func reportGlobalStopTimeoutSeconds(appName string) string {
|
|
|
|
|
return common.PropertyGetDefault("ps", "--global", "stop-timeout-seconds", "30")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func reportStopTimeoutSeconds(appName string) string {
|
|
|
|
|
return common.PropertyGetDefault("ps", appName, "stop-timeout-seconds", "30")
|
|
|
|
|
}
|