From d53e4efc4a41760f5156fe00da341a0c5ca33674 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=EC=9D=B4=EC=88=98=EC=A4=80?= <june@june-2.local>
Date: Mon, 23 Oct 2023 10:51:21 +0900
Subject: [PATCH] Frist: init code.

---
 app-setting.sh        | 10 ++++++++++
 config1.json          |  9 +++++++++
 config2.json          |  6 ++++++
 install.sh            |  9 +++++++++
 main.py               | 24 ++++++++++++++++++++++++
 sdt-cloud-app.service | 10 ++++++++++
 6 files changed, 68 insertions(+)
 create mode 100755 app-setting.sh
 create mode 100644 config1.json
 create mode 100644 config2.json
 create mode 100755 install.sh
 create mode 100644 main.py
 create mode 100644 sdt-cloud-app.service

diff --git a/app-setting.sh b/app-setting.sh
new file mode 100755
index 0000000..6fc79ad
--- /dev/null
+++ b/app-setting.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+if [ -z $1 ]; then
+	echo "Please fill in app's name."
+	exit
+fi
+
+mv sdt-cloud-app.service $1.service
+sudo sed -i "s/sdt-cloud-app/$1/g" ./install.sh
+
diff --git a/config1.json b/config1.json
new file mode 100644
index 0000000..f77c7a2
--- /dev/null
+++ b/config1.json
@@ -0,0 +1,9 @@
+{
+    "topic": "performance",
+    "id": "sdt",
+    "password": "11223344",
+    "host": {
+        "address": "192.168.100.200",
+        "hostname": "sdt"
+    }
+}
\ No newline at end of file
diff --git a/config2.json b/config2.json
new file mode 100644
index 0000000..4a478a0
--- /dev/null
+++ b/config2.json
@@ -0,0 +1,6 @@
+{
+	"hw": "intel",
+	"cpu": 12,
+	"memory": 32,
+	"gpu": "2080TI"	
+}
diff --git a/install.sh b/install.sh
new file mode 100755
index 0000000..22f2e0e
--- /dev/null
+++ b/install.sh
@@ -0,0 +1,9 @@
+#!/bin/bash
+
+set -e
+
+sudo sed -i "s/appName/$1/g" /usr/local/sdt/app/$1/sdt-cloud-app.service
+sudo cp /usr/local/sdt/app/$1/sdt-cloud-app.service /etc/systemd/system/$1.service
+sudo systemctl start $1
+sudo systemctl enable $1
+
diff --git a/main.py b/main.py
new file mode 100644
index 0000000..9097393
--- /dev/null
+++ b/main.py
@@ -0,0 +1,24 @@
+import paho.mqtt.client as mqtt
+import json
+import argparse
+
+from datetime import datetime
+import time
+import yaml
+
+parser = argparse.ArgumentParser()
+parser.add_argument('-config',help='')
+args = parser.parse_args()
+
+with open(f'/usr/local/sdt/app/{args.config}/config.json', encoding='UTF-8') as f:
+    jsonData = json.load(f)
+
+
+# mqttc = mqtt.Client() # puclisher 이름
+# mqttc.username_pw_set("sdt", "251327")
+# mqttc.connect("13.209.39.139", 32259)
+while True:
+    print(f"Config value: {jsonData['topic']}", flush=True)
+    time.sleep(2)
+
+
diff --git a/sdt-cloud-app.service b/sdt-cloud-app.service
new file mode 100644
index 0000000..09e2c10
--- /dev/null
+++ b/sdt-cloud-app.service
@@ -0,0 +1,10 @@
+[Unit]
+Description=sdt-cloud-app
+
+[Service]
+ExecStart=/usr/bin/python3 /usr/local/sdt/app/appName/main.py -config appName
+Restart=always
+RestartSec=10
+
+[Install]
+WantedBy=multi-user.target