Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Hypha
Tools
Indie Web Server
Commits
e464f986
Verified
Commit
e464f986
authored
Apr 12, 2019
by
Aral Balkan
Browse files
Implement logs and status commands
parent
43d99fb1
Changes
1
Hide whitespace changes
Inline
Side-by-side
bin/web-server.js
View file @
e464f986
...
...
@@ -5,7 +5,6 @@ const path = require('path')
const
ansi
=
require
(
'
ansi-escape-sequences
'
)
const
webServer
=
require
(
'
../index.js
'
)
const
pm2
=
require
(
'
pm2
'
)
const
childProcess
=
require
(
'
child_process
'
)
const
arguments
=
require
(
'
minimist
'
)(
process
.
argv
.
slice
(
2
),
{
boolean
:
true
})
...
...
@@ -48,13 +47,13 @@ const command = {
isOff
:
(
arguments
.
off
||
firstPositionalArgument
===
'
off
'
),
isMonitor
:
(
arguments
.
monitor
||
firstPositionalArgument
===
'
monitor
'
),
isLogs
:
(
arguments
.
logs
||
firstPositionalArgument
===
'
logs
'
),
is
Info
:
(
arguments
.
info
||
firstPositionalArgument
===
'
info
'
)
is
Status
:
(
arguments
.
status
||
firstPositionalArgument
===
'
status
'
)
}
// If we didn’t match a command, we default to dev.
const
didMatchCommand
=
Object
.
values
(
command
).
reduce
((
p
,
n
)
=>
p
||
n
)
command
.
isDev
=
(
arguments
.
dev
||
firstPositionalArgument
===
'
dev
'
||
!
didMatchCommand
)
const
firstPositionalArgumentDidMatchCommand
=
[
'
version
'
,
'
help
'
,
'
test
'
,
'
on
'
,
'
off
'
,
'
monitor
'
,
'
logs
'
,
'
info
'
].
reduce
((
p
,
n
)
=>
p
||
(
firstPositionalArgument
===
n
),
false
)
const
firstPositionalArgumentDidMatchCommand
=
[
'
version
'
,
'
help
'
,
'
test
'
,
'
on
'
,
'
off
'
,
'
monitor
'
,
'
logs
'
,
'
status
'
].
reduce
((
p
,
n
)
=>
p
||
(
firstPositionalArgument
===
n
),
false
)
// Help / usage instructions.
if
(
command
.
isHelp
)
{
...
...
@@ -69,7 +68,7 @@ if (command.isHelp) {
const
usageOff
=
`
${
clr
(
'
off
'
,
'
green
'
)}
`
const
usageMonitor
=
`
${
clr
(
'
monitor
'
,
'
green
'
)}
`
const
usageLogs
=
`
${
clr
(
'
logs
'
,
'
green
'
)}
`
const
usage
Info
=
`
${
clr
(
'
info
'
,
'
green
'
)}
`
const
usage
Status
=
`
${
clr
(
'
status
'
,
'
green
'
)}
`
const
usagePort
=
`
${
clr
(
'
--port
'
,
'
yellow
'
)}
=
${
clr
(
'
N
'
,
'
cyan
'
)}
`
const
usage
=
`
...
...
@@ -78,7 +77,7 @@ if (command.isHelp) {
${
clr
(
'
web-server
'
,
'
bold
'
)}
[
${
usageCommand
}
] [
${
usageFolderToServe
}
] [
${
usageOptions
}
]
${
usageCommand
}
\t
${
usageVersion
}
|
${
usageHelp
}
|
${
usageDev
}
|
${
usageTest
}
|
${
usageOn
}
|
${
usageOff
}
|
${
usageMonitor
}
|
${
usageLogs
}
|
${
usage
Info
}
${
usageCommand
}
\t
${
usageVersion
}
|
${
usageHelp
}
|
${
usageDev
}
|
${
usageTest
}
|
${
usageOn
}
|
${
usageOff
}
|
${
usageMonitor
}
|
${
usageLogs
}
|
${
usage
Status
}
${
usageFolderToServe
}
\tPath of folder to serve (defaults to current folder).
${
usageOptions
}
\tSettings that alter server characteristics.
...
...
@@ -96,7 +95,7 @@ if (command.isHelp) {
${
usageOff
}
\t\tTurn server off and remove it from startup items.
${
usageMonitor
}
\tMonitor server state.
${
usageLogs
}
\t\tDisplay and tail server logs.
${
usage
Info
}
\t\tDisplay detailed server information.
${
usage
Status
}
\t\tDisplay detailed server information.
If
${
usageCommand
}
is omitted, behaviour defaults to
${
usageDev
}
.
...
...
@@ -124,14 +123,14 @@ switch (true) {
childProcess
.
fork
(
pm2Path
,
[
'
monit
'
],
{
env
:
process
.
env
})
break
// Logs (proxy:
pm2 logs
web-server)
// Logs (proxy:
journalctl --follow --unit
web-server)
case
command
.
isLogs
:
childProcess
.
fork
(
pm2Path
,
[
'
logs
'
,
'
web-server
'
],
{
env
:
process
.
env
})
childProcess
.
spawn
(
'
journalctl
'
,
[
'
--follow
'
,
'
--unit
'
,
'
web-server
'
],
{
env
:
process
.
env
,
stdio
:
'
inherit
'
})
break
//
Info
(proxy:
pm2 show
web-server)
case
command
.
is
Info
:
childProcess
.
fork
(
pm2Path
,
[
'
show
'
,
'
web-server
'
],
{
env
:
process
.
env
})
//
Status
(proxy:
systemctl status
web-server)
case
command
.
is
Status
:
childProcess
.
spawn
(
'
systemctl
'
,
[
'
status
'
,
'
web-server
'
],
{
env
:
process
.
env
,
stdio
:
'
inherit
'
})
break
// Off (turn off the server daemon and remove it from startup items).
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment