usage:
gogs-nssm-installer.bat <your-machine-name> <ip-of-your-machine> <port-for-gogs-web>
ex) gogs-nssm-installer.bat mywin8 192.168.0.10 5050
important notice: If use none secure location, use loopback ip (like 127.0.1.1) for gogs and use gogs behind other web server (nginx, apache etc).
note: [your-machine-name] will use for url. so I recommend use lowercase. note: this bat does not maintain hosts file.
https://gogs.io/docs/installation/run_as_windows_service https://nssm.cc/commands https://nssm.cc/usage
-
nssm extarct to c:\opt\nssm (or modify bat file with your environment)
c:\opt\nssm\win32\nssm.exe -
gogs (32bit) extarct to c:\opt\gogs (or modify bat file with your environment)
c:\opt\gogs\gogs.exe -
portable git (32bit) extarct to c:\opt\gogs\PortableGit (or modify bat file with your environment)
c:\opt\gogs\PortableGit\bin\git.exe
If your windows is 64bit, I recommend install 32bit version.
Some environment, 64bit git-bash is slow.
If your git-bash(64bit) is not slow, use 64bit version (nssm, gogs and portable-git).
note: nssm includes 32bit and 64bit.
gogs-nssm-installer.bat
@echo off
IF [%1] == [] goto usage
IF [%2] == [] goto usage
IF [%3] == [] goto usage
setlocal
@echo url -^> http://%1:%3/
@echo ip -^> %2
@echo runuser -^> %COMPUTERNAME%$
set nssm=C:\opt\nssm\win32\nssm.exe
set gogspath=C:\opt\gogs
set gitpath=C:\opt\gogs\PortableGit\bin
if not exist %nssm% (
echo !! nssm not found !!
echo need %nssm% to install.
goto end
)
if not exist %gogspath%\gogs.exe (
echo !! gogs.exe not found !!
echo you need %gogspath%\gogs.exe to install.
goto end
)
if not exist %gitpath%\git.exe (
echo !! git.exe not found !!
echo you need %gitpath%\git.exe to install.
goto end
)
if exist %gogspath%\custom\conf\app.ini (
echo !! app.ini already exists !!
echo %gogspath%\custom\conf\app.ini exists. remove or rename that file first.
goto end
)
SET /P AREYOUSURE=Are you sure (Y/[N])?
IF /I "%AREYOUSURE%" NEQ "Y" GOTO end
if not exist %gogspath%\custom\conf (
mkdir %gogspath%\custom\conf
)
set appini=%gogspath%\custom\conf\app.ini
echo RUN_USER = %COMPUTERNAME%$> %appini%
echo.>>%appini%
echo [server]>>%appini%
echo DOMAIN = %1>>%appini%
echo PROTOCOL = http>>%appini%
echo HTTP_ADDR = %2>>%appini%
echo HTTP_PORT = %3>>%appini%
echo OFFLINE_MODE = true>>%appini%
echo ROOT_URL = http://%1:%3/>>%appini%
echo.>>%appini%
type %appini%
@echo hit any key to continue or ctrl+c to abort.
pause
%nssm% install gogs %gogspath%\gogs.exe
if %ERRORLEVEL% NEQ 0 (
echo !! service install error !!
echo to remove existing service run following
echo %nssm% stop gogs
echo %nssm% remove gogs
goto end
)
%nssm% set gogs AppDirectory %gogspath%
%nssm% set gogs AppParameters web
%nssm% set gogs DisplayName "Go Gits Service"
%nssm% set gogs Description "Gogs (Go Git Service) is a painless self-hosted Git service."
%nssm% set gogs Start SERVICE_DELAYED_AUTO_START
%nssm% set gogs AppStdout %gogspath%\log\gogs-nssm.txt
%nssm% set gogs AppStderr %gogspath%\log\gogs-nssm.txt
%nssm% set gogs AppRotateFiles 1
%nssm% set gogs AppRotateBytes 1000000
%nssm% set gogs AppEnvironmentExtra PATH=%gogspath%;%gitpath%;%%PATH%%
%nssm% start gogs
goto end
:usage
@echo Usage: %0 ^<url-host^> ^<ip^> ^<port^>
exit /B 1
:end
endlocal