ROS Startup Script

Is anyone else having difficulty getting startup scripts to actually run? I have a “known-working” cloud-configthat also writes out the startup script successfully… but then, the script does not run. Here is that cloud-config:

(kept “I’m doing things on start” because … nice."

rancher:
  network:
    dns:
      nameserver:
        - 8.8.4.4
    interfaces:
      eth0:
        dhcp: true
  state:
   fstype: auto
   dev: LABEL=RANCHER_STATE
   autoformat:
     - /dev/sda
write_files:
  - path: /opt/rancher/bin/start.sh
    permissions: "0755"
    owner: root
    content: |
      #!/bin/bash
      echo "I'm doing things on start"
      sudo docker run -d --privileged -v /var/run/docker.sock:/var/run/docker.sock rancher/agent:v0.8.2 http://192.168.100.104:8080/v1/scripts/329112598C875AC4281E:1446123600000:bObtCFAc6k9A2hjaaR4IBq8Yg

Could you format the code so that i could try and use the same cloud-config?

We ran into the exact same problem over the weekend. We have a cloud-config that creates a start.sh script that we’ve been using successfully with ROS v0.3.3 that doesn’t work at all with ROS v0.4.0 (or later, tried the same cloud-config with the latest version of ROS, v0.4.1).

When we checked into the problem a bit more, we noticed that the start.sh script isn’t created at all if the permissions are set as they always were with previous ROS versions (like you, we’d set our permissions to 0755, as was shown in the example we’d worked off of from the RancherOS website). When we modified the cloud-config to use 755 for the permissions instead, the script was created in the appropriate directory (/opt/rancher/bin) and the script does seem to execute during the node boot process.

However, that has led us to another issue that we have yet to sort out. Although the script is run at boot time with the new permissions, the docker commands in that script fail to run (we have two docker commands in our start.sh script that load a docker image that is downloaded from a local web server and start that image as a docker container and when we check the ROS instance after it boots successfully that image has not been loaded and, as a result, the container is not running. Keep in mind that this same cloud-config worked without issues under ROS v.0.3.3, so something has obviously changed and we just haven’t been able to sort out the changes yet…

@denise Added backticks around the yml, usually when it looks flat they just forgot the code fence… you can edit people’s posts too :slight_smile:

So, I’v tried to reproduce and here’s what I’ve got. My cloud-config is:

#cloud-config
write_files:
  - path: /opt/rancher/bin/start.sh
    permissions: "0755"
    owner: root
    content: |
      #!/bin/bash
      echo "I'm doing things on start" > /opt/start-sh-did-this

After I’ve logged in I can see /opt/start-sh-did-this file is there with the expected content.

@tjmcs Docker cannot be used in these startup scripts as docker service starts after console in v0.4.0+. The best way to run docker containers on start is run them as services (I admit, I should spend more time on the docs), e.g. like with this cloud-config (adapted from @Jacob_Gadikian’s docker-run command above, this one runs Rancher Agent v0.8.2 as a privileged container bind-mounting /var/run/docker.sock):

#cloud-config
rancher:
  services:
    rancher-agent:
      image: rancher/agent:v0.8.2
      command: http://192.168.100.104:8080/v1/scripts/skipped-the-base64-stuff
      privileged: true
      volumes:
      - /var/run/docker.sock:/var/run/docker.sock