修复安装问题
This commit is contained in:
+6
-1
@@ -78,8 +78,13 @@ func getDefaultSocketPath() string {
|
||||
return ""
|
||||
}
|
||||
// LoadConfig reads the config file or creates one with defaults.
|
||||
func LoadConfig() *Config {
|
||||
// If customPath is non-empty, it overrides the OS-aware config file path.
|
||||
func LoadConfig(customPath string) *Config {
|
||||
configDir, configFile := getConfigPath()
|
||||
if customPath != "" {
|
||||
configFile = customPath
|
||||
configDir = filepath.Dir(configFile)
|
||||
}
|
||||
defaultPath := getDefaultStoragePath()
|
||||
|
||||
// Check if config file exists; create with defaults if not.
|
||||
|
||||
+5
-1
@@ -42,13 +42,17 @@ chmod 0755 "${INSTALL_DIR}"
|
||||
find "${INSTALL_DIR}/templates" -type d -exec chmod 0755 {} \;
|
||||
find "${INSTALL_DIR}/templates" -type f -exec chmod 0644 {} \;
|
||||
|
||||
SOCKET_PATH="${INSTALL_DIR}/web.sock"
|
||||
|
||||
if [[ ! -f "${CONFIG_DIR}/config.yaml" ]]; then
|
||||
SECRET=$(openssl rand -hex 32)
|
||||
cat > "${CONFIG_DIR}/config.yaml" <<EOF
|
||||
database:
|
||||
type: sqlite
|
||||
dsn: ""
|
||||
web:
|
||||
port: "8080"
|
||||
socket: ${SOCKET_PATH}
|
||||
path: ${DATA_DIR}
|
||||
secret: ${SECRET}
|
||||
EOF
|
||||
@@ -68,7 +72,7 @@ Type=simple
|
||||
User=${SERVICE_USER}
|
||||
Group=${SERVICE_USER}
|
||||
WorkingDirectory=${INSTALL_DIR}
|
||||
ExecStart=${INSTALL_DIR}/${BINARY_NAME}
|
||||
ExecStart=${INSTALL_DIR}/${BINARY_NAME} -config ${CONFIG_DIR}/config.yaml
|
||||
Restart=on-failure
|
||||
RestartSec=5s
|
||||
NoNewPrivileges=true
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
@@ -17,8 +18,12 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
// 0. Parse command-line flags.
|
||||
configFlag := flag.String("config", "", "path to config file (default: OS-aware path)")
|
||||
flag.Parse()
|
||||
|
||||
// 1. Load configuration (auto-creates if missing).
|
||||
cfg := config.LoadConfig()
|
||||
cfg := config.LoadConfig(*configFlag)
|
||||
|
||||
// 2. Initialize the database (auto-migrates, seeds admin).
|
||||
db := models.InitDB(cfg)
|
||||
|
||||
Reference in New Issue
Block a user