1
0
mirror of https://github.com/rancher/os.git synced 2025-06-28 15:56:58 +00:00

Execute start scripts using bash

This commit is contained in:
Josh Curl 2016-08-31 16:18:51 -07:00
parent bd904fcbda
commit d4a026dc5d
No known key found for this signature in database
GPG Key ID: 82B504B9BCCFA677
4 changed files with 62 additions and 29 deletions

View File

@ -105,25 +105,14 @@ func Main() {
cloudinitexecute.ApplyConsole(cfg)
if util.ExistsAndExecutable(config.CloudConfigScriptFile) {
cmd := exec.Command(config.CloudConfigScriptFile)
if err := cmd.Run(); err != nil {
log.Error(err)
}
if err := runScript(config.CloudConfigScriptFile); err != nil {
log.Error(err)
}
if util.ExistsAndExecutable(startScript) {
cmd := exec.Command(startScript)
if err := cmd.Run(); err != nil {
log.Error(err)
}
if err := runScript(startScript); err != nil {
log.Error(err)
}
if util.ExistsAndExecutable("/etc/rc.local") {
cmd := exec.Command("/etc/rc.local")
if err := cmd.Run(); err != nil {
log.Error(err)
}
if err := runScript("/etc/rc.local"); err != nil {
log.Error(err)
}
os.Setenv("TERM", "linux")
@ -292,3 +281,26 @@ func setupSSH(cfg *config.CloudConfig) error {
return os.MkdirAll("/var/run/sshd", 0644)
}
func runScript(path string) error {
if !util.ExistsAndExecutable(config.CloudConfigScriptFile) {
return nil
}
script, err := os.Open(path)
if err != nil {
return err
}
magic := make([]byte, 2)
if _, err = script.Read(magic); err != nil {
return err
}
cmd := exec.Command("/bin/sh", path)
if string(magic) == "#!" {
cmd = exec.Command(path)
}
return cmd.Run()
}

View File

@ -5,7 +5,23 @@ write_files:
owner: root
content: |
#!/bin/bash
touch /home/rancher/test
touch /home/rancher/test1
- path: /opt/rancher/bin/start.sh
permissions: "0755"
owner: root
content: |
touch /home/rancher/test3
- path: /etc/rc.local
permissions: "0755"
owner: root
content: |
touch /home/rancher/test4
- path: /var/lib/rancher/conf/cloud-config-script
permissions: "0755"
owner: root
content: |
#!/bin/bash
touch /home/rancher/test5
runcmd:
- []
- [ test ]

View File

@ -1,11 +0,0 @@
package integration
import . "gopkg.in/check.v1"
func (s *QemuSuite) TestRuncmd(c *C) {
err := s.RunQemu("--cloud-config", "./tests/assets/test_26/cloud-config.yml")
c.Assert(err, IsNil)
s.CheckCall(c, "ls /home/rancher | grep test")
s.CheckCall(c, "ls /home/rancher | grep test2")
}

View File

@ -0,0 +1,16 @@
package integration
import (
"fmt"
. "gopkg.in/check.v1"
)
func (s *QemuSuite) TestStartCommands(c *C) {
err := s.RunQemu("--cloud-config", "./tests/assets/test_26/cloud-config.yml")
c.Assert(err, IsNil)
for i := 1; i < 6; i++ {
s.CheckCall(c, fmt.Sprintf("ls /home/rancher | grep test%d", i))
}
}