Adding a systemd service for Sashimono in sashimono-install script. (#26)

This commit is contained in:
Savinda Senevirathne
2021-07-09 16:53:27 +05:30
committed by GitHub
parent 82ba515cbd
commit 41889b17c7
2 changed files with 38 additions and 11 deletions

View File

@@ -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."

View File

@@ -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
exit 0