Use nssm instead of sc
This commit is contained in:
parent
59ba823865
commit
d05ba5cc55
10
Makefile
10
Makefile
@ -4,9 +4,12 @@ VERSION = 0.1.0
|
|||||||
|
|
||||||
all: build run
|
all: build run
|
||||||
|
|
||||||
|
# Default build
|
||||||
build:
|
build:
|
||||||
@if not exist $(BIN_DIR) mkdir $(BIN_DIR)
|
@if not exist $(BIN_DIR) mkdir $(BIN_DIR)
|
||||||
go build -ldflags "-s -w -X main.version=$(VERSION)" -o $(BIN_DIR)\$(APP_NAME).exe .
|
set CGO_ENABLED=0 && \
|
||||||
|
set GOOS=windows && set GOARCH=amd64 && \
|
||||||
|
go build -ldflags="-s -w -trimpath -X main.version=$(VERSION)" -o $(BIN_DIR)\$(APP_NAME).exe .
|
||||||
|
|
||||||
run:
|
run:
|
||||||
go run .
|
go run .
|
||||||
@ -14,9 +17,12 @@ run:
|
|||||||
clean:
|
clean:
|
||||||
@if exist $(BIN_DIR) rmdir /s /q $(BIN_DIR)
|
@if exist $(BIN_DIR) rmdir /s /q $(BIN_DIR)
|
||||||
|
|
||||||
|
# Windows-specific optimized build
|
||||||
windows:
|
windows:
|
||||||
@if not exist $(BIN_DIR) mkdir $(BIN_DIR)
|
@if not exist $(BIN_DIR) mkdir $(BIN_DIR)
|
||||||
set GOOS=windows&& set GOARCH=amd64&& go build -o $(BIN_DIR)\$(APP_NAME).exe .
|
set CGO_ENABLED=0 && \
|
||||||
|
set GOOS=windows && set GOARCH=amd64 && \
|
||||||
|
go build -ldflags="-s -w -trimpath -X main.version=$(VERSION)" -o $(BIN_DIR)\$(APP_NAME).exe .
|
||||||
|
|
||||||
tidy:
|
tidy:
|
||||||
go mod tidy
|
go mod tidy
|
||||||
|
|||||||
5
bin/config.json
Normal file
5
bin/config.json
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"update_url": "https://triztech.pro/cpanelwebcall/TOKEN",
|
||||||
|
"check_interval_seconds": 30,
|
||||||
|
"ip_check_url": "https://api.ipify.org"
|
||||||
|
}
|
||||||
@ -1,23 +1,41 @@
|
|||||||
@echo off
|
@echo off
|
||||||
|
REM ===============================
|
||||||
|
REM DDNS Updater Install using NSSM
|
||||||
|
REM ===============================
|
||||||
|
|
||||||
REM Get the folder where this bat is located
|
REM Get the folder where this bat is located
|
||||||
SET SCRIPT_DIR=%~dp0
|
SET SCRIPT_DIR=%~dp0
|
||||||
|
|
||||||
REM Define the service exe path (same folder as bat)
|
REM Define program and NSSM paths
|
||||||
SET EXE_NAME=DDNSUpdater.exe
|
SET EXE_NAME=DDNSUpdater.exe
|
||||||
SET EXE_PATH=%SCRIPT_DIR%%EXE_NAME%
|
SET EXE_PATH=%SCRIPT_DIR%%EXE_NAME%
|
||||||
|
SET NSSM_PATH=%SCRIPT_DIR%nssm.exe
|
||||||
|
|
||||||
REM Check if the exe exists
|
REM Check if files exist
|
||||||
IF NOT EXIST "%EXE_PATH%" (
|
IF NOT EXIST "%EXE_PATH%" (
|
||||||
echo ERROR: %EXE_NAME% not found in the same folder as this script.
|
echo ERROR: %EXE_NAME% not found in the same folder as this script.
|
||||||
pause
|
pause
|
||||||
exit /b 1
|
exit /b 1
|
||||||
)
|
)
|
||||||
|
|
||||||
REM Create the service (auto-start)
|
IF NOT EXIST "%NSSM_PATH%" (
|
||||||
sc create DDNSUpdaterService binPath= "%EXE_PATH%" start= auto
|
echo ERROR: nssm.exe not found in the same folder as this script.
|
||||||
|
pause
|
||||||
|
exit /b 1
|
||||||
|
)
|
||||||
|
|
||||||
|
REM Remove existing service if present
|
||||||
|
"%NSSM_PATH%" remove DDNSUpdaterService confirm
|
||||||
|
|
||||||
|
REM Install service
|
||||||
|
"%NSSM_PATH%" install DDNSUpdaterService "%EXE_PATH%"
|
||||||
|
|
||||||
|
REM Optional: auto-start at boot
|
||||||
|
"%NSSM_PATH%" set DDNSUpdaterService Start SERVICE_AUTO_START
|
||||||
|
|
||||||
REM Start the service
|
REM Start the service
|
||||||
sc start DDNSUpdaterService
|
"%NSSM_PATH%" start DDNSUpdaterService
|
||||||
|
|
||||||
echo Service DDNSUpdaterService installed and started.
|
echo.
|
||||||
|
echo DDNSUpdaterService installed and started successfully!
|
||||||
pause
|
pause
|
||||||
|
|||||||
BIN
bin/nssm.exe
Normal file
BIN
bin/nssm.exe
Normal file
Binary file not shown.
@ -1,5 +1,21 @@
|
|||||||
@echo off
|
@echo off
|
||||||
sc stop DDNSUpdaterService
|
REM ===============================
|
||||||
sc delete DDNSUpdaterService
|
REM DDNS Updater Uninstall using NSSM
|
||||||
echo Service DDNSUpdaterService stopped and deleted.
|
REM ===============================
|
||||||
|
|
||||||
|
SET SCRIPT_DIR=%~dp0
|
||||||
|
SET NSSM_PATH=%SCRIPT_DIR%nssm.exe
|
||||||
|
|
||||||
|
IF NOT EXIST "%NSSM_PATH%" (
|
||||||
|
echo ERROR: nssm.exe not found in the same folder as this script.
|
||||||
|
pause
|
||||||
|
exit /b 1
|
||||||
|
)
|
||||||
|
|
||||||
|
REM Stop and remove the service
|
||||||
|
"%NSSM_PATH%" stop DDNSUpdaterService
|
||||||
|
"%NSSM_PATH%" remove DDNSUpdaterService confirm
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo DDNSUpdaterService uninstalled successfully!
|
||||||
pause
|
pause
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user