service: ensure user home directory is present.
This commit is contained in:
+14
-1
@@ -9,6 +9,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"os/user"
|
"os/user"
|
||||||
|
"path/filepath"
|
||||||
"syscall"
|
"syscall"
|
||||||
"text/template"
|
"text/template"
|
||||||
"time"
|
"time"
|
||||||
@@ -33,6 +34,8 @@ func (darwinSystem) New(i Interface, c *Config) (Service, error) {
|
|||||||
s := &darwinLaunchdService{
|
s := &darwinLaunchdService{
|
||||||
i: i,
|
i: i,
|
||||||
Config: c,
|
Config: c,
|
||||||
|
|
||||||
|
userService: c.Option.bool(optionUserService, optionUserServiceDefault),
|
||||||
}
|
}
|
||||||
|
|
||||||
return s, nil
|
return s, nil
|
||||||
@@ -60,6 +63,8 @@ func isInteractive() (bool, error) {
|
|||||||
type darwinLaunchdService struct {
|
type darwinLaunchdService struct {
|
||||||
i Interface
|
i Interface
|
||||||
*Config
|
*Config
|
||||||
|
|
||||||
|
userService bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *darwinLaunchdService) String() string {
|
func (s *darwinLaunchdService) String() string {
|
||||||
@@ -70,7 +75,7 @@ func (s *darwinLaunchdService) String() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *darwinLaunchdService) getServiceFilePath() (string, error) {
|
func (s *darwinLaunchdService) getServiceFilePath() (string, error) {
|
||||||
if s.Option.bool(optionUserService, optionUserServiceDefault) {
|
if s.userService {
|
||||||
u, err := user.Current()
|
u, err := user.Current()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@@ -90,6 +95,14 @@ func (s *darwinLaunchdService) Install() error {
|
|||||||
return fmt.Errorf("Init already exists: %s", confPath)
|
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)
|
f, err := os.Create(confPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
Reference in New Issue
Block a user