Run level scripts on rancherOS

Hi Ranchers,

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

/opt/rancher/bin/ <- 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?


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

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

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?

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.

@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


    echo "I'm melting"
    exit 0

trap die TERM


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

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

  - path: /etc/profile.d/
    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"