Skip to content

Instantly share code, notes, and snippets.

@fliedonion
Last active December 14, 2016 17:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fliedonion/5418d72869ff9812027a9df98b10e2d6 to your computer and use it in GitHub Desktop.
Save fliedonion/5418d72869ff9812027a9df98b10e2d6 to your computer and use it in GitHub Desktop.
install bat for gogs with nssm

install gogs with nssm.

summary

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.

see also

https://gogs.io/docs/installation/run_as_windows_service https://nssm.cc/commands https://nssm.cc/usage

other requirements

  • 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.

bat file source

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment