|
8 | 8 | "github.com/bcdevtools/node-management/validation" |
9 | 9 | "github.com/pkg/errors" |
10 | 10 | "github.com/spf13/cobra" |
| 11 | + "os/user" |
11 | 12 | "regexp" |
12 | 13 | "strings" |
13 | 14 | ) |
@@ -220,8 +221,6 @@ func GetGenStartWebCmd() *cobra.Command { |
220 | 221 |
|
221 | 222 | var sb strings.Builder |
222 | 223 | { |
223 | | - sb.WriteString(constants.BINARY_NAME) |
224 | | - sb.WriteString(" ") |
225 | 224 | sb.WriteString(cmdStartWeb) |
226 | 225 | sb.WriteString(" ") |
227 | 226 | sb.WriteString(nodeHomeDirectory) |
@@ -324,7 +323,56 @@ func GetGenStartWebCmd() *cobra.Command { |
324 | 323 | fmt.Println() |
325 | 324 | fmt.Println("Generated command:") |
326 | 325 | fmt.Println() |
| 326 | + fmt.Print(constants.BINARY_NAME, " ") |
327 | 327 | fmt.Println(sb.String()) |
| 328 | + |
| 329 | + currentUser, err := user.Current() |
| 330 | + if err != nil { |
| 331 | + utils.ExitWithErrorMsg("ERR: failed to get current user") |
| 332 | + return |
| 333 | + } |
| 334 | + appBinaryPath, ec := utils.LaunchAppAndGetOutput("which", []string{constants.BINARY_NAME}) |
| 335 | + appBinaryPath = strings.TrimSpace(appBinaryPath) |
| 336 | + if ec != 0 || appBinaryPath == "" { |
| 337 | + appBinaryPath = constants.BINARY_NAME |
| 338 | + } |
| 339 | + |
| 340 | + fmt.Println() |
| 341 | + regexNonAlphanumeric := regexp.MustCompile(`[^a-zA-Z\d]`) |
| 342 | + serviceFileName := strings.ToLower( |
| 343 | + fmt.Sprintf("%s.%s.service", |
| 344 | + regexNonAlphanumeric.ReplaceAllString(brand, "-"), |
| 345 | + regexNonAlphanumeric.ReplaceAllString(chainName, "-"), |
| 346 | + ), |
| 347 | + ) |
| 348 | + { |
| 349 | + fmt.Println("Service file:") |
| 350 | + fmt.Println(fmt.Sprintf("sudo vi /etc/systemd/system/%s", serviceFileName)) |
| 351 | + } |
| 352 | + fmt.Println() |
| 353 | + { |
| 354 | + fmt.Println(fmt.Sprintf(`[Unit] |
| 355 | +Description=%s on %s |
| 356 | +After=network.target |
| 357 | +# |
| 358 | +[Service] |
| 359 | +Restart=always |
| 360 | +RestartSec=10 |
| 361 | +User=%s |
| 362 | +ExecStart=%s %s |
| 363 | +Restart=on-failure |
| 364 | +LimitNOFILE=65535 |
| 365 | +# |
| 366 | +[Install] |
| 367 | +WantedBy=multi-user.target`, |
| 368 | + chainName, brand, currentUser, appBinaryPath, sb.String()), |
| 369 | + ) |
| 370 | + } |
| 371 | + { |
| 372 | + fmt.Println() |
| 373 | + fmt.Println("sudo systemctl enable", serviceFileName) |
| 374 | + fmt.Println("sudo systemctl restart", serviceFileName) |
| 375 | + } |
328 | 376 | }, |
329 | 377 | } |
330 | 378 |
|
|
0 commit comments