Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Sharkey
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dima Krasner
Sharkey
Commits
112c68cd
Unverified
Commit
112c68cd
authored
4 years ago
by
marihachi
Committed by
GitHub
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
refactor init (#7464)
parent
4e5e542f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/boot/master.ts
+36
-35
36 additions, 35 deletions
src/boot/master.ts
with
36 additions
and
35 deletions
src/boot/master.ts
+
36
−
35
View file @
112c68cd
...
...
@@ -45,26 +45,15 @@ function greet() {
export
async
function
masterMain
()
{
let
config
!
:
Config
;
// initialize app
try
{
greet
();
// initialize app
config
=
await
init
();
if
(
config
.
port
==
null
||
Number
.
isNaN
(
config
.
port
))
{
bootLogger
.
error
(
'
The port is not configured. Please configure port.
'
,
null
,
true
);
process
.
exit
(
1
);
}
if
(
process
.
platform
===
'
linux
'
&&
isWellKnownPort
(
config
.
port
)
&&
!
isRoot
())
{
bootLogger
.
error
(
'
You need root privileges to listen on well-known port on Linux
'
,
null
,
true
);
process
.
exit
(
1
);
}
if
(
!
await
isPortAvailable
(
config
.
port
))
{
bootLogger
.
error
(
`Port
${
config
.
port
}
is already in use`
,
null
,
true
);
process
.
exit
(
1
);
}
showEnvironment
();
await
showMachineInfo
(
bootLogger
);
showNodejsVersion
();
config
=
loadConfigBoot
();
await
connectDb
();
await
validatePort
(
config
);
}
catch
(
e
)
{
bootLogger
.
error
(
'
Fatal error occurred during initialization
'
,
null
,
true
);
process
.
exit
(
1
);
...
...
@@ -89,14 +78,6 @@ const runningNodejsVersion = process.version.slice(1).split('.').map(x => parseI
const
requiredNodejsVersion
=
[
11
,
7
,
0
];
const
satisfyNodejsVersion
=
!
lessThan
(
runningNodejsVersion
,
requiredNodejsVersion
);
function
isWellKnownPort
(
port
:
number
):
boolean
{
return
port
<
1024
;
}
async
function
isPortAvailable
(
port
:
number
):
Promise
<
boolean
>
{
return
await
portscanner
.
checkPortStatus
(
port
,
'
127.0.0.1
'
)
===
'
closed
'
;
}
function
showEnvironment
():
void
{
const
env
=
process
.
env
.
NODE_ENV
;
const
logger
=
bootLogger
.
createSubLogger
(
'
env
'
);
...
...
@@ -110,14 +91,7 @@ function showEnvironment(): void {
logger
.
info
(
`You
${
isRoot
()
?
''
:
'
do not
'
}
have root privileges`
);
}
/**
* Init app
*/
async
function
init
():
Promise
<
Config
>
{
showEnvironment
();
await
showMachineInfo
(
bootLogger
);
function
showNodejsVersion
():
void
{
const
nodejsLogger
=
bootLogger
.
createSubLogger
(
'
nodejs
'
);
nodejsLogger
.
info
(
`Version
${
runningNodejsVersion
.
join
(
'
.
'
)}
`
);
...
...
@@ -126,7 +100,9 @@ async function init(): Promise<Config> {
nodejsLogger
.
error
(
`Node.js version is less than
${
requiredNodejsVersion
.
join
(
'
.
'
)}
. Please upgrade it.`
,
null
,
true
);
process
.
exit
(
1
);
}
}
function
loadConfigBoot
():
Config
{
const
configLogger
=
bootLogger
.
createSubLogger
(
'
config
'
);
let
config
;
...
...
@@ -146,6 +122,10 @@ async function init(): Promise<Config> {
configLogger
.
succ
(
'
Loaded
'
);
return
config
;
}
async
function
connectDb
():
Promise
<
void
>
{
const
dbLogger
=
bootLogger
.
createSubLogger
(
'
db
'
);
// Try to connect to DB
...
...
@@ -159,8 +139,29 @@ async function init(): Promise<Config> {
dbLogger
.
error
(
e
);
process
.
exit
(
1
);
}
}
return
config
;
async
function
validatePort
(
config
:
Config
):
Promise
<
void
>
{
const
isWellKnownPort
=
(
port
:
number
)
=>
port
<
1024
;
async
function
isPortAvailable
(
port
:
number
):
Promise
<
boolean
>
{
return
await
portscanner
.
checkPortStatus
(
port
,
'
127.0.0.1
'
)
===
'
closed
'
;
}
if
(
config
.
port
==
null
||
Number
.
isNaN
(
config
.
port
))
{
bootLogger
.
error
(
'
The port is not configured. Please configure port.
'
,
null
,
true
);
process
.
exit
(
1
);
}
if
(
process
.
platform
===
'
linux
'
&&
isWellKnownPort
(
config
.
port
)
&&
!
isRoot
())
{
bootLogger
.
error
(
'
You need root privileges to listen on well-known port on Linux
'
,
null
,
true
);
process
.
exit
(
1
);
}
if
(
!
await
isPortAvailable
(
config
.
port
))
{
bootLogger
.
error
(
`Port
${
config
.
port
}
is already in use`
,
null
,
true
);
process
.
exit
(
1
);
}
}
async
function
spawnWorkers
(
limit
:
number
=
1
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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