Skip to content

Commit 54316f0

Browse files
author
3aa49ec6bfc910647fa1c5a013e48eef
committed
Added support for other rclone providers
1 parent 3517914 commit 54316f0

File tree

4 files changed

+61
-7
lines changed

4 files changed

+61
-7
lines changed

deploy/install-website.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ EOF
4444
cd /bin/node-teslausb/build/website
4545
npm i --omit=dev
4646

47+
echo "Configuring website service..."
48+
4749
# Enable the service
4850
systemctl enable node-teslausb-www.service
4951

@@ -52,3 +54,5 @@ systemctl restart node-teslausb-www
5254

5355
# Refresh the systemd daemon
5456
systemctl daemon-reload
57+
58+
echo "Website service configured"

deploy/install-worker.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,15 @@ Restart=always
4646
WantedBy=multi-user.target
4747
EOF
4848

49+
echo "Configuring worker service..."
50+
4951
# Enable the service
5052
systemctl enable node-teslausb.service
5153

5254
# Restart website (need to test whether this will just start if not running)
5355
systemctl restart node-teslausb
5456

5557
# Refresh the systemd daemon
56-
systemctl daemon-reload
58+
systemctl daemon-reload
59+
60+
echo "Worker service configured"

src/worker/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const processInterval = async () => {
4444
return;
4545
}
4646

47-
const archiveReachable = await checkIfArchiveIsReachable(config.archive.server);
47+
const archiveReachable = await checkIfArchiveIsReachable();
4848
if (archiveReachable === false) {
4949
await restartWifi();
5050
} else if (state.lastCopyDate === undefined || ((new Date()).getTime() > (new Date(state.lastCopyDate)).getTime() + config.delayBetweenCopyRetryInSeconds * 1000)) {

src/worker/src/modules/network.ts

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,70 @@
11
import { logWithTimestamp, errorWithTimestamp } from "./log.js";
22
import ping from "ping";
33
import { executeBashCommand } from "./bash.js";
4+
import { getRcloneConfig } from "./rclone.js";
45

56
export const restartWifi = async () => {
67
logWithTimestamp("Restarting wifi")
78
await executeBashCommand("ifconfig wlan0 down && ifconfig wlan0 up")
89
}
910

10-
export const checkIfArchiveIsReachable = async (archiveServer) => {
11+
export const checkIfArchiveIsReachable = async () => {
1112

13+
const config = getRcloneConfig()
14+
const connectivityTestType = getConnectivityTestType(config)
15+
16+
if (connectivityTestType === ConnectivityTestType.internetConnected) {
17+
return await testInternetConnected()
18+
}
19+
20+
if (connectivityTestType === ConnectivityTestType.pingHost) {
21+
return await testPingHost(config.host)
22+
}
23+
24+
};
25+
26+
const testPingHost = async (host: string) => {
27+
try {
28+
const res = await ping.promise.probe(host, {
29+
timeout: 5, // Timeout in seconds
30+
extra: ["-c", "1"], // Sends only 1 packet
31+
});
32+
33+
logWithTimestamp(`${host} is ${res.alive ? 'reachable' : 'not reachable'}`);
34+
return res.alive;
35+
} catch (error) {
36+
errorWithTimestamp('Error pinging host:', error);
37+
return false;
38+
}
39+
}
40+
41+
const testInternetConnected = async () => {
1242
try {
13-
const res = await ping.promise.probe(archiveServer, {
43+
const res = await ping.promise.probe("google.com", {
1444
timeout: 5, // Timeout in seconds
1545
extra: ["-c", "1"], // Sends only 1 packet
1646
});
1747

18-
logWithTimestamp(`${archiveServer} is ${res.alive ? 'reachable' : 'not reachable'}`);
48+
logWithTimestamp(`Internet is ${res.alive ? 'reachable' : 'not reachable'}`);
1949
return res.alive;
2050
} catch (error) {
21-
errorWithTimestamp('Error pinging archive server:', error);
51+
errorWithTimestamp('Error pinging google.com:', error);
2252
return false;
2353
}
24-
};
54+
}
55+
56+
enum ConnectivityTestType {
57+
pingHost = "pingHost",
58+
internetConnected = "internetConnected",
59+
}
60+
61+
const getConnectivityTestType = (config: any) => {
62+
let connectivityTestType: ConnectivityTestType;
63+
switch (config.type) {
64+
case "smb":
65+
connectivityTestType = ConnectivityTestType.pingHost
66+
default:
67+
connectivityTestType = ConnectivityTestType.internetConnected
68+
}
69+
return connectivityTestType
70+
}

0 commit comments

Comments
 (0)