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