|
|
@ -3,6 +3,7 @@ package command |
|
|
import ( |
|
|
import ( |
|
|
"os" |
|
|
"os" |
|
|
"os/signal" |
|
|
"os/signal" |
|
|
|
|
|
"path/filepath" |
|
|
"strings" |
|
|
"strings" |
|
|
"syscall" |
|
|
"syscall" |
|
|
"time" |
|
|
"time" |
|
|
@ -21,7 +22,7 @@ import ( |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
var cmdWorker = &Command{ |
|
|
var cmdWorker = &Command{ |
|
|
UsageLine: "worker -admin=<admin_server> [-capabilities=<task_types>] [-maxConcurrent=<num>]", |
|
|
|
|
|
|
|
|
UsageLine: "worker -admin=<admin_server> [-capabilities=<task_types>] [-maxConcurrent=<num>] [-workingDir=<path>]", |
|
|
Short: "start a maintenance worker to process cluster maintenance tasks", |
|
|
Short: "start a maintenance worker to process cluster maintenance tasks", |
|
|
Long: `Start a maintenance worker that connects to an admin server to process |
|
|
Long: `Start a maintenance worker that connects to an admin server to process |
|
|
maintenance tasks like vacuum, erasure coding, remote upload, and replication fixes. |
|
|
maintenance tasks like vacuum, erasure coding, remote upload, and replication fixes. |
|
|
@ -34,6 +35,7 @@ Examples: |
|
|
weed worker -admin=admin.example.com:23646 |
|
|
weed worker -admin=admin.example.com:23646 |
|
|
weed worker -admin=localhost:23646 -capabilities=vacuum,replication |
|
|
weed worker -admin=localhost:23646 -capabilities=vacuum,replication |
|
|
weed worker -admin=localhost:23646 -maxConcurrent=4 |
|
|
weed worker -admin=localhost:23646 -maxConcurrent=4 |
|
|
|
|
|
weed worker -admin=localhost:23646 -workingDir=/tmp/worker |
|
|
`, |
|
|
`, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -43,6 +45,7 @@ var ( |
|
|
workerMaxConcurrent = cmdWorker.Flag.Int("maxConcurrent", 2, "maximum number of concurrent tasks") |
|
|
workerMaxConcurrent = cmdWorker.Flag.Int("maxConcurrent", 2, "maximum number of concurrent tasks") |
|
|
workerHeartbeatInterval = cmdWorker.Flag.Duration("heartbeat", 30*time.Second, "heartbeat interval") |
|
|
workerHeartbeatInterval = cmdWorker.Flag.Duration("heartbeat", 30*time.Second, "heartbeat interval") |
|
|
workerTaskRequestInterval = cmdWorker.Flag.Duration("taskInterval", 5*time.Second, "task request interval") |
|
|
workerTaskRequestInterval = cmdWorker.Flag.Duration("taskInterval", 5*time.Second, "task request interval") |
|
|
|
|
|
workerWorkingDir = cmdWorker.Flag.String("workingDir", "", "working directory for the worker") |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
func init() { |
|
|
func init() { |
|
|
@ -67,6 +70,33 @@ func runWorker(cmd *Command, args []string) bool { |
|
|
return false |
|
|
return false |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Set working directory and create task-specific subdirectories
|
|
|
|
|
|
var baseWorkingDir string |
|
|
|
|
|
if *workerWorkingDir != "" { |
|
|
|
|
|
glog.Infof("Setting working directory to: %s", *workerWorkingDir) |
|
|
|
|
|
if err := os.Chdir(*workerWorkingDir); err != nil { |
|
|
|
|
|
glog.Fatalf("Failed to change working directory: %v", err) |
|
|
|
|
|
return false |
|
|
|
|
|
} |
|
|
|
|
|
wd, err := os.Getwd() |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
glog.Fatalf("Failed to get working directory: %v", err) |
|
|
|
|
|
return false |
|
|
|
|
|
} |
|
|
|
|
|
baseWorkingDir = wd |
|
|
|
|
|
glog.Infof("Current working directory: %s", baseWorkingDir) |
|
|
|
|
|
|
|
|
|
|
|
// Create task-specific subdirectories
|
|
|
|
|
|
for _, capability := range capabilities { |
|
|
|
|
|
taskDir := filepath.Join(baseWorkingDir, string(capability)) |
|
|
|
|
|
if err := os.MkdirAll(taskDir, 0755); err != nil { |
|
|
|
|
|
glog.Fatalf("Failed to create task directory %s: %v", taskDir, err) |
|
|
|
|
|
return false |
|
|
|
|
|
} |
|
|
|
|
|
glog.Infof("Created task directory: %s", taskDir) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// Create worker configuration
|
|
|
// Create worker configuration
|
|
|
config := &types.WorkerConfig{ |
|
|
config := &types.WorkerConfig{ |
|
|
AdminServer: *workerAdminServer, |
|
|
AdminServer: *workerAdminServer, |
|
|
@ -74,6 +104,7 @@ func runWorker(cmd *Command, args []string) bool { |
|
|
MaxConcurrent: *workerMaxConcurrent, |
|
|
MaxConcurrent: *workerMaxConcurrent, |
|
|
HeartbeatInterval: *workerHeartbeatInterval, |
|
|
HeartbeatInterval: *workerHeartbeatInterval, |
|
|
TaskRequestInterval: *workerTaskRequestInterval, |
|
|
TaskRequestInterval: *workerTaskRequestInterval, |
|
|
|
|
|
BaseWorkingDir: baseWorkingDir, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Create worker instance
|
|
|
// Create worker instance
|
|
|
@ -94,6 +125,21 @@ func runWorker(cmd *Command, args []string) bool { |
|
|
// Set admin client
|
|
|
// Set admin client
|
|
|
workerInstance.SetAdminClient(adminClient) |
|
|
workerInstance.SetAdminClient(adminClient) |
|
|
|
|
|
|
|
|
|
|
|
// Set working directory
|
|
|
|
|
|
if *workerWorkingDir != "" { |
|
|
|
|
|
glog.Infof("Setting working directory to: %s", *workerWorkingDir) |
|
|
|
|
|
if err := os.Chdir(*workerWorkingDir); err != nil { |
|
|
|
|
|
glog.Fatalf("Failed to change working directory: %v", err) |
|
|
|
|
|
return false |
|
|
|
|
|
} |
|
|
|
|
|
wd, err := os.Getwd() |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
glog.Fatalf("Failed to get working directory: %v", err) |
|
|
|
|
|
return false |
|
|
|
|
|
} |
|
|
|
|
|
glog.Infof("Current working directory: %s", wd) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// Start the worker
|
|
|
// Start the worker
|
|
|
err = workerInstance.Start() |
|
|
err = workerInstance.Start() |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
|