Skip to content

Commit 8aafa73

Browse files
committed
updated readme; added rest_api_server start automation; fixed service name conflict
1 parent 41f3168 commit 8aafa73

File tree

10 files changed

+59
-7
lines changed

10 files changed

+59
-7
lines changed

README.md

+15-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,21 @@ To compile, use [compile.sh](socket_server/compile.sh). A named and detached scr
3333

3434
## Rest-API Server
3535

36-
To be described and implemented.
36+
Currently available endpoints:
37+
38+
```
39+
POST /sms
40+
{
41+
"recipient": string,
42+
"message": string
43+
}
44+
```
45+
46+
```
47+
GET /health
48+
```
49+
50+
To compile, use [compile.sh](rest_api_server/compile.sh). A named and detached screen that also logs to a uniquely named file can be created using [start.sh](rest_api_server/start.sh). The [ensure_running.sh](rest_api_server/ensure_running.sh) script checks periodically whether the named screen is up, and if it isn't, it calls said start script. The [ensure_running.service](rest_api_server/ensure_running.service) is a `systemd`-service, which makes sure that [ensure_running.sh](rest_api_server/ensure_running.sh) is up at all times. This service can be installed by making use of [install_service.sh](rest_api_server/install_service.sh).
3751

3852
## My Setup
3953

rest_api_server/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
server.jar

rest_api_server/compile.sh

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
cd sim-modem-api
3+
./gradlew bootJar
4+
cp build/libs/*.jar ../server.jar
5+
cd ..
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[Unit]
2+
Description=Infinite loop rest_api_server screen watcher
3+
4+
[Service]
5+
User=blvckbytes
6+
Type=simple
7+
ExecStart=/home/blvckbytes/sim-modem-api/rest_api_server/ensure_running.sh
8+
Restart=always
9+
10+
[Install]
11+
WantedBy=default.target

rest_api_server/ensure_running.sh

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
while true
3+
do
4+
/usr/bin/screen -S sim_modem_rest_api_server -Q select . 2>&1 > /dev/null
5+
6+
# Non-zero exit code means that there was no such screen
7+
if [[ "`echo $?`" != "0" ]]
8+
then
9+
/home/blvckbytes/sim-modem-api/rest_api_server/start.sh
10+
echo "Started rest api server"
11+
fi
12+
13+
echo sleeping
14+
sleep 5
15+
done

rest_api_server/install_service.sh

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
sudo cp ensure_running.service /etc/systemd/system/rest_api_server_ensure_running.service
3+
sudo systemctl enable rest_api_server_ensure_running.service
4+
sudo systemctl start rest_api_server_ensure_running.service

rest_api_server/sim-modem-api/src/main/kotlin/me/blvckbytes/simmodemapi/rest/SimModemCommandDto.kt

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
package me.blvckbytes.simmodemapi.rest
22

3-
import com.fasterxml.jackson.annotation.JsonFormat
43
import me.blvckbytes.simmodemapi.modem.SimModemResponse
54
import java.time.LocalDateTime
65

76
class SimModemCommandDto(
87
val command: String,
98
val response: String,
109
val timeoutMs: Int,
11-
// @field:JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
1210
val commandSentStamp: LocalDateTime,
13-
// @field:JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
1411
val responseReceivedStamp: LocalDateTime
1512
) {
1613
companion object {
1714
fun fromModel(model: SimModemResponse, commandGenerator: CommandGeneratorPort): SimModemCommandDto {
1815
return SimModemCommandDto(
16+
// TODO: Also substitute non printable characters
1917
commandGenerator.trimControlCharacters(model.command.command),
2018
commandGenerator.trimControlCharacters(model.content),
2119
model.command.timeoutMs,

rest_api_server/sim-modem-api/src/main/resources/application.properties

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ socket-server.host=192.168.1.49
22
socket-server.port=8080
33
socket-server.heartbeat-period-ms=2000
44
socket-server.heartbeat-sentinel=<heartbeat>
5+
server.port=8090

rest_api_server/start.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
basepath=/home/blvckbytes/sim-modem-api/rest_api_server
3+
/usr/bin/screen -m -d -S sim_modem_rest_api_server -L -Logfile $basepath/`date +"%Y-%m-%d-%H-%M-%S-%N"`.txt java -jar $basepath/server.jar

socket_server/install_service.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/bash
2-
sudo cp ensure_running.service /etc/systemd/system/
3-
sudo systemctl enable ensure_running.service
4-
sudo systemctl start ensure_running.service
2+
sudo cp ensure_running.service /etc/systemd/system/socket_server_ensure_running.service
3+
sudo systemctl enable socket_server_ensure_running.service
4+
sudo systemctl start socket_server_ensure_running.service

0 commit comments

Comments
 (0)