Run as service
Run as service
Configure Gogs to start automatically as a system service on Linux, macOS, and Windows
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:
sudo cp /home/git/gogs/scripts/systemd/gogs.service /etc/systemd/system/gogs.service
sudo vim /etc/systemd/system/gogs.serviceHere is the default service file for reference:
[Unit]
Description=Gogs
After=network.target
After=mariadb.service mysql.service mysqld.service postgresql.service memcached.service redis.service
[Service]
# Uncomment the following if you have repos with lots of files
# and get an HTTP 500 error because of that
#LimitMEMLOCK=infinity
#LimitNOFILE=65535
Type=simple
User=git
Group=git
WorkingDirectory=/home/git/gogs
ExecStart=/home/git/gogs/gogs web
Restart=always
RestartSec=2s
Environment=USER=git HOME=/home/git
# Hardening directives (comment out if not supported by your systemd version)
ProtectSystem=full
PrivateDevices=yes
PrivateTmp=yes
NoNewPrivileges=true
[Install]
WantedBy=multi-user.targetUpdate the following values to match your environment:
UserandGroup-- the system user running GogsWorkingDirectory-- the Gogs installation directoryExecStart-- the full path to the Gogs binaryEnvironment-- ensureUSERandHOMEmatch 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
sudo systemctl enable gogs
sudo systemctl start gogs3. Verify the service
# Check status
sudo systemctl status gogs -l
# View logs
sudo journalctl -b -u gogsIf 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:
RUN_USER = COMPUTERNAME$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:
[server]
DOMAIN = gogs
PROTOCOL = http
HTTP_ADDR = 127.0.1.1
HTTP_PORT = 80
OFFLINE_MODE = true
EXTERNAL_URL = http://gogs/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:
# Gogs local HTTPd
127.0.1.1 gogs3. Create and start the service
Open a command prompt as Administrator:
sc create gogs start= auto binPath= "\"C:\gogs\gogs.exe\" web --config \"C:\gogs\custom\conf\app.ini\""There must be a space after each = in the sc create command. This is a Windows sc.exe syntax requirement.
Start the service:
net start gogsYou should see:
The gogs service is starting.
The gogs service was started successfully.Windows services run from %WINDIR%\System32 by default. Always use absolute paths in app.ini for data directories and database files:
[server]
APP_DATA_PATH = c:/gogs/data
[database]
PATH = c:/gogs/data/gogs.dbUse forward slashes (/) in paths to avoid escape character issues.
评论
登录后参与评论
InfoSphere