2012-08-07 08:29:22 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2013-08-13 04:27:47 +00:00
|
|
|
"code.google.com/p/weed-fs/go/glog"
|
2013-12-09 21:27:09 +00:00
|
|
|
"code.google.com/p/weed-fs/go/util"
|
2013-12-02 09:37:36 +00:00
|
|
|
"code.google.com/p/weed-fs/go/weed/weed_server"
|
2012-08-24 05:46:54 +00:00
|
|
|
"net/http"
|
2012-09-17 00:31:15 +00:00
|
|
|
"os"
|
2012-10-06 17:50:52 +00:00
|
|
|
"runtime"
|
2012-08-24 05:46:54 +00:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
"time"
|
2012-08-07 08:29:22 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2012-08-24 05:46:54 +00:00
|
|
|
cmdVolume.Run = runVolume // break init cycle
|
2012-08-07 08:29:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var cmdVolume = &Command{
|
2012-09-26 08:55:56 +00:00
|
|
|
UsageLine: "volume -port=8080 -dir=/tmp -max=5 -ip=server_name -mserver=localhost:9333",
|
2012-08-24 05:46:54 +00:00
|
|
|
Short: "start a volume server",
|
|
|
|
Long: `start a volume server to provide storage spaces
|
2012-08-07 08:29:22 +00:00
|
|
|
|
|
|
|
`,
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
2013-08-13 16:22:06 +00:00
|
|
|
vport = cmdVolume.Flag.Int("port", 8080, "http listen port")
|
2013-08-28 17:39:15 +00:00
|
|
|
volumeFolders = cmdVolume.Flag.String("dir", os.TempDir(), "directories to store data files. dir[,dir]...")
|
2013-08-13 16:22:06 +00:00
|
|
|
maxVolumeCounts = cmdVolume.Flag.String("max", "7", "maximum numbers of volumes, count[,count]...")
|
2014-04-26 05:09:42 +00:00
|
|
|
ip = cmdVolume.Flag.String("ip", "", "ip or server name")
|
|
|
|
publicIp = cmdVolume.Flag.String("publicIp", "", "Publicly accessible <ip|server_name>")
|
2013-08-13 16:22:06 +00:00
|
|
|
masterNode = cmdVolume.Flag.String("mserver", "localhost:9333", "master server location")
|
2014-02-05 19:47:26 +00:00
|
|
|
vpulse = cmdVolume.Flag.Int("pulseSeconds", 5, "number of seconds between heartbeats, must be smaller than or equal to the master's setting")
|
2014-03-20 18:07:15 +00:00
|
|
|
vTimeout = cmdVolume.Flag.Int("idleTimeout", 10, "connection idle seconds")
|
2013-08-13 16:22:06 +00:00
|
|
|
vMaxCpu = cmdVolume.Flag.Int("maxCpu", 0, "maximum number of CPUs. 0 means all available CPUs")
|
|
|
|
dataCenter = cmdVolume.Flag.String("dataCenter", "", "current volume server's data center name")
|
|
|
|
rack = cmdVolume.Flag.String("rack", "", "current volume server's rack name")
|
|
|
|
volumeWhiteListOption = cmdVolume.Flag.String("whiteList", "", "comma separated Ip addresses having write permission. No limit if empty.")
|
2014-05-15 08:08:00 +00:00
|
|
|
fixJpgOrientation = cmdVolume.Flag.Bool("fix.jpg.orientation", false, "Adjust jpg orientation when uploading.")
|
2012-08-07 08:29:22 +00:00
|
|
|
|
2013-08-13 16:22:06 +00:00
|
|
|
volumeWhiteList []string
|
2012-08-07 08:29:22 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func runVolume(cmd *Command, args []string) bool {
|
2012-11-07 09:51:43 +00:00
|
|
|
if *vMaxCpu < 1 {
|
|
|
|
*vMaxCpu = runtime.NumCPU()
|
|
|
|
}
|
2012-10-06 17:50:52 +00:00
|
|
|
runtime.GOMAXPROCS(*vMaxCpu)
|
2013-07-13 18:38:01 +00:00
|
|
|
folders := strings.Split(*volumeFolders, ",")
|
|
|
|
maxCountStrings := strings.Split(*maxVolumeCounts, ",")
|
|
|
|
maxCounts := make([]int, 0)
|
|
|
|
for _, maxString := range maxCountStrings {
|
|
|
|
if max, e := strconv.Atoi(maxString); e == nil {
|
|
|
|
maxCounts = append(maxCounts, max)
|
|
|
|
} else {
|
2014-04-17 07:16:44 +00:00
|
|
|
glog.Fatalf("The max specified in -max not a valid number %s", maxString)
|
2013-07-13 18:38:01 +00:00
|
|
|
}
|
2012-09-17 00:31:15 +00:00
|
|
|
}
|
2013-07-13 18:38:01 +00:00
|
|
|
if len(folders) != len(maxCounts) {
|
2013-08-09 06:57:22 +00:00
|
|
|
glog.Fatalf("%d directories by -dir, but only %d max is set by -max", len(folders), len(maxCounts))
|
2013-07-13 18:38:01 +00:00
|
|
|
}
|
|
|
|
for _, folder := range folders {
|
2013-12-09 21:27:09 +00:00
|
|
|
if err := util.TestFolderWritable(folder); err != nil {
|
|
|
|
glog.Fatalf("Check Data Folder(-dir) Writable %s : %s", folder, err)
|
2013-07-13 18:38:01 +00:00
|
|
|
}
|
2012-09-17 00:31:15 +00:00
|
|
|
}
|
2012-09-26 10:27:10 +00:00
|
|
|
|
2014-04-26 05:09:42 +00:00
|
|
|
if *publicIp == "" {
|
|
|
|
if *ip == "" {
|
|
|
|
*publicIp = "localhost"
|
|
|
|
} else {
|
|
|
|
*publicIp = *ip
|
|
|
|
}
|
2012-09-26 09:29:16 +00:00
|
|
|
}
|
2013-08-13 16:22:06 +00:00
|
|
|
if *volumeWhiteListOption != "" {
|
|
|
|
volumeWhiteList = strings.Split(*volumeWhiteListOption, ",")
|
2013-08-13 06:48:10 +00:00
|
|
|
}
|
2012-09-20 09:11:08 +00:00
|
|
|
|
2013-12-09 21:27:09 +00:00
|
|
|
r := http.NewServeMux()
|
2012-08-24 05:46:54 +00:00
|
|
|
|
2014-05-13 07:04:28 +00:00
|
|
|
volumeServer := weed_server.NewVolumeServer(r, *ip, *vport, *publicIp, folders, maxCounts,
|
2013-12-02 09:37:36 +00:00
|
|
|
*masterNode, *vpulse, *dataCenter, *rack, volumeWhiteList,
|
2014-05-15 08:08:00 +00:00
|
|
|
*fixJpgOrientation,
|
2013-12-02 09:37:36 +00:00
|
|
|
)
|
2012-08-24 05:46:54 +00:00
|
|
|
|
2014-04-26 05:09:42 +00:00
|
|
|
listeningAddress := *ip + ":" + strconv.Itoa(*vport)
|
|
|
|
|
|
|
|
glog.V(0).Infoln("Start Weed volume server", util.VERSION, "at", listeningAddress)
|
|
|
|
|
|
|
|
listener, e := util.NewListener(listeningAddress, time.Duration(*vTimeout)*time.Second)
|
2012-08-24 05:46:54 +00:00
|
|
|
if e != nil {
|
2014-03-20 18:07:15 +00:00
|
|
|
glog.Fatalf(e.Error())
|
|
|
|
}
|
|
|
|
|
2014-05-13 22:04:04 +00:00
|
|
|
OnInterrupt(func() {
|
|
|
|
volumeServer.Shutdown()
|
|
|
|
})
|
2014-05-13 07:04:28 +00:00
|
|
|
|
2014-03-20 18:07:15 +00:00
|
|
|
if e := http.Serve(listener, r); e != nil {
|
|
|
|
glog.Fatalf("Fail to serve:%s", e.Error())
|
2012-08-24 05:46:54 +00:00
|
|
|
}
|
|
|
|
return true
|
2012-08-07 08:29:22 +00:00
|
|
|
}
|