Skip to content
This repository has been archived by the owner on Mar 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #582 from aravindavk/systemd_service
Browse files Browse the repository at this point in the history
Default configuration for glusterd2 when run using `systemctl`
  • Loading branch information
kshlm authored Feb 27, 2018
2 parents b5f8705 + ae0fe1b commit 51e7ddc
Show file tree
Hide file tree
Showing 20 changed files with 62 additions and 55 deletions.
22 changes: 11 additions & 11 deletions doc/quick-start-user-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,29 +51,29 @@ $ mkdir -p /var/lib/gd2
```

**Create a config file:** This is optional but if your VM/machine has multiple network interfaces, it is recommended to create a config file. The config file location can be passed to Glusterd2 using the `--config` option.
Glusterd2 will also pick up conf files named `glusterd.{yaml|json|toml}` if available in `/etc/glusterd2/` or the current directory.

```yaml
$ cat conf.yaml
workdir: "/var/lib/gd2"
peeraddress: "192.168.56.101:24008"
clientaddress: "192.168.56.101:24007"
etcdcurls: "http://192.168.56.101:2379"
etcdpurls: "http://192.168.56.101:2380"
Glusterd2 will also pick up conf file named `glusterd2.toml` if available in `/etc/glusterd2/` or the current directory.

```toml
$ cat conf.toml
workdir = "/var/lib/gd2"
peeraddress = "192.168.56.101:24008"
clientaddress = "192.168.56.101:24007"
etcdcurls = "http://192.168.56.101:2379"
etcdpurls = "http://192.168.56.101:2380"
```

Replace the IP address accordingly on each node.

**Start glusterd2 process:** Glusterd2 is not a daemon and currently can run only in the foreground.

```sh
# ./glusterd2 --config conf.yaml
# ./glusterd2 --config conf.toml
```

You will see an output similar to the following:
```log
INFO[2017-08-28T16:03:58+05:30] Starting GlusterD pid=1650
INFO[2017-08-28T16:03:58+05:30] loaded configuration from file file=conf.yaml
INFO[2017-08-28T16:03:58+05:30] loaded configuration from file file=conf.toml
INFO[2017-08-28T16:03:58+05:30] Generated new UUID uuid=19db62df-799b-47f1-80e4-0f5400896e05
INFO[2017-08-28T16:03:58+05:30] started muxsrv listener
INFO[2017-08-28T16:03:58+05:30] Started GlusterD ReST server ip:port=192.168.56.101:24007
Expand Down
6 changes: 6 additions & 0 deletions e2e/config/1.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
workdir = "/tmp/gd2_func_test/w1"
logfile = "w1.log"
peeraddress = "127.0.0.1:24008"
clientaddress = "127.0.0.1:24007"
etcdcurls = "http://127.0.0.1:2479"
etcdpurls = "http://127.0.0.1:2480"
6 changes: 0 additions & 6 deletions e2e/config/1.yaml

This file was deleted.

6 changes: 6 additions & 0 deletions e2e/config/2.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
workdir = "/tmp/gd2_func_test/w2"
logfile = "w2.log"
peeraddress = "127.0.0.1:23008"
clientaddress = "127.0.0.1:23007"
etcdcurls = "http://127.0.0.1:2379"
etcdpurls = "http://127.0.0.1:2380"
6 changes: 0 additions & 6 deletions e2e/config/2.yaml

This file was deleted.

6 changes: 6 additions & 0 deletions e2e/config/3.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
workdir = "/tmp/gd2_func_test/w3"
logfile = "w3.log"
peeraddress = "127.0.0.1:22008"
clientaddress = "127.0.0.1:22007"
etcdcurls = "http://127.0.0.1:2279"
etcdpurls = "http://127.0.0.1:2280"
6 changes: 0 additions & 6 deletions e2e/config/3.yaml

This file was deleted.

7 changes: 7 additions & 0 deletions e2e/config/4.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
workdir = "/tmp/gd2_func_test/w4"
logfile = "w4.log"
peeraddress = "127.0.0.1:21008"
clientaddress = "127.0.0.1:21007"
etcdcurls = "http://127.0.0.1:2179"
etcdpurls = "http://127.0.0.1:2180"
restauth = true
7 changes: 0 additions & 7 deletions e2e/config/4.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion e2e/georep_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
func TestGeorepCreateDelete(t *testing.T) {
r := require.New(t)

gds, err := setupCluster("./config/1.yaml", "./config/2.yaml")
gds, err := setupCluster("./config/1.toml", "./config/2.toml")
r.Nil(err)
defer teardownCluster(gds)

Expand Down
2 changes: 1 addition & 1 deletion e2e/glustershd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func TestGlusterShd(t *testing.T) {

r := require.New(t)

gds, err := setupCluster("./config/1.yaml", "./config/2.yaml")
gds, err := setupCluster("./config/1.toml", "./config/2.toml")
r.Nil(err)
defer teardownCluster(gds)

Expand Down
6 changes: 3 additions & 3 deletions e2e/peer_ops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ import (
func TestAddRemovePeer(t *testing.T) {
r := require.New(t)

g1, err := spawnGlusterd("./config/1.yaml", true)
g1, err := spawnGlusterd("./config/1.toml", true)
r.Nil(err)
defer g1.Stop()
defer g1.EraseWorkdir()
r.True(g1.IsRunning())

g2, err := spawnGlusterd("./config/2.yaml", true)
g2, err := spawnGlusterd("./config/2.toml", true)
r.Nil(err)
defer g2.Stop()
defer g2.EraseWorkdir()
r.True(g2.IsRunning())

g3, err := spawnGlusterd("./config/3.yaml", true)
g3, err := spawnGlusterd("./config/3.toml", true)
r.Nil(err)
defer g3.Stop()
defer g3.EraseWorkdir()
Expand Down
2 changes: 1 addition & 1 deletion e2e/quota_enable.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func testQuotaEnable(t *testing.T) {
var err error
r := require.New(t)

gds, err := setupCluster("./config/1.yaml", "./config/2.yaml")
gds, err := setupCluster("./config/1.toml", "./config/2.toml")
r.Nil(err)
defer teardownCluster(gds)

Expand Down
2 changes: 1 addition & 1 deletion e2e/restapi_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
func TestRESTAPIAuth(t *testing.T) {
r := require.New(t)

g1, err := spawnGlusterd("./config/4.yaml", true)
g1, err := spawnGlusterd("./config/4.toml", true)
r.Nil(err)
defer g1.Stop()
defer g1.EraseWorkdir()
Expand Down
4 changes: 2 additions & 2 deletions e2e/restart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
func TestRestart(t *testing.T) {
r := require.New(t)

gd, err := spawnGlusterd("./config/1.yaml", true)
gd, err := spawnGlusterd("./config/1.toml", true)
r.Nil(err)
r.True(gd.IsRunning())

Expand Down Expand Up @@ -42,7 +42,7 @@ func TestRestart(t *testing.T) {

r.Nil(gd.Stop())

gd, err = spawnGlusterd("./config/1.yaml", false)
gd, err = spawnGlusterd("./config/1.toml", false)
r.Nil(err)
r.True(gd.IsRunning())

Expand Down
11 changes: 6 additions & 5 deletions e2e/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ import (

"github.com/gluster/glusterd2/pkg/api"
"github.com/gluster/glusterd2/pkg/restclient"
"gopkg.in/yaml.v2"

toml "github.com/pelletier/go-toml"
)

type gdProcess struct {
Cmd *exec.Cmd
ClientAddress string `yaml:"clientaddress"`
PeerAddress string `yaml:"peeraddress"`
Workdir string `yaml:"workdir"`
ClientAddress string `toml:"clientaddress"`
PeerAddress string `toml:"peeraddress"`
Workdir string `toml:"workdir"`
uuid string
}

Expand Down Expand Up @@ -98,7 +99,7 @@ func spawnGlusterd(configFilePath string, cleanStart bool) (*gdProcess, error) {
}

g := gdProcess{}
if err = yaml.Unmarshal(fContent, &g); err != nil {
if err = toml.Unmarshal(fContent, &g); err != nil {
return nil, err
}

Expand Down
4 changes: 2 additions & 2 deletions e2e/volume_ops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestVolume(t *testing.T) {

r := require.New(t)

gds, err = setupCluster("./config/1.yaml", "./config/2.yaml")
gds, err = setupCluster("./config/1.toml", "./config/2.toml")
r.Nil(err)
defer teardownCluster(gds)

Expand Down Expand Up @@ -192,7 +192,7 @@ func TestVolumeOptions(t *testing.T) {

r := require.New(t)

gds, err := setupCluster("./config/1.yaml")
gds, err := setupCluster("./config/1.toml")
r.Nil(err)
defer teardownCluster(gds)

Expand Down
2 changes: 1 addition & 1 deletion extras/systemd/glusterd2.service
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Before=network-online.target
Conflicts=glusterd.service

[Service]
ExecStart=/usr/sbin/glusterd2
ExecStart=/usr/sbin/glusterd2 --config=/etc/glusterd2/glusterd2.toml
KillMode=process

[Install]
Expand Down
7 changes: 5 additions & 2 deletions glusterd2/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func parseFlags() {
flag.String("workdir", "", "Working directory for GlusterD. (default: current directory)")
flag.String("localstatedir", "", "Directory to store local state information. (default: workdir)")
flag.String("rundir", "", "Directory to store runtime data. (default: workdir/run)")
flag.String("config", "", "Configuration file for GlusterD. By default looks for glusterd2.(yaml|toml|json) in [/usr/local]/etc/glusterd2 and current working directory.")
flag.String("config", "", "Configuration file for GlusterD. By default looks for glusterd2.toml in [/usr/local]/etc/glusterd2 and current working directory.")

flag.String(logging.DirFlag, "", logging.DirHelp+" (default: workdir/log)")
flag.String(logging.FileFlag, "STDOUT", logging.FileHelp)
Expand Down Expand Up @@ -135,6 +135,9 @@ func initConfig(confFile string) error {
// If a config file was given, read in configration from that file.
// If the file is not present panic.

// Limit config to toml only to avoid confusion with multiple config types
config.SetConfigType("toml")

if confFile == "" {
config.SetConfigName(defaultConfName)
for _, p := range defaultConfPaths {
Expand All @@ -148,7 +151,7 @@ func initConfig(confFile string) error {
if confFile == "" {
log.WithFields(log.Fields{
"paths": defaultConfPaths,
"config": defaultConfName + ".(toml|yaml|json)",
"config": defaultConfName + ".toml",
"error": err,
}).Debug("failed to read any config files, continuing with defaults")
} else {
Expand Down
3 changes: 3 additions & 0 deletions scripts/gen-gd2conf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ PREFIX=${PREFIX:-/usr/local}
DATADIR=${DATADIR:-$PREFIX/share}
LOCALSTATEDIR=${LOCALSTATEDIR:-$PREFIX/var/lib}
LOGDIR=${LOGDIR:-$PREFIX/var/log}
RUNDIR=${RUNDIR:-$PREFIX/var/run}

GD2="glusterd2"
GD2STATEDIR=${GD2STATEDIR:-$LOCALSTATEDIR/$GD2}
GD2LOGDIR=${GD2LOGDIR:-$LOGDIR/$GD2}
GD2RUNDIR=${GD2RUNDIR:-$RUNDIR/$GD2}

OUTDIR=${1:-build}
mkdir -p $OUTDIR
Expand All @@ -19,4 +21,5 @@ cat >$OUTPUT <<EOF
localstatedir = "$GD2STATEDIR"
logdir = "$GD2LOGDIR"
logfile = "$GD2.log"
rundir = "$GD2RUNDIR"
EOF

0 comments on commit 51e7ddc

Please sign in to comment.