@@ -4,12 +4,15 @@ import (
4
4
"fmt"
5
5
"os"
6
6
"os/exec"
7
+ "strconv"
7
8
"syscall"
9
+ "time"
8
10
9
11
"github.com/apex/log"
10
12
"github.com/spf13/cobra"
11
13
"github.com/tarantool/tt/cli/cmd/internal"
12
14
"github.com/tarantool/tt/cli/cmdcontext"
15
+ "github.com/tarantool/tt/cli/integrity"
13
16
"github.com/tarantool/tt/cli/modules"
14
17
"github.com/tarantool/tt/cli/process_utils"
15
18
"github.com/tarantool/tt/cli/running"
20
23
// In go, we can't just fork the process (reason - goroutines).
21
24
// So, for daemonize, we restarts the process with "watchdog" flag.
22
25
watchdog bool
26
+ // integrityCheckPeriod is a flag enables periodic integrity checks.
27
+ // The default period is 1 day.
28
+ integrityCheckPeriod = 24 * 60 * 60
23
29
)
24
30
25
31
// NewStartCmd creates start command.
@@ -47,6 +53,8 @@ func NewStartCmd() *cobra.Command {
47
53
startCmd .Flags ().BoolVar (& watchdog , "watchdog" , false , "" )
48
54
startCmd .Flags ().MarkHidden ("watchdog" )
49
55
56
+ integrity .RegisterIntegrityCheckPeriodFlag (startCmd .Flags (), & integrityCheckPeriod )
57
+
50
58
return startCmd
51
59
}
52
60
@@ -61,9 +69,25 @@ func startWatchdog(ttExecutable string, instance running.InstanceCtx) error {
61
69
return nil
62
70
}
63
71
64
- log .Infof ("Starting an instance [%s]..." , appName )
72
+ newArgs := []string {}
73
+ if cmdCtx .Cli .IntegrityCheck != "" {
74
+ newArgs = append (newArgs , "--integrity-check" , cmdCtx .Cli .IntegrityCheck )
75
+ }
76
+
77
+ newArgs = append (newArgs , "start" , "--watchdog" , appName )
78
+
79
+ if cmdCtx .Cli .IntegrityCheck != "" {
80
+ newArgs = append (newArgs , "--integrity-check-period" ,
81
+ strconv .Itoa (integrityCheckPeriod ))
82
+ }
83
+
84
+ f , err := integrity .FileRepository .Read (ttExecutable )
85
+ if err != nil {
86
+ return err
87
+ }
88
+ f .Close ()
65
89
66
- newArgs := [] string { "start" , "--watchdog" , appName }
90
+ log . Infof ( "Starting an instance [%s]..." , appName )
67
91
68
92
wdCmd := exec .Command (ttExecutable , newArgs ... )
69
93
// Set new pgid for watchdog process, so it will not be killed after a session is closed.
@@ -113,7 +137,13 @@ func internalStartModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
113
137
return nil
114
138
}
115
139
116
- if err := running .Start (cmdCtx , & runningCtx .Instances [0 ]); err != nil {
140
+ checkPeriod := time .Duration (0 )
141
+
142
+ if cmdCtx .Cli .IntegrityCheck != "" && integrityCheckPeriod > 0 {
143
+ checkPeriod = time .Duration (integrityCheckPeriod * int (time .Second ))
144
+ }
145
+
146
+ if err := running .Start (cmdCtx , & runningCtx .Instances [0 ], checkPeriod ); err != nil {
117
147
return err
118
148
}
119
149
return nil
0 commit comments