# ROS Startup Script

**URL:** <https://forums.suse.com/t/ros-startup-script/829>\
**Category:** RancherOS\
**Created:** [October 30, 2015, 5:30pm UTC](https://forums.suse.com/t/ros-startup-script/829 "2015-10-30T17:30:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jacob\_Gadikian](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/jacob_gadikian/32/45_2.png) [@Jacob\_Gadikian](https://forums.suse.com/u/Jacob_Gadikian)\
**Post date:** [October 30, 2015, 5:30pm UTC](https://forums.suse.com/t/ros-startup-script/829/1 "2015-10-30T17:30:46Z")

</div>

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."

```auto
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

```

---

<div class="post-metadata">

**Author:** ![denise](https://avatars.discourse-cdn.com/v4/letter/d/82dd89/32.png) [@denise](https://forums.suse.com/u/denise)\
**Post date:** [November 2, 2015, 7:13pm UTC](https://forums.suse.com/t/ros-startup-script/829/2 "2015-11-02T19:13:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tjmcs](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/tjmcs/32/508_2.png) [@tjmcs](https://forums.suse.com/u/tjmcs)\
**Post date:** [November 16, 2015, 6:59pm UTC](https://forums.suse.com/t/ros-startup-script/829/3 "2015-11-16T18:59:19Z")

</div>

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](http://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…

---

<div class="post-metadata">

**Author:** ![vincent](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/vincent/32/7156_2.png) [@vincent](https://forums.suse.com/u/vincent)\
**Post date:** [November 17, 2015, 12:06am UTC](https://forums.suse.com/t/ros-startup-script/829/4 "2015-11-17T00:06:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![imikushin](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/imikushin/32/17_2.png) [@imikushin](https://forums.suse.com/u/imikushin)\
**Post date:** [November 18, 2015, 5:47am UTC](https://forums.suse.com/t/ros-startup-script/829/5 "2015-11-18T05:47:03Z")

</div>

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

```auto
#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):

```auto
#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

```
