Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caddy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
caddy
Commits
9a78857b
Commit
9a78857b
authored
May 05, 2015
by
Matthew Holt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Startup/shutdown commands run in background with &
parent
1e730a74
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
3 deletions
+17
-3
config/setup/startupshutdown.go
config/setup/startupshutdown.go
+17
-3
No files found.
config/setup/startupshutdown.go
View file @
9a78857b
...
...
@@ -3,6 +3,7 @@ package setup
import
(
"os"
"os/exec"
"strings"
"github.com/mholt/caddy/middleware"
)
...
...
@@ -20,11 +21,19 @@ func Shutdown(c *Controller) (middleware.Middleware, error) {
// to the list of callback functions passed in by reference.
func
registerCallback
(
c
*
Controller
,
list
*
[]
func
()
error
)
error
{
for
c
.
Next
()
{
if
!
c
.
NextArg
()
{
args
:=
c
.
RemainingArgs
()
if
len
(
args
)
==
0
{
return
c
.
ArgErr
()
}
command
,
args
,
err
:=
middleware
.
SplitCommandAndArgs
(
c
.
Val
())
nonblock
:=
false
if
len
(
args
)
>
1
&&
args
[
len
(
args
)
-
1
]
==
"&"
{
// Run command in background; non-blocking
nonblock
=
true
args
=
args
[
:
len
(
args
)
-
1
]
}
command
,
args
,
err
:=
middleware
.
SplitCommandAndArgs
(
strings
.
Join
(
args
,
" "
))
if
err
!=
nil
{
return
c
.
Err
(
err
.
Error
())
}
...
...
@@ -33,8 +42,13 @@ func registerCallback(c *Controller, list *[]func() error) error {
cmd
:=
exec
.
Command
(
command
,
args
...
)
cmd
.
Stdout
=
os
.
Stdout
cmd
.
Stderr
=
os
.
Stderr
if
nonblock
{
return
cmd
.
Start
()
}
else
{
return
cmd
.
Run
()
}
}
*
list
=
append
(
*
list
,
fn
)
}
...
...
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