Skip to main content
Running Gogs as a system service ensures it starts automatically on boot and restarts if it crashes. Choose the init system or service manager that matches your operating system.

Linux

Systemd is the default init system on most modern Linux distributions (Ubuntu 16.04+, Debian 8+, CentOS 7+, Fedora, Arch Linux, etc.).Gogs ships with a systemd service template at scripts/systemd/gogs.service in the installation directory.

1. Customize the service file

Copy the template and edit it to match your installation:
Here is the default service file for reference:
Update the following values to match your environment:
  • User and Group — the system user running Gogs
  • WorkingDirectory — the Gogs installation directory
  • ExecStart — the full path to the Gogs binary
  • Environment — ensure USER and HOME match the Gogs user
If you use MySQL/MariaDB, PostgreSQL, Redis, or Memcached, the After= lines ensure Gogs starts after those services. Uncomment or add lines as needed for your database.

2. Enable and start the service

3. Verify the service

If you have repositories with a large number of files and encounter HTTP 500 errors, uncomment the LimitMEMLOCK=infinity and LimitNOFILE=65535 directives in the service file.

Windows

On Windows, Gogs can run as a native Windows service using either the builtin minwinsvc support or the third-party NSSM tool.
Gogs binaries built with the minwinsvc tag (release archive name that contains mws) support running as a native Windows service.

1. Configure Gogs for Windows

Edit C:\gogs\custom\conf\app.ini:
Replace COMPUTERNAME with the output of echo %COMPUTERNAME% in a command prompt. For example, if the computer name is USER-PC, set RUN_USER = USER-PC$.Configure the server section:
Using an address in the 127.x.x.x range (other than 127.0.0.1) prevents port conflicts with other local services while keeping traffic local. Any address from 127.0.0.2 to 127.254.254.254 works.

2. Add a hosts entry

Open Notepad as Administrator and edit C:\Windows\System32\drivers\etc\hosts:

3. Create and start the service

Open a command prompt as Administrator:
There must be a space after each = in the sc create command. This is a Windows sc.exe syntax requirement.
Start the service:
You should see:
Windows services run from %WINDIR%\System32 by default. Always use absolute paths in app.ini for data directories and database files:
Use forward slashes (/) in paths to avoid escape character issues.