diff --git a/installer/sashimono-install.sh b/installer/sashimono-install.sh index 759e64a..3e85280 100755 --- a/installer/sashimono-install.sh +++ b/installer/sashimono-install.sh @@ -5,6 +5,7 @@ sashimono_bin=/usr/bin/sashimono-agent docker_bin=/usr/bin/sashimono-agent/dockerbin sashimono_data=/etc/sashimono +sashimono_service="sashimono-agent" group="sashimonousers" cgroupsuffix="-cg" @@ -57,7 +58,30 @@ rm -r $tmp # Setting up cgroup rules. ! groupadd $group && echo "Group creation failed." && rollback -! echo "@$group cpu,memory %u$cgroupsuffix" >> /etc/cgrules.conf && echo "Cgroup rule creation failed." && rollback +! echo "@$group cpu,memory %u$cgroupsuffix" >>/etc/cgrules.conf && echo "Cgroup rule creation failed." && rollback + +# StartLimitIntervalSec=0 to make unlimited retries. RestartSec=1 is to keep 1 second gap between restarts. +if [ -f $sashimono_bin/sagent ]; then + echo "[Unit] + Description=Running and monitoring sashimono agent. + After=network.target + StartLimitIntervalSec=0 + [Service] + User=root + Group=root + Type=simple + ExecStart=$sashimono_bin/sagent run $sashimono_data + Restart=on-failure + RestartSec=1 + [Install] + WantedBy=multi-user.target" >/etc/systemd/system/$sashimono_service.service + + systemctl daemon-reload + systemctl enable $sashimono_service + systemctl start $sashimono_service +else + echo "Sashimono binary not found in ${sashimono_bin}. Skipped adding Sashimono service." +fi echo "Sashimono installed successfully." echo "Please restart your cgroup rule generator service or reboot your server for changes to apply." diff --git a/installer/sashimono-uninstall.sh b/installer/sashimono-uninstall.sh index de238fd..edd68f7 100755 --- a/installer/sashimono-uninstall.sh +++ b/installer/sashimono-uninstall.sh @@ -3,6 +3,7 @@ sashimono_bin=/usr/bin/sashimono-agent sashimono_data=/etc/sashimono +sashimono_service="sashimono-agent" group="sashimonousers" cgroupsuffix="-cg" @@ -18,17 +19,15 @@ prefix="sashi" users=$(cut -d: -f1 /etc/passwd | grep "^$prefix" | sort) readarray -t userarr <<<"$users" validusers=() -for user in "${userarr[@]}" -do - [ ${#user} -lt 24 ] || [ ${#user} -gt 32 ] || [[ ! "$user" =~ ^$prefix[0-9]+$ ]] && continue +for user in "${userarr[@]}"; do + [ ${#user} -lt 24 ] || [ ${#user} -gt 32 ] || [[ ! "$user" =~ ^$prefix[0-9]+$ ]] && continue validusers+=("$user") done ucount=${#validusers[@]} if [ $ucount -gt 0 ]; then echo "Are you sure you want to delete all $ucount Sashimono contract instances?" - for user in "${validusers[@]}" - do + for user in "${validusers[@]}"; do echo "$user" done echo "Type $ucount to confirm deletion:" @@ -36,10 +35,9 @@ if [ $ucount -gt 0 ]; then if [ "$confirmation" == "$ucount" ]; then echo "Deleting $ucount contract instances..." - for user in "${validusers[@]}" - do - output=$($(pwd)/user-uninstall.sh $user | tee /dev/stderr) - [ "${output: -10}" != "UNINST_SUC" ] && echo "Uninstall user '$user' failed. Aborting." && exit 1 + for user in "${validusers[@]}"; do + output=$($(pwd)/user-uninstall.sh $user | tee /dev/stderr) + [ "${output: -10}" != "UNINST_SUC" ] && echo "Uninstall user '$user' failed. Aborting." && exit 1 done else echo "Uninstall cancelled." @@ -47,6 +45,11 @@ if [ $ucount -gt 0 ]; then fi fi +echo "Removing Sashimono service..." +systemctl stop $sashimono_service +systemctl disable $sashimono_service +rm /etc/systemd/system/$sashimono_service.service + echo "Deleting binaries..." rm -r $sashimono_bin @@ -59,4 +62,4 @@ sed -i -r "/^@$group\s+cpu,memory\s+%u$cgroupsuffix/d" /etc/cgrules.conf echo "Sashimono uninstalled successfully." echo "Please restart your cgroup rule generator service or reboot your server for changes to apply." -exit 0 \ No newline at end of file +exit 0