#!/bin/bash # Very simple systemd unit generator for vitastor-osd services # Not the final solution yet, mostly for tests # Copyright (c) Vitaliy Filippov, 2019+ # License: MIT # USAGE: ./make-osd.sh /dev/disk/by-partuuid/xxx [ /dev/disk/by-partuuid/yyy]... IP_SUBSTR="10.200.1." ETCD_HOSTS="etcd0=http://10.200.1.10:2380,etcd1=http://10.200.1.11:2380,etcd2=http://10.200.1.12:2380" set -e -x IP=`ip -json a s | jq -r '.[].addr_info[] | select(.local | startswith("'$IP_SUBSTR'")) | .local'` [ "$IP" != "" ] || exit 1 ETCD_MON=$(echo $ETCD_HOSTS | perl -pe 's/:2380/:2379/g; s/etcd\d*=//g;') D=`dirname $0` # Create OSDs on all passed devices for DEV in $*; do OSD_NUM=$(vitastor-cli alloc-osd) echo Creating OSD $OSD_NUM on $DEV OPT=$(vitastor-cli simple-offsets --format options $DEV | tr '\n' ' ') META=$(vitastor-cli simple-offsets --format json $DEV | jq .data_offset) dd if=/dev/zero of=$DEV bs=1048576 count=$(((META+1048575)/1048576)) oflag=direct cat >/etc/systemd/system/vitastor-osd$OSD_NUM.service <