# Run level scripts on rancherOS

**URL:** <https://forums.suse.com/t/run-level-scripts-on-rancheros/1525>\
**Category:** RancherOS\
**Created:** [January 25, 2016, 10:07am UTC](https://forums.suse.com/t/run-level-scripts-on-rancheros/1525 "2016-01-25T10:07:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![richardoflynn](https://avatars.discourse-cdn.com/v4/letter/r/ee7513/32.png) [@richardoflynn](https://forums.suse.com/u/richardoflynn)\
**Post date:** [January 25, 2016, 10:07am UTC](https://forums.suse.com/t/run-level-scripts-on-rancheros/1525/1 "2016-01-25T10:07:50Z")

</div>

Hi Ranchers,

Not sure if this is in the documentation, but for others…

/opt/rancher/bin/start.sh \<- runs before docker has started  
/etc/rc.local \<- runs after docker has started - although scripts needs to check docker has finished loading (e.g. check for docker info) if you are requiring use of docker.

My question to the Rancher team is:

Is it possible to set up scripts that can run on termination or reboot of rancherOS?

Thanks.

---

<div class="post-metadata">

**Author:** ![ibuildthecloud](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/ibuildthecloud/32/8_2.png) [@ibuildthecloud](https://forums.suse.com/u/ibuildthecloud)\
**Post date:** [January 26, 2016, 10:05pm UTC](https://forums.suse.com/t/run-level-scripts-on-rancheros/1525/2 "2016-01-26T22:05:45Z")

</div>

If we were to do that it would be with the following caveats.

1. It would be unreliable, because things crash 🙂
2. It would have to complete in less than 10 seconds.

---

<div class="post-metadata">

**Author:** ![richardoflynn](https://avatars.discourse-cdn.com/v4/letter/r/ee7513/32.png) [@richardoflynn](https://forums.suse.com/u/richardoflynn)\
**Post date:** [January 26, 2016, 10:17pm UTC](https://forums.suse.com/t/run-level-scripts-on-rancheros/1525/3 "2016-01-26T22:17:20Z")

</div>

Ok so currently no. My use case is running rancher with spotinst. When the host gets a shutdown signal, any other os I could put a script in to ping my hip chat. I know rancheros is minimal but might be nice to support some shutdown hook?

---

<div class="post-metadata">

**Author:** ![ibuildthecloud](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/ibuildthecloud/32/8_2.png) [@ibuildthecloud](https://forums.suse.com/u/ibuildthecloud)\
**Post date:** [January 26, 2016, 10:19pm UTC](https://forums.suse.com/t/run-level-scripts-on-rancheros/1525/4 "2016-01-26T22:19:53Z")

</div>

You can actually do this today in a way. Create a container that does nothing but wait for SIGTERM. After SIGTERM ping hip chat. On shutdown of rancher os we do stop all system services (must be in system-docker, not user-docker). So your container would shutdown.

---

<div class="post-metadata">

**Author:** ![ibuildthecloud](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/ibuildthecloud/32/8_2.png) [@ibuildthecloud](https://forums.suse.com/u/ibuildthecloud)\
**Post date:** [January 26, 2016, 10:33pm UTC](https://forums.suse.com/t/run-level-scripts-on-rancheros/1525/5 "2016-01-26T22:33:10Z")

</div>

@richardoflynn For example the following script will print “I’m melting” on shutdown. You just have to launch it with `-i` or `stdin_open: true`

```
#!/bin/bash

die()
{
    echo "I'm melting"
    exit 0
}

trap die TERM

read I_FEEL_LIKE_I_SERVE_NO_PURPOSE
```

---

<div class="post-metadata">

**Author:** ![pwFoo](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/pwfoo/32/2884_2.png) [@pwFoo](https://forums.suse.com/u/pwFoo)\
**Post date:** [January 29, 2016, 11:36am UTC](https://forums.suse.com/t/run-level-scripts-on-rancheros/1525/6 "2016-01-29T11:36:59Z")

</div>

Hi @ibuildthecloud,

I need a way to set some aliases and custom configuration to RancherOS / console. Could you provide such a example executed during boot?

I created a system-docker convoy os-service for example, but need an alias for console usage (convoy binary can’t be bind to the console, so I have to use docker exec …).  
`91dbadb6ddd4 pwfoo/private:os-convoy-vfs "/convoy-start.sh" 3 days ago Up 9 minutes os_convoy-vfs_1`

So something like a config container ( need to know how the convoy container is named) or a /etc/rc.local is needed.  
`alias sysdocker="sudo system-docker"`  
`alias convoy="sudo system-docker exec -ti os_convoy-vfs_1 convoy"`

---

<div class="post-metadata">

**Author:** ![bdentino](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/bdentino/32/1489_2.png) [@bdentino](https://forums.suse.com/u/bdentino)\
**Post date:** [August 4, 2016, 7:21pm UTC](https://forums.suse.com/t/run-level-scripts-on-rancheros/1525/7 "2016-08-04T19:21:13Z")

</div>

@pwFoo Adding the aliases to a script in /etc/profile.d should do the trick

```auto
#cloud-config
write_files:
  - path: /etc/profile.d/alias.sh
    permissions: "0755"
    owner: root
    content: |
      alias convoy="sudo system-docker exec -it convoy convoy"
      alias serf="sudo system-docker exec -it serf serf"
      alias sd="sudo system-docker"

```
