Scheduling updates with

Last week we open-sourced our supervisor and released it's own API, which is a massive step in enhancing control of your devices running in the wild. The supervisor is a device-side agent that, for lack of a better word, supervises your application. It runs all resin related tasks. One task in particular which is both important for the purpose of this post and in general, is updating the application's running container.

Ordinarily, when you push a new update to a application, it automatically notifies the supervisor running on all available devices to download the new code and restart the application. This is great, but what if your application is running a crucial process or is interacting with a user. Good news! The supervisor now has the functionality to prevent the restarting of the application during these inappropriate times. In order to do this, you simply create a lockfile at this path /data/resin-updates.lock.

NOTE: Your device will still download the new code however it will not kill the currently running application and switch to the new code until the lock in /data/resin-updates.lock is released.

I've prepared a simple example to illustrate how useful this feature can be. It uses cron to lock and unlock updates at certain times of the day.

In 'jobs.txt', two cron jobs are scheduled: one for unlocking and another for locking again.

# /proc/1/fd/1 is systemd's stdout, and therefore appears in the resin logs.

# run unlock at 00:00 everyday 
0 0 * * * rm -f /data/resin-updates.lock > /proc/1/fd/1

# run lock at 00:10 everyday
10 0 * * * lockfile /data/resin-updates.lock > /proc/1/fd/1  

After pushing my example app, head to the devices web terminal and run:

$ crontab -l

You should see the two jobs from jobs.txt waiting to be executed at midnight and 10' past respectively.

We have also automatically acquired the lock on container start in This way the updates will lock when the container intially starts.

# Lock updates when container starts
lockfile /data/resin-updates.lock  
while sleep 10; do echo "My app is running without interruption"; done  

Great, now your devices will only update at midnight but what happens if there is an emergency and you really need to override the lock to provide an update? The supervisor API has you covered!

$ curl -X POST --header "Content-Type:application/json" \
    --header "Authorization: Bearer <auth token>" \
    --data '{"deviceId": <deviceId>, "appId": <appId>, "data": {"force": true}}"' \

Read our documentation for more info on interacting with the supervisor.

Now you'll have full control over your devices update schedule so your engineers won't have to deploy at midnight.

Sleep Tight!

Have questions, or just want to say hi? Find the team on our community chat.

comments powered by Disqus
Terms of Service | Privacy Statement | Master agreement | Copyright 2019 Balena | All Rights Reserved