diff --git a/dependencies/user-cgcreate.sh b/dependencies/user-cgcreate.sh index c460443..b214759 100755 --- a/dependencies/user-cgcreate.sh +++ b/dependencies/user-cgcreate.sh @@ -35,9 +35,12 @@ if [ "$max_swap_kbytes" != "" ] && [ ! ${#max_swap_kbytes} -eq 0 ] && [ "$max_sw ! instance_swap_kbytes=$(expr $instance_mem_kbytes + $max_swap_kbytes / $max_instance_count) && echo "Max swap memory limit calculation error." && exit 1 fi -instance_cpu_us=0 +instance_cpu_quota=0 +# In the Sashimono configuration, CPU time is 1000000us Sashimono is given max_cpu_us out of it. +# Instance allocation is multiplied by number of cores to determined the number of cores per instance and devided by 10 since cfs_period_us is set to 100000us if [ "$max_cpu_us" != "" ] && [ ! ${#max_cpu_us} -eq 0 ] && [ "$max_cpu_us" -gt 0 ]; then - ! instance_cpu_us=$(expr $max_cpu_us / $max_instance_count) && echo "Max cpu limit calculation error." && exit 1 + cores=$(grep -c ^processor /proc/cpuinfo) + ! instance_cpu_quota=$(expr $(expr $cores \* $max_cpu_us) / $(expr $max_instance_count \* 10)) && echo "Max cpu limit calculation error." && exit 1 fi prefix="sashi" @@ -53,18 +56,18 @@ done has_err=0 for user in "${validusers[@]}"; do # Setup user cgroup. - if [ $instance_cpu_us -gt 0 ] && + if [ $instance_cpu_quota -gt 0 ] && ! (cgcreate -g cpu:$user$cgroupsuffix && - echo "1000000" > /sys/fs/cgroup/cpu/$user$cgroupsuffix/cpu.cfs_period_us && - echo "$instance_cpu_us" > /sys/fs/cgroup/cpu/$user$cgroupsuffix/cpu.cfs_quota_us); then + echo "100000" >/sys/fs/cgroup/cpu/$user$cgroupsuffix/cpu.cfs_period_us && + echo "$instance_cpu_quota" >/sys/fs/cgroup/cpu/$user$cgroupsuffix/cpu.cfs_quota_us); then echo "CPU cgroup creation for $user failed." has_err=1 fi if [ $instance_mem_kbytes -gt 0 ] && ! (cgcreate -g memory:$user$cgroupsuffix && - echo "${instance_mem_kbytes}K" > /sys/fs/cgroup/memory/$user$cgroupsuffix/memory.limit_in_bytes && - echo "${instance_swap_kbytes}K" > /sys/fs/cgroup/memory/$user$cgroupsuffix/memory.memsw.limit_in_bytes); then + echo "${instance_mem_kbytes}K" >/sys/fs/cgroup/memory/$user$cgroupsuffix/memory.limit_in_bytes && + echo "${instance_swap_kbytes}K" >/sys/fs/cgroup/memory/$user$cgroupsuffix/memory.memsw.limit_in_bytes); then echo "Memory cgroup creation for $user failed." has_err=1 fi diff --git a/dependencies/user-install.sh b/dependencies/user-install.sh index 13661bc..8073b20 100755 --- a/dependencies/user-install.sh +++ b/dependencies/user-install.sh @@ -209,10 +209,14 @@ WantedBy=default.target" >"$user_dir"/.config/systemd/user/ledger_fs.service sudo -u "$user" XDG_RUNTIME_DIR="$user_runtime_dir" systemctl --user daemon-reload +# In the Sashimono configuration, CPU time is 1000000us Sashimono is given max_cpu_us out of it. +# Instance allocation is multiplied by number of cores to determined the number of cores per instance and devided by 10 since cfs_period_us is set to 100000us +cores=$(grep -c ^processor /proc/cpuinfo) +cpu_quota=$(expr $(expr $cores \* $cpu) / 10) echo "Setting up user cgroup resources." ! (cgcreate -g cpu:$user$cgroupsuffix && - echo "1000000" >/sys/fs/cgroup/cpu/$user$cgroupsuffix/cpu.cfs_period_us && - echo "$cpu" >/sys/fs/cgroup/cpu/$user$cgroupsuffix/cpu.cfs_quota_us) && rollback "CGROUP_CPU_CREAT" + echo "100000" >/sys/fs/cgroup/cpu/$user$cgroupsuffix/cpu.cfs_period_us && + echo "$cpu_quota" >/sys/fs/cgroup/cpu/$user$cgroupsuffix/cpu.cfs_quota_us) && rollback "CGROUP_CPU_CREAT" ! (cgcreate -g memory:$user$cgroupsuffix && echo "${memory}K" >/sys/fs/cgroup/memory/$user$cgroupsuffix/memory.limit_in_bytes && echo "${swapmem}K" >/sys/fs/cgroup/memory/$user$cgroupsuffix/memory.memsw.limit_in_bytes) && rollback "CGROUP_MEM_CREAT" diff --git a/installer/prereq.sh b/installer/prereq.sh index 36f7ec9..23c8980 100755 --- a/installer/prereq.sh +++ b/installer/prereq.sh @@ -48,11 +48,17 @@ else fi fi +# Install iptables +if ! command -v iptables &>/dev/null; then + stage "Installing iptables" + apt-get install -y iptables +fi + # Load br_netfilter kernel module on startup (if not loaded already). if [[ -z "$(lsmod | grep br_netfilter)" ]]; then echo "Adding br_netfilter" modprobe br_netfilter - echo "br_netfilter" > /etc/modules-load.d/br_netfilter.conf + echo "br_netfilter" >/etc/modules-load.d/br_netfilter.conf fi # ------------------------------- @@ -92,10 +98,10 @@ if [ $updated -eq 1 ]; then # Create a backup of original, if remount failed replace updated with backup. cp $originalfstab $backup mv "$tmpfstab" $originalfstab - if ! mount -o remount / 2>&1 ; then + if ! mount -o remount / 2>&1; then mv $backup $originalfstab echo "Re mounting error." && exit 1 - fi + fi echo "Updated fstab." else echo "fstab already configured." @@ -134,7 +140,7 @@ if [ $res -eq 0 ]; then res=$? updated=1 elif [ $res -eq 0 ]; then - echo "user_allow_other" >> "$tmpconf" + echo "user_allow_other" >>"$tmpconf" res=$? updated=1 fi @@ -236,7 +242,7 @@ if [ $res -eq 100 ]; then fi fi elif [ $res -eq 0 ]; then - echo "GRUB_CMDLINE_LINUX=\"cgroup_enable=memory swapaccount=1\"" >> "$tmpgrub" + echo "GRUB_CMDLINE_LINUX=\"cgroup_enable=memory swapaccount=1\"" >>"$tmpgrub" res=$? updated=1 fi @@ -251,7 +257,7 @@ if [ $updated -eq 1 ]; then cp /etc/default/grub $grub_backup mv "$tmpgrub" /etc/default/grub rm -r "$tmp" - if ! update-grub >/dev/null 2>&1 ; then + if ! update-grub >/dev/null 2>&1; then mv $grub_backup /etc/default/grub echo "Grub update failed." exit 1 @@ -268,4 +274,4 @@ else echo "Grub already configured." fi -exit 0 \ No newline at end of file +exit 0 diff --git a/mb-xrpl/lib/appenv.js b/mb-xrpl/lib/appenv.js index 05e9fef..892c212 100644 --- a/mb-xrpl/lib/appenv.js +++ b/mb-xrpl/lib/appenv.js @@ -20,7 +20,7 @@ appenv = { ACQUIRE_LEASE_TIMEOUT_THRESHOLD: 0.8, ACQUIRE_LEASE_WAIT_TIMEOUT_THRESHOLD: 0.4, SASHI_CLI_PATH: appenv.IS_DEV_MODE ? "../build/sashi" : "/usr/bin/sashi", - MB_VERSION: '0.5.2', + MB_VERSION: '0.5.3', TOS_HASH: '757A0237B44D8B2BBB04AE2BAD5813858E0AECD2F0B217075E27E0630BA74314' // This is the sha256 hash of TOS text. } Object.freeze(appenv); diff --git a/mb-xrpl/lib/message-board.js b/mb-xrpl/lib/message-board.js index 3e7374f..13e11a5 100644 --- a/mb-xrpl/lib/message-board.js +++ b/mb-xrpl/lib/message-board.js @@ -107,14 +107,15 @@ class MessageBoard { console.log(`Moments exceeded (current ledger:${e.ledger_index}, expiry ledger:${x.expiryLedger}). Destroying ${x.containerName}`); // Expire the current lease agreement (Burn the instance NFT) and re-minting and creating sell offer for the same lease index. const nft = (await (new evernode.XrplAccount(x.tenant)).getNfts())?.find(n => n.NFTokenID == x.containerName); + // If there's no nft for this record it should be already burned and instance is destroyed, So we only delete the record. if (!nft) - throw `Cannot find a NFT for ${x.containerName}`; + console.log(`Cannot find a NFT for ${x.containerName}`); + else { + const uriInfo = evernode.UtilHelpers.decodeLeaseNftUri(nft.URI); + await this.destroyInstance(x.containerName, x.tenant, uriInfo.leaseIndex, true); + } - const uriInfo = evernode.UtilHelpers.decodeLeaseNftUri(nft.URI); - await this.destroyInstance(x.containerName, x.tenant, uriInfo.leaseIndex, true); this.activeInstanceCount--; - await this.hostClient.updateRegInfo(this.activeInstanceCount); - /** * Soft deletion for debugging purpose. */ @@ -122,6 +123,8 @@ class MessageBoard { // Delete the lease record related to this instance (Permanent Delete). await this.deleteLeaseRecord(x.txHash); + + await this.hostClient.updateRegInfo(this.activeInstanceCount); console.log(`Destroyed ${x.containerName}`); } catch (e) { diff --git a/src/version.hpp b/src/version.hpp index b20e904..3bbe61a 100644 --- a/src/version.hpp +++ b/src/version.hpp @@ -6,7 +6,7 @@ namespace version { // Sashimono agent version. Written to new configs. - constexpr const char *AGENT_VERSION = "0.5.2"; + constexpr const char *AGENT_VERSION = "0.5.3"; // Minimum compatible config version (this will be used to validate configs). constexpr const char *MIN_CONFIG_VERSION = "0.5.0";