Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
22fa00199
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Summer2022
22fa00199
Commits
a8160e64
Unverified
Commit
a8160e64
authored
2 years ago
by
fagongzi
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add service main (#4207)
parent
e403fde8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
cmd/mo-service/cfg.go
+79
-0
79 additions, 0 deletions
cmd/mo-service/cfg.go
cmd/mo-service/main.go
+95
-0
95 additions, 0 deletions
cmd/mo-service/main.go
cmd/mo-service/version.go
+47
-0
47 additions, 0 deletions
cmd/mo-service/version.go
with
221 additions
and
0 deletions
cmd/mo-service/cfg.go
0 → 100644
+
79
−
0
View file @
a8160e64
// Copyright 2022 Matrix Origin
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package
main
import
(
"fmt"
"os"
"strings"
"github.com/BurntSushi/toml"
"github.com/matrixorigin/matrixone/pkg/dnservice"
"github.com/matrixorigin/matrixone/pkg/logutil"
)
const
(
cnServiceType
=
"CN"
dnServiceType
=
"DN"
logServiceType
=
"LOG"
standaloneServiceType
=
"STANDALONE"
)
var
(
supportServiceTypes
=
map
[
string
]
any
{
cnServiceType
:
cnServiceType
,
dnServiceType
:
dnServiceType
,
logServiceType
:
logServiceType
,
standaloneServiceType
:
standaloneServiceType
,
}
)
// Config mo-service configuration
type
Config
struct
{
// Log log config
Log
logutil
.
LogConfig
`toml:"log"`
// ServiceType service type, select the corresponding configuration to start the
// service according to the service type. [CN|DN|Log|Standalone]
ServiceType
string
`toml:"service-type"`
// DN dn service config
DN
dnservice
.
Config
`toml:"dn"`
}
func
parseConfigFromFile
(
file
string
)
(
*
Config
,
error
)
{
if
file
==
""
{
return
nil
,
fmt
.
Errorf
(
"toml config file not set"
)
}
data
,
err
:=
os
.
ReadFile
(
file
)
if
err
!=
nil
{
return
nil
,
err
}
cfg
:=
&
Config
{}
if
_
,
err
=
toml
.
Decode
(
string
(
data
),
cfg
);
err
!=
nil
{
return
nil
,
err
}
if
err
:=
cfg
.
validate
();
err
!=
nil
{
return
nil
,
err
}
return
cfg
,
nil
}
func
(
c
*
Config
)
validate
()
error
{
if
_
,
ok
:=
supportServiceTypes
[
strings
.
ToUpper
(
c
.
ServiceType
)];
!
ok
{
return
fmt
.
Errorf
(
"service type %s not support"
,
c
.
ServiceType
)
}
return
nil
}
This diff is collapsed.
Click to expand it.
cmd/mo-service/main.go
0 → 100644
+
95
−
0
View file @
a8160e64
// Copyright 2022 Matrix Origin
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package
main
import
(
"context"
"errors"
"flag"
"fmt"
"os"
"os/signal"
"strings"
"syscall"
"github.com/matrixorigin/matrixone/pkg/common/stopper"
"github.com/matrixorigin/matrixone/pkg/dnservice"
"github.com/matrixorigin/matrixone/pkg/logutil"
)
var
(
uuid
=
flag
.
String
(
"uuid"
,
""
,
"UUID of the service node"
)
configFile
=
flag
.
String
(
"cfg"
,
"./mo.toml"
,
"toml configuration used to start mo-service"
)
version
=
flag
.
Bool
(
"version"
,
false
,
"print version information"
)
)
func
main
()
{
flag
.
Parse
()
maybePrintVersion
()
cfg
,
err
:=
parseConfigFromFile
(
*
configFile
)
if
err
!=
nil
{
panic
(
fmt
.
Sprintf
(
"failed to parse config from %s, error: %s"
,
*
configFile
,
err
.
Error
()))
}
setupLogger
(
cfg
)
stopper
:=
stopper
.
NewStopper
(
"main"
,
stopper
.
WithLogger
(
logutil
.
GetGlobalLogger
()))
if
err
:=
startService
(
cfg
,
stopper
);
err
!=
nil
{
panic
(
err
)
}
waitSignalToStop
(
stopper
)
}
func
setupLogger
(
cfg
*
Config
)
{
logutil
.
SetupMOLogger
(
&
cfg
.
Log
)
}
func
waitSignalToStop
(
stopper
*
stopper
.
Stopper
)
{
sigchan
:=
make
(
chan
os
.
Signal
,
1
)
signal
.
Notify
(
sigchan
,
syscall
.
SIGTERM
,
syscall
.
SIGINT
)
<-
sigchan
stopper
.
Stop
()
}
func
startService
(
cfg
*
Config
,
stopper
*
stopper
.
Stopper
)
error
{
// TODO: start other service
switch
strings
.
ToUpper
(
cfg
.
ServiceType
)
{
case
dnServiceType
:
return
startDNService
(
cfg
,
stopper
)
}
return
nil
}
func
startDNService
(
cfg
*
Config
,
stopper
*
stopper
.
Stopper
)
error
{
if
*
uuid
==
""
{
return
errors
.
New
(
"UUID not set"
)
}
return
stopper
.
RunNamedTask
(
"dn-service"
,
func
(
ctx
context
.
Context
)
{
s
,
err
:=
dnservice
.
NewService
(
&
cfg
.
DN
,
dnservice
.
WithLogger
(
logutil
.
GetGlobalLogger
()
.
Named
(
"dn-service"
)))
if
err
!=
nil
{
panic
(
err
)
}
if
err
:=
s
.
Start
();
err
!=
nil
{
panic
(
err
)
}
<-
ctx
.
Done
()
if
err
:=
s
.
Close
();
err
!=
nil
{
panic
(
err
)
}
})
}
This diff is collapsed.
Click to expand it.
cmd/mo-service/version.go
0 → 100644
+
47
−
0
View file @
a8160e64
// Copyright 2022 Matrix Origin
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package
main
import
(
"fmt"
"os"
)
var
(
// GoVersion go version, setup by makefile
GoVersion
=
""
// BranchName git branch, setup by makefile
BranchName
=
""
// CommitID git commit id, setup by makefile
CommitID
=
""
// BuildTime build time, setup by makefile
BuildTime
=
""
// Version version, setup by makefile
Version
=
""
)
func
maybePrintVersion
()
{
if
!*
version
{
return
}
fmt
.
Println
(
"MatrixOne build info:"
)
fmt
.
Printf
(
" The golang version used to build this binary: %s
\n
"
,
GoVersion
)
fmt
.
Printf
(
" Git branch name: %s
\n
"
,
BranchName
)
fmt
.
Printf
(
" Git commit ID: %s
\n
"
,
CommitID
)
fmt
.
Printf
(
" Buildtime: %s
\n
"
,
BuildTime
)
fmt
.
Printf
(
" Version: %s
\n
"
,
Version
)
os
.
Exit
(
0
)
}
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment