Skip to content

Commit 9207f21

Browse files
committed
configuration and script update
1 parent ca4727e commit 9207f21

File tree

7 files changed

+48
-28
lines changed

7 files changed

+48
-28
lines changed

config/config.go

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,44 @@
11
package config
22

33
import (
4+
"fmt"
45
"log"
56
"os"
67

78
"github.com/joho/godotenv"
89
)
910

1011
var ConfigFiles =[]string{
11-
".env",
1212
"/var/lib/vilesql/.env",
13+
".env",
1314
}
1415

15-
func GetValue(key string) string {
16-
var configFile string
17-
for _, file := range ConfigFiles {
16+
func getConfigFile() (string, error){
17+
var count = 0
18+
for count < len(ConfigFiles) {
19+
file := ConfigFiles[count]
1820
if _, err := os.Stat(file); err == nil {
19-
configFile = file
20-
break
21-
} else {
22-
log.Printf("Error accessing configuration file %s: %v", file, err)
21+
return file, nil
2322
}
23+
count++
2424
}
25-
err := godotenv.Load(configFile)
25+
return "", fmt.Errorf("⚠️ Warning: using default variables")
26+
}
27+
28+
func GetValue(key string) string {
29+
var configFile, err = getConfigFile()
2630
if err != nil {
27-
log.Printf("⚠️ Warning: %s, using default variables", err.Error())
31+
log.Printf("%s", err.Error())
32+
godotenv.Load()
33+
34+
// Set default values if variables are missing
35+
setDefaultEnv("SESSION_KEY", "default-session-key")
36+
setDefaultEnv("COOKIE_STORE_KEY", "default-cookie-key")
37+
log.Printf("key: %s value: %s, Config File: %s", key, os.Getenv(key), configFile)
38+
return os.Getenv(key)
2839
}
29-
// Set default values if variables are missing
30-
setDefaultEnv("SESSION_KEY", "default-session-key")
31-
setDefaultEnv("COOKIE_STORE_KEY", "default-cookie-key")
40+
godotenv.Load(configFile)
41+
log.Printf("key: %s value: %s, Config File: %s", key, os.Getenv(key), configFile)
3242
return os.Getenv(key)
3343
}
3444

scripts/postinstall.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
set -e
55

66
DATA_DIR="/var/lib/vilesql"
7-
CONFIG_DIR="$DATA_DIR"
87
LOG_DIR="/var/log/vilesql"
98
LOG_FILE="$LOG_DIR/vilesql.log"
9+
RUNTIME_LOG_FILE="/var/log/vilesql.log"
1010
BIN_PATH="/usr/bin/vilesql"
1111
SERVICE_PATH="/etc/systemd/system/vilesql.service"
1212
ENV_FILE="$DATA_DIR/.env"
@@ -42,7 +42,7 @@ chown "$USER:$GROUP" "$BIN_PATH"
4242
chmod 755 "$BIN_PATH"
4343

4444
# Create necessary directories with correct ownership
45-
for dir in "$DATA_DIR" "$CONFIG_DIR" "$LOG_DIR"; do
45+
for dir in "$DATA_DIR" "$LOG_DIR"; do
4646
if [[ ! -d "$dir" ]]; then
4747
log "📁 Creating directory: $dir"
4848
mkdir -p "$dir" || {
@@ -79,7 +79,6 @@ chmod 755 "$ENV_FILE"
7979

8080
# Set secure permissions for other directories
8181
chmod 755 "$DATA_DIR"
82-
chmod 755 "$CONFIG_DIR"
8382
chmod 755 "$LOG_DIR"
8483

8584
# Install systemd service file (if missing)
@@ -130,5 +129,6 @@ echo "🚀 Next steps:"
130129
echo " 1️⃣ Edit config: sudo nano $ENV_FILE"
131130
echo " 2️⃣ Check status: sudo systemctl status vilesql"
132131
echo " 3️⃣ View logs: sudo tail -f $LOG_FILE"
132+
echo " 3️⃣ View runtime logs: sudo tail -f $LOG_FILE"
133133
echo " 4️⃣ Run manually: sudo -u vilesql /usr/bin/vilesql --help"
134134
echo ""

scripts/postremove.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ set -e
55

66
SYSTEMD_SERVICE="/etc/systemd/system/vilesql.service"
77
DATA_DIR="/var/lib/vilesql"
8-
CONFIG_DIR="$DATA_DIR"
8+
CONFIG_FILE="$DATA_DIR/.env"
99
USER="vilesql"
1010
GROUP="vilesql"
11+
LOG_DIR="/var/log/vilesql"
12+
LOG_FILE="$LOG_DIR/vilesql.log"
13+
RUNTIME_LOG_FILE="/var/log/vilesql.log"
1114

1215
log() {
1316
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1"
@@ -45,5 +48,5 @@ echo ""
4548
echo "🚀 VileSQL has been removed!"
4649
echo "📌 Note: Data directories were preserved."
4750
echo "To **completely remove** all data, run:"
48-
echo " sudo rm -rf $DATA_DIR $CONFIG_DIR"
51+
echo " sudo rm -rf $DATA_DIR $CONFIG_FILE $LOG_DIR $RUNTIME_LOG_FILE"
4952
echo ""

scripts/postupgrade.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
set -e
55

66
DATA_DIR="/var/lib/vilesql"
7-
CONFIG_DIR="$DATA_DIR"
7+
CONFIG_FILE="$DATA_DIR/.env"
88
SYSTEMD_SERVICE="/etc/systemd/system/vilesql.service"
99
USER="vilesql"
1010
GROUP="vilesql"
@@ -23,7 +23,7 @@ if [[ "$EUID" -ne 0 ]]; then
2323
fi
2424

2525
# Create directories if missing
26-
for dir in "$DATA_DIR" "$CONFIG_DIR"; do
26+
for dir in "$DATA_DIR"; do
2727
if [[ ! -d "$dir" ]]; then
2828
log "📁 Creating directory: $dir"
2929
mkdir -p "$dir"
@@ -33,7 +33,7 @@ done
3333

3434
# Set secure permissions
3535
chmod 755 "$DATA_DIR"
36-
chmod 700 "$CONFIG_DIR"
36+
chmod 755 "$CONFIG_FILE"
3737

3838
# Run database migrations if vilesql is installed
3939
if command -v vilesql &>/dev/null; then
@@ -116,7 +116,7 @@ log "✅ Post-upgrade script completed successfully!"
116116
echo ""
117117
echo "🚀 VileSQL has been successfully upgraded!"
118118
echo "📁 Data directory: $DATA_DIR"
119-
echo "⚙️ Configuration file: $CONFIG_DIR/.env"
119+
echo "⚙️ Configuration file: $CONFIG_FILE"
120120
echo ""
121121
echo "🔄 To start the service: sudo systemctl start vilesql"
122122
echo "📌 To check status: sudo systemctl status vilesql"

scripts/preremove.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ USER="vilesql"
77
GROUP="vilesql"
88
SYSTEMD_SERVICE="/etc/systemd/system/vilesql.service"
99
DATA_DIR="/var/lib/vilesql"
10-
CONFIG_DIR="$DATA_DIR"
10+
CONFIG_FILE="$DATA_DIR/.env"
11+
LOG_DIR="/var/log/vilesql"
12+
LOG_FILE="$LOG_DIR/vilesql.log"
13+
RUNTIME_LOG_FILE="/var/log/vilesql.log"
1114

1215
log() {
1316
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1"
@@ -56,5 +59,5 @@ echo ""
5659
echo "🚀 VileSQL service has been disabled and stopped!"
5760
echo "📌 Note: Data directories were **preserved**."
5861
echo "To **completely remove** all data, run:"
59-
echo " sudo rm -rf $DATA_DIR $CONFIG_DIR"
62+
echo " sudo rm -rf $DATA_DIR $CONFIG_FILE $LOG_DIR $RUNTIME_LOG_FILE"
6063
echo ""

scripts/uninstall.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ USER="vilesql"
1010
GROUP="vilesql"
1111
SERVICE_PATH="/etc/systemd/system/vilesql.service"
1212
DATA_DIR="/var/lib/vilesql"
13-
CONFIG_DIR="$DATA_DIR"
13+
CONFIG_FILE="$DATA_DIR/.env"
14+
LOG_DIR="/var/log/vilesql"
15+
LOG_FILE="/var/log/vilesql.log"
1416

1517
log() {
1618
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1"
@@ -68,12 +70,14 @@ fi
6870
# Offer to remove data directories
6971
echo "📂 Data directories found:"
7072
echo " - $DATA_DIR"
71-
echo " - $CONFIG_DIR"
73+
echo " - $CONFIG_FILE"
74+
echo " - $LOG_DIR"
75+
echo " - $LOG_FILE"
7276
read -p "Remove all data directories? (y/N): " -n 1 -r
7377
echo
7478
if [[ $REPLY =~ ^[Yy]$ ]]; then
7579
log "🗑️ Removing data directories..."
76-
sudo rm -rf "$DATA_DIR" "$CONFIG_DIR"
80+
sudo rm -rf "$DATA_DIR" "$CONFIG_FILE" "$LOG_DIR" "$LOG_FILE"
7781
log "✅ Data directories removed."
7882
else
7983
log "📂 Data directories preserved."

scripts/vilesql.service

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ WorkingDirectory=/var/lib/vilesql
1313

1414
# Load environment variables before executing VileSQL
1515
EnvironmentFile=/var/lib/vilesql/.env
16-
ExecStart=/bin/bash -c 'source /var/lib/vilesql/.env && exec /usr/bin/vilesql --host=$HOST --port=5000'
16+
ExecStart=/bin/bash -c 'source /var/lib/vilesql/.env && exec /usr/bin/vilesql --host=$HOST --port=5000 --verbose'
1717
ExecReload=/bin/kill -USR2 $MAINPID
1818

1919
Restart=always

0 commit comments

Comments
 (0)