Skip to content

Commit

Permalink
service: ensure user home directory is present.
Browse files Browse the repository at this point in the history
  • Loading branch information
kardianos committed May 21, 2015
1 parent 03368a8 commit 4be10ae
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion service_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"os/signal"
"os/user"
"path/filepath"
"syscall"
"text/template"
"time"
Expand All @@ -33,6 +34,8 @@ func (darwinSystem) New(i Interface, c *Config) (Service, error) {
s := &darwinLaunchdService{
i: i,
Config: c,

userService: c.Option.bool(optionUserService, optionUserServiceDefault),
}

return s, nil
Expand Down Expand Up @@ -60,6 +63,8 @@ func isInteractive() (bool, error) {
type darwinLaunchdService struct {
i Interface
*Config

userService bool
}

func (s *darwinLaunchdService) String() string {
Expand All @@ -70,7 +75,7 @@ func (s *darwinLaunchdService) String() string {
}

func (s *darwinLaunchdService) getServiceFilePath() (string, error) {
if s.Option.bool(optionUserService, optionUserServiceDefault) {
if s.userService {
u, err := user.Current()
if err != nil {
return "", err
Expand All @@ -90,6 +95,14 @@ func (s *darwinLaunchdService) Install() error {
return fmt.Errorf("Init already exists: %s", confPath)
}

if s.userService {
// Ensure that ~/Library/LaunchAgents exists.
err = os.MkdirAll(filepath.Dir(confPath), 0700)
if err != nil {
return err
}
}

f, err := os.Create(confPath)
if err != nil {
return err
Expand Down

0 comments on commit 4be10ae

Please sign in to comment.