toymaker.git

commit 13d4a2107bb7a5f28ef7ed567df3e82d97b6cff7

Author: Adam <git@apiote.xyz>

stop building toy item

 server2.sh | 16 ++++++++++++++++
 start.sh | 12 +++++++++++-


diff --git a/server2.sh b/server2.sh
index 1d64f38d22ecb3f09e152f4d45b3007a10cee45f..6d0868416b7f12078962db96570cafe13d4fb837 100755
--- a/server2.sh
+++ b/server2.sh
@@ -178,6 +178,22 @@ 			respond500 "error while creating $toy"
 		else
 			respond202 "$toy" "$item"
 		fi
+	DELETE)
+		check_auth "$authorization" || return
+
+		if [ "$(slashes "$path")" -eq 3 ]
+		then
+			toy=$(field "$path" 3)
+			item=$(field "$path" 4)
+			if stop_item "$toy" "$item"
+			then
+				respond200 ""
+			else
+				respond500 "error while stopping $toy/$item"
+			fi
+		else
+			respond404 "$path"
+		fi
 		;;
 	*)
 		respond405 "$method"




diff --git a/start.sh b/start.sh
index fc7a7e6127d8d52456900f760857db43214fcf59..a99689ee2000b1ed48eff6a9935bc2b545ac819b 100644
--- a/start.sh
+++ b/start.sh
@@ -23,9 +23,19 @@ 	mkdir "toys/$toy/$currentItem"
 	rm -r "toys/$toy/.lock"
 
 	(
-	podman run --rm "toy_$toy" >"/toys/$toy/$currentItem.log" 2>&1
+	podman run --name "item_${toy}_$item" --rm "toy_$toy" >"/toys/$toy/$currentItem.log" 2>&1
 	echo $? >"toys/$toy/$currentItem.exit"
 	) &
 
 	printf "%s" "$currentItem"
 }
+
+stop_item() {
+	toy=$1
+	item=$2
+	if ! podman ps | grep -q "item_${toy}_$item"
+	then
+		return
+	fi
+	podman stop "item_${toy}_$item"
+}