diff --git a/debian/vitastor-mon.install b/debian/vitastor-mon.install index d344f91f..b5f61f6d 100644 --- a/debian/vitastor-mon.install +++ b/debian/vitastor-mon.install @@ -1 +1,2 @@ mon usr/lib/vitastor +mon/vitastor-mon.service /lib/systemd/system diff --git a/debian/vitastor-mon.postinst b/debian/vitastor-mon.postinst new file mode 100644 index 00000000..b627d9bb --- /dev/null +++ b/debian/vitastor-mon.postinst @@ -0,0 +1,8 @@ +#!/bin/sh + +set -e + +if [ "$1" = "configure" ]; then + addgroup --system --quiet vitastor + adduser --system --quiet --ingroup vitastor --no-create-home --home /nonexistent vitastor +fi diff --git a/debian/vitastor-osd.install b/debian/vitastor-osd.install index bce2fb9c..07e37a51 100644 --- a/debian/vitastor-osd.install +++ b/debian/vitastor-osd.install @@ -2,4 +2,5 @@ usr/bin/vitastor-osd usr/bin/vitastor-disk usr/bin/vitastor-dump-journal mon/vitastor-osd@.service /lib/systemd/system +mon/vitastor.target /lib/systemd/system mon/90-vitastor.rules /lib/udev/rules.d diff --git a/debian/vitastor-osd.postinst b/debian/vitastor-osd.postinst new file mode 100644 index 00000000..3b05abfb --- /dev/null +++ b/debian/vitastor-osd.postinst @@ -0,0 +1,9 @@ +#!/bin/sh + +set -e + +if [ "$1" = "configure" ]; then + addgroup --system --quiet vitastor + adduser --system --quiet --ingroup vitastor --no-create-home --home /nonexistent vitastor + install -o vitastor -g vitastor -d /var/log/vitastor +fi diff --git a/mon/make-units.sh b/mon/make-etcd.sh similarity index 57% rename from mon/make-units.sh rename to mon/make-etcd.sh index ab74faff..4650e58e 100755 --- a/mon/make-units.sh +++ b/mon/make-etcd.sh @@ -1,13 +1,12 @@ #!/bin/bash -# Very simple systemd unit generator for etcd & vitastor-mon services -# Not the final solution yet, mostly for tests +# Simple systemd unit generator for etcd # Copyright (c) Vitaliy Filippov, 2019+ # License: MIT -# USAGE: ./make-units.sh +# USAGE: [IP_SUBSTR=10.200.1.] [ETCD_HOSTS=etcd0=http://10.200.1.10:2380,...] ./make-etcd.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" +IP_SUBSTR=${IP_SUBSTR:-10.200.1.} +ETCD_HOSTS=${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'` @@ -16,7 +15,6 @@ 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 @@ -50,37 +48,3 @@ EOF systemctl daemon-reload systemctl enable etcd systemctl start etcd - -useradd vitastor -chmod 755 /root - -# Vitastor target -cat >/etc/systemd/system/vitastor.target </etc/systemd/system/vitastor-mon.service </dev/null ||: +useradd -r -g vitastor -s /sbin/nologin -c "Vitastor daemons" -M -d /nonexistent vitastor 2>/dev/null ||: +install -o vitastor -g vitastor -d /var/log/vitastor + + %files -n vitastor-mon /usr/lib/vitastor/mon +/lib/systemd/system/vitastor-mon.service + + +%pre -n vitastor-mon +groupadd -r -f vitastor 2>/dev/null ||: +useradd -r -g vitastor -s /sbin/nologin -c "Vitastor daemons" -M -d /nonexistent vitastor 2>/dev/null ||: %files -n vitastor-client diff --git a/rpm/vitastor-el8.spec b/rpm/vitastor-el8.spec index 6cec9eaa..3a6c850c 100644 --- a/rpm/vitastor-el8.spec +++ b/rpm/vitastor-el8.spec @@ -103,7 +103,7 @@ cd .. mkdir -p %buildroot/usr/lib/vitastor cp -r mon %buildroot/usr/lib/vitastor mkdir -p %buildroot/lib/systemd/system -cp mon/vitastor-osd@.service %buildroot/lib/systemd/system +cp mon/vitastor.target mon/vitastor-mon.service mon/vitastor-osd@.service %buildroot/lib/systemd/system mkdir -p %buildroot/lib/udev/rules.d cp mon/90-vitastor.rules %buildroot/lib/udev/rules.d @@ -117,11 +117,24 @@ cp mon/90-vitastor.rules %buildroot/lib/udev/rules.d %_bindir/vitastor-disk %_bindir/vitastor-dump-journal /lib/systemd/system/vitastor-osd@.service +/lib/systemd/system/vitastor.target /lib/udev/rules.d/90-vitastor.rules +%pre -n vitastor-osd +groupadd -r -f vitastor 2>/dev/null ||: +useradd -r -g vitastor -s /sbin/nologin -c "Vitastor daemons" -M -d /nonexistent vitastor 2>/dev/null ||: +install -o vitastor -g vitastor -d /var/log/vitastor + + %files -n vitastor-mon /usr/lib/vitastor/mon +/lib/systemd/system/vitastor-mon.service + + +%pre -n vitastor-mon +groupadd -r -f vitastor 2>/dev/null ||: +useradd -r -g vitastor -s /sbin/nologin -c "Vitastor daemons" -M -d /nonexistent vitastor 2>/dev/null ||: %files -n vitastor-client