Store state in localdata

The tailscaled.state file in localdata will now persist across updates, so your camera stays connected to Tailscale without re-authentication
This commit is contained in:
Weston Blieden
2025-12-17 09:31:34 +01:00
parent 2d1ff5e8a6
commit 396b450415
6 changed files with 150 additions and 44 deletions
+28 -8
View File
@@ -1,10 +1,30 @@
#!/bin/sh
echo "Starting Service"
chmod 777 /usr/local/packages/Tailscale_VPN/lib/tailscale
chmod 777 /usr/local/packages/Tailscale_VPN/lib/tailscaled
/usr/local/packages/Tailscale_VPN/lib/tailscaled --socks5-server=localhost:1055 --tun=userspace-networking --socket=/usr/local/packages/Tailscale_VPN/tailscaled.sock &
echo "Service Started"
echo "Scroll to Bottom for link"
/usr/local/packages/Tailscale_VPN/lib/tailscale --socket=/usr/local/packages/Tailscale_VPN/tailscaled.sock up
wait
echo "Starting Service"
# Define paths
APP_DIR="/usr/local/packages/Tailscale_VPN"
STATE_DIR="$APP_DIR/localdata"
# Create localdata directory if it doesn't exist
mkdir -p "$STATE_DIR"
# Set permissions
chmod 777 "$APP_DIR/lib/tailscale"
chmod 777 "$APP_DIR/lib/tailscaled"
# Start tailscaled with state stored in localdata
"$APP_DIR/lib/tailscaled" \
--state="$STATE_DIR/tailscaled.state" \
--socket="$STATE_DIR/tailscaled.sock" \
--socks5-server=localhost:1055 \
--tun=userspace-networking &
echo "Service Started"
sleep 2
echo "Scroll to Bottom for link"
# Run tailscale up with the socket in localdata
"$APP_DIR/lib/tailscale" --socket="$STATE_DIR/tailscaled.sock" up
wait
+26 -8
View File
@@ -1,10 +1,28 @@
#!/bin/sh
echo "Starting Service"
chmod 777 /usr/local/packages/Tailscale_VPN/lib/tailscale
chmod 777 /usr/local/packages/Tailscale_VPN/lib/tailscaled
/usr/local/packages/Tailscale_VPN/lib/tailscaled &
echo "Service Started"
echo "Scroll to Bottom for link"
/usr/local/packages/Tailscale_VPN/lib/tailscale up --accept-routes
wait
echo "Starting Service"
# Define paths
APP_DIR="/usr/local/packages/Tailscale_VPN"
STATE_DIR="$APP_DIR/localdata"
# Create localdata directory if it doesn't exist
mkdir -p "$STATE_DIR"
# Set permissions
chmod 777 "$APP_DIR/lib/tailscale"
chmod 777 "$APP_DIR/lib/tailscaled"
# Start tailscaled with state stored in localdata
"$APP_DIR/lib/tailscaled" \
--state="$STATE_DIR/tailscaled.state" \
--socket="$STATE_DIR/tailscaled.sock" &
echo "Service Started"
sleep 2
echo "Scroll to Bottom for link"
# Run tailscale up with the socket in localdata
"$APP_DIR/lib/tailscale" --socket="$STATE_DIR/tailscaled.sock" up --accept-routes
wait
+27 -6
View File
@@ -17,7 +17,9 @@
#include <errno.h>
#define APP_NAME "serverconfig"
#define CONFIG_FILE "/usr/local/packages/serverconfig/config.txt"
#define APP_DIR "/usr/local/packages/serverconfig"
#define STATE_DIR APP_DIR "/localdata"
#define CONFIG_FILE STATE_DIR "/config.txt"
#define SCRIPT_PATH "/usr/local/packages/serverconfig/start_tailscale.sh"
#define SCRIPT_SOURCE "/usr/local/packages/serverconfig/lib/start_tailscale.sh"
@@ -27,6 +29,19 @@ static gboolean signal_handler(gpointer loop) {
return G_SOURCE_REMOVE;
}
// Create localdata directory
static void ensure_localdata_exists(void) {
struct stat st = {0};
if (stat(STATE_DIR, &st) == -1) {
if (mkdir(STATE_DIR, 0755) != 0) {
syslog(LOG_ERR, "Failed to create localdata directory: %s", strerror(errno));
} else {
syslog(LOG_INFO, "Created localdata directory: %s", STATE_DIR);
}
}
}
// Copy script from lib folder to main directory
static void copy_script_file(void) {
char buffer[4096];
@@ -109,6 +124,9 @@ static void update_config_file(AXParameter* handle) {
gchar* key_value = NULL;
FILE* file;
// Ensure localdata directory exists
ensure_localdata_exists();
// Get parameter values
if (!ax_parameter_get(handle, "CustomServer", &server_value, &error)) {
syslog(LOG_ERR, "Failed to get CustomServer: %s",
@@ -125,7 +143,7 @@ static void update_config_file(AXParameter* handle) {
key_value = g_strdup("");
}
// Write to config file
// Write to config file in localdata
file = fopen(CONFIG_FILE, "w");
if (file) {
fprintf(file, "custom_server=%s\n", server_value ? server_value : "");
@@ -135,12 +153,12 @@ static void update_config_file(AXParameter* handle) {
// Set permissions to ensure the file is readable
chmod(CONFIG_FILE, 0644);
syslog(LOG_INFO, "Updated configuration file: custom_server=%s",
syslog(LOG_INFO, "Updated configuration file in local custom_server=%s",
server_value ? server_value : "");
syslog(LOG_INFO, "Updated configuration file: auth_key=%s",
syslog(LOG_INFO, "Updated configuration file in local auth_key=%s",
key_value && strlen(key_value) > 0 ? "(set)" : "(empty)");
} else {
syslog(LOG_ERR, "Failed to open config file for writing");
syslog(LOG_ERR, "Failed to open config file for writing: %s", strerror(errno));
}
// Clean up
@@ -185,6 +203,9 @@ int main(void) {
exit(1);
}
// Ensure localdata directory exists
ensure_localdata_exists();
// Ensure script is copied from lib folder
copy_script_file();
@@ -229,4 +250,4 @@ int main(void) {
ax_parameter_free(handle);
return 0;
}
}
+15 -6
View File
@@ -5,10 +5,15 @@
pkill -f tailscaled || true
# Simple script to start Tailscale with custom configuration
CONFIG_FILE="/usr/local/packages/serverconfig/config.txt"
TAILSCALED_PATH="/usr/local/packages/serverconfig/lib/tailscaled"
TAILSCALE_PATH="/usr/local/packages/serverconfig/lib/tailscale"
SOCKET_PATH="/usr/local/packages/serverconfig/tailscaled.sock"
APP_DIR="/usr/local/packages/serverconfig"
STATE_DIR="$APP_DIR/localdata"
CONFIG_FILE="$STATE_DIR/config.txt"
TAILSCALED_PATH="$APP_DIR/lib/tailscaled"
TAILSCALE_PATH="$APP_DIR/lib/tailscale"
SOCKET_PATH="$STATE_DIR/tailscaled.sock"
# Create localdata directory if it doesn't exist
mkdir -p "$STATE_DIR"
# Log to syslog
logger -t "tailscale_script" "Starting Tailscale VPN service"
@@ -31,9 +36,13 @@ if [ -f "$CONFIG_FILE" ]; then
done < "$CONFIG_FILE"
fi
# Start tailscaled
# Start tailscaled with state stored in localdata
logger -t "tailscale_script" "Starting tailscaled daemon"
$TAILSCALED_PATH --socks5-server=localhost:1055 --tun=userspace-networking --socket=$SOCKET_PATH &
$TAILSCALED_PATH \
--state="$STATE_DIR/tailscaled.state" \
--socket=$SOCKET_PATH \
--socks5-server=localhost:1055 \
--tun=userspace-networking &
TAILSCALED_PID=$!
# Wait for tailscaled to initialize
+28 -8
View File
@@ -1,10 +1,30 @@
#!/bin/sh
echo "Starting Service"
chmod 777 /usr/local/packages/Tailscale_VPN/lib/tailscale
chmod 777 /usr/local/packages/Tailscale_VPN/lib/tailscaled
/usr/local/packages/Tailscale_VPN/lib/tailscaled --socks5-server=localhost:1055 --tun=userspace-networking --socket=/usr/local/packages/Tailscale_VPN/tailscaled.sock &
echo "Service Started"
echo "Scroll to Bottom for link"
/usr/local/packages/Tailscale_VPN/lib/tailscale --socket=/usr/local/packages/Tailscale_VPN/tailscaled.sock up
wait
echo "Starting Service"
# Define paths
APP_DIR="/usr/local/packages/Tailscale_VPN"
STATE_DIR="$APP_DIR/localdata"
# Create localdata directory if it doesn't exist
mkdir -p "$STATE_DIR"
# Set permissions
chmod 777 "$APP_DIR/lib/tailscale"
chmod 777 "$APP_DIR/lib/tailscaled"
# Start tailscaled with state stored in localdata
"$APP_DIR/lib/tailscaled" \
--state="$STATE_DIR/tailscaled.state" \
--socket="$STATE_DIR/tailscaled.sock" \
--socks5-server=localhost:1055 \
--tun=userspace-networking &
echo "Service Started"
sleep 2
echo "Scroll to Bottom for link"
# Run tailscale up with the socket in localdata
"$APP_DIR/lib/tailscale" --socket="$STATE_DIR/tailscaled.sock" up
wait
+26 -8
View File
@@ -1,10 +1,28 @@
#!/bin/sh
echo "Starting Service"
chmod 777 /usr/local/packages/Tailscale_VPN/lib/tailscale
chmod 777 /usr/local/packages/Tailscale_VPN/lib/tailscaled
/usr/local/packages/Tailscale_VPN/lib/tailscaled &
echo "Service Started"
echo "Scroll to Bottom for link"
/usr/local/packages/Tailscale_VPN/lib/tailscale up --accept-routes
wait
echo "Starting Service"
# Define paths
APP_DIR="/usr/local/packages/Tailscale_VPN"
STATE_DIR="$APP_DIR/localdata"
# Create localdata directory if it doesn't exist
mkdir -p "$STATE_DIR"
# Set permissions
chmod 777 "$APP_DIR/lib/tailscale"
chmod 777 "$APP_DIR/lib/tailscaled"
# Start tailscaled with state stored in localdata
"$APP_DIR/lib/tailscaled" \
--state="$STATE_DIR/tailscaled.state" \
--socket="$STATE_DIR/tailscaled.sock" &
echo "Service Started"
sleep 2
echo "Scroll to Bottom for link"
# Run tailscale up with the socket in localdata
"$APP_DIR/lib/tailscale" --socket="$STATE_DIR/tailscaled.sock" up --accept-routes
wait