#!/bin/sh if [ "$(id -u)" != "0" ]; then echo "Please run this script as root" exit 1 fi USER=$1 SYSTEMD_FILE=/etc/systemd/system/eva-ics.service SYSTEMD_REGISTRY_FILE=/etc/systemd/system/eva-ics-registry.service if [ -z "$USER" ]; then echo "Usage: $0 " exit 1 fi if ! id "$USER" > /dev/null 2>&1 ; then echo "User $USER does not exist" exit 2 fi [ -z "$EVA_DIR" ] && EVA_DIR=/opt/eva if [ ! -d $EVA_DIR ] ; then echo "Directory $EVA_DIR does not exist" echo "To specify custom directory, run the script as EVA_DIR=/path/to/eva/dir $0" exit 2 fi echo "Stopping EVA ICS..." if [ -f "$SYSTEMD_FILE" ]; then if ! systemctl stop eva-ics; then echo "Unable to stop EVA ICS" exit 3 fi if ! systemctl stop eva-ics-registry; then echo "Unable to stop EVA ICS registry" exit 3 fi fi if ! "$EVA_DIR/sbin/registry-control" stop; then echo "Unable to stop EVA ICS registry" exit 3 fi if ! FORCE_ALL=1 "$EVA_DIR/sbin/eva-control" stop; then echo "Unable to stop EVA ICS" exit 3 fi echo "Changing ownership of $EVA_DIR to $USER..." if ! chown -R "$USER" "$EVA_DIR"; then echo "Unable to chown" exit 4 fi if [ -f "$SYSTEMD_FILE" ]; then echo "Changing systemd user for EVA ICS..." if ! sed -i "s/^User=.*/User=$USER/g" "$SYSTEMD_FILE"; then echo "Unable to change systemd user for eva-ics.service" exit 5 fi if ! sed -i "s/^User=.*/User=$USER/g" "$SYSTEMD_REGISTRY_FILE"; then echo "Unable to change systemd user for eva-ics-registry" exit 5 fi echo "Reloading systemd..." if ! systemctl daemon-reload; then echo "Unable to reload systemd" exit 6 fi fi for c in uc lm sfa; do FNAME="/etc/logrotate.d/eva-$c" if [ -f "${FNAME}" ]; then echo "Changing user in ${FNAME}" sed -i "s/create 640 .*/create 640 ${USER} adm/g" "${FNAME}" fi done if [ -f "$SYSTEMD_FILE" ]; then echo "Starting EVA ICS via systemctl..." if ! systemctl restart eva-ics-registry; then echo "Unable to start EVA ICS registry" exit 3 fi if ! systemctl restart eva-ics; then echo "Unable to start EVA ICS" exit 3 fi else echo "Starting EVA ICS..." if ! "$EVA_DIR/sbin/registry-control" start; then echo "Unable to start EVA ICS registry" exit 3 fi if ! "$EVA_DIR/sbin/eva-control" start; then echo "Unable to start EVA ICS" exit 3 fi fi