Skip to content

Instantly share code, notes, and snippets.

@kayrus
Last active March 2, 2016 14:28
Show Gist options
  • Save kayrus/a7cceefef4cd973dd1ff to your computer and use it in GitHub Desktop.
Save kayrus/a7cceefef4cd973dd1ff to your computer and use it in GitHub Desktop.
#!/bin/bash
DESIRED_STATE="launched"
ETCD_TIMEOUT=2s
for i in {1..1000}; do
LOCALFILENAME="app$i.service"
echo "Submiting $LOCALFILENAME"
LOCALFILE="[Unit]
Description=hole
[Service]
ExecStart=/usr/bin/bash -c 'while true; do echo \"Hello, world $i\"; sleep 1; done'"
echo "Attempting to update unit file in etcd"
LOCALHASH=$(echo "$LOCALFILE" | sha1sum | awk '{print $1}')
ESCAPED_STRING=$(echo "$LOCALFILE" | sed ":a;N;\$!ba;s#\\\#\\\\\\\#g;s#\n#\\\n#g;s#\\\"#\\\\\"#g;s#\r#\\\r#g;s#\t#\\\t#g")
LOCALHASH_DEC=$(echo "$LOCALHASH" | sed -r 's#(.{2})#0x\1,#g' | tr -d '\n' | xargs -d ',' printf "%d," | sed 's#,$##')
NEW_JSON="{\"Raw\":\"$ESCAPED_STRING\\n\"}"
etcdctl --timeout $ETCD_TIMEOUT set /_coreos.com/fleet/unit/$LOCALHASH "$NEW_JSON"
NEW_OBJECT="{\"Name\":\"$LOCALFILENAME\",\"UnitHash\":[$LOCALHASH_DEC]}"
etcdctl --timeout $ETCD_TIMEOUT set /_coreos.com/fleet/job/$LOCALFILENAME/object "$NEW_OBJECT" &
etcdctl --timeout $ETCD_TIMEOUT set /_coreos.com/fleet/job/$LOCALFILENAME/target-state "$DESIRED_STATE" &
done
wait
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment