#!/bin/bash # Very simple systemd unit generator for etcd & vitastor-mon services # Not the final solution yet, mostly for tests # Copyright (c) Vitaliy Filippov, 2019+ # License: MIT # USAGE: ./make-units.sh 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" # determine IP IP=`ip -json a s | jq -r '.[].addr_info[] | select(.local | startswith("'$IP_SUBSTR'")) | .local'` [ "$IP" != "" ] || exit 1 ETCD_NUM=${ETCD_HOSTS/$IP*/} [ "$ETCD_NUM" != "$ETCD_HOSTS" ] || exit 1 ETCD_NUM=$(echo $ETCD_NUM | tr -d -c , | wc -c) # etcd useradd etcd mkdir -p /var/lib/etcd$ETCD_NUM.etcd cat >/etc/systemd/system/etcd.service </etc/systemd/system/vitastor.target </etc/systemd/system/vitastor-mon.service <