-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathrunChainSeq.go
48 lines (37 loc) · 1.09 KB
/
runChainSeq.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package utils
import (
"fmt"
"os"
"os/exec"
"path/filepath"
)
func RunChainSeq(folderPath, scriptName string) error {
// Get the absolute path of the specified folder
absFolderPath, err := filepath.Abs(folderPath)
if err != nil {
return fmt.Errorf("failed to get absolute path: %v", err)
}
// Check if the directory exists
if _, err := os.Stat(absFolderPath); os.IsNotExist(err) {
return fmt.Errorf("directory does not exist: %v", absFolderPath)
}
// Change to the specified folder
if err := os.Chdir(absFolderPath); err != nil {
return fmt.Errorf("failed to change directory: %v", err)
}
pm2Args := []string{"start", scriptName}
// Run the shell script
cmd := exec.Command("pm2", pm2Args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
fmt.Printf("Running shell script %s in folder %s\n", scriptName, absFolderPath)
if err := cmd.Run(); err != nil {
return fmt.Errorf("failed to run shell script: %v", err)
}
err = os.Chdir("../")
if err != nil {
return fmt.Errorf("failed to change directory: %v", err)
}
fmt.Println("Shell script executed successfully")
return nil
}