github.com/altoros/juju-vmware@v0.0.0-20150312064031-f19ae857ccca/upgrades/lockdirectory.go (about) 1 // Copyright 2014 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package upgrades 5 6 import ( 7 "fmt" 8 "path" 9 10 "github.com/juju/utils/exec" 11 ) 12 13 var ubuntuHome = "/home/ubuntu" 14 15 // Previously the lock directory was created when the uniter started. This 16 // allows serialization of all of the hook execution across units running on a 17 // single machine. This lock directory is now also used but the juju-run 18 // command on the host machine. juju-run also gets a lock on the hook 19 // execution fslock prior to execution. However, the lock directory was owned 20 // by root, and the juju-run process was being executed by the ubuntu user, so 21 // we need to change the ownership of the lock directory to ubuntu:ubuntu. 22 // Also we need to make sure that this directory exists on machines with no 23 // units. 24 func ensureLockDirExistsAndUbuntuWritable(context Context) error { 25 lockDir := path.Join(context.AgentConfig().DataDir(), "locks") 26 // We only try to change ownership if there is an ubuntu user 27 // defined, and we determine this by the existance of the home dir. 28 command := fmt.Sprintf(""+ 29 "mkdir -p %s\n"+ 30 "[ -e %s ] && chown ubuntu:ubuntu %s\n", 31 lockDir, ubuntuHome, lockDir) 32 logger.Tracef("command: %s", command) 33 result, err := exec.RunCommands(exec.RunParams{ 34 Commands: command, 35 }) 36 if err != nil { 37 return err 38 } 39 logger.Tracef("stdout: %s", result.Stdout) 40 return nil 41 }