2017-11-26 16:44:32 -05:00
---
date : "2016-12-21T15:00:00-02:00"
slug : "windows-service"
2023-07-25 21:00:14 -05:00
sidebar_position : 50
2023-04-27 22:33:41 -05:00
aliases :
- /en-us/windows-service
2017-11-26 16:44:32 -05:00
---
2024-08-06 16:44:42 -07:00
# Register as a Windows Service
## Prerequisites
2019-01-16 21:43:26 +07:00
The following changes are made in C:\gitea\custom\conf\app.ini:
2024-06-06 22:49:46 +08:00
```ini title="app.ini"
2019-01-16 21:43:26 +07:00
RUN_USER = COMPUTERNAME$
` ``
Sets Gitea to run as the local system user.
COMPUTERNAME is whatever the response is from ` echo %COMPUTERNAME%` on the command line. If the response is ` USER-PC` then ` RUN_USER = USER-PC$`
2024-08-06 16:44:42 -07:00
### Use absolute paths
2019-01-16 21:43:26 +07:00
2021-12-24 04:56:57 +01:00
If you use SQLite3, change the ` PATH` to include the full path:
2019-01-16 21:43:26 +07:00
2024-06-06 22:49:46 +08:00
` ``ini title="app.ini"
2019-01-16 21:43:26 +07:00
[database]
PATH = c:/gitea/data/gitea.db
` ``
2024-08-06 16:44:42 -07:00
## Register as a Windows Service
2017-11-26 16:44:32 -05:00
2018-01-08 16:48:42 -06:00
To register Gitea as a Windows service, open a command prompt (cmd) as an Administrator,
then run the following command:
2017-11-26 16:44:32 -05:00
2024-06-06 22:49:46 +08:00
` ``sh
2019-12-13 00:13:38 -05:00
sc.exe create gitea start= auto binPath= "\"C:\gitea\gitea.exe\" web --config \"C:\gitea\custom\conf\app.ini\""
2017-11-26 16:44:32 -05:00
` ``
2018-01-08 16:48:42 -06:00
Do not forget to replace ` C:\gitea` with the correct Gitea directory.
2017-11-26 16:44:32 -05:00
2018-01-08 16:48:42 -06:00
Open "Windows Services", search for the service named "gitea", right-click it and click on
2019-03-09 16:15:45 -05:00
"Run". If everything is OK, Gitea will be reachable on ` http://localhost:3000` (or the port
2018-01-08 16:48:42 -06:00
that was configured).
2017-11-26 16:44:32 -05:00
2024-08-06 16:44:42 -07:00
### Adding startup dependencies
2022-08-28 16:28:42 +01:00
2022-09-07 14:40:36 -04:00
To add a startup dependency to the Gitea Windows service (eg Mysql, Mariadb), as an Administrator, then run the following command:
2022-08-28 16:28:42 +01:00
2024-06-06 22:49:46 +08:00
` ``sh
2022-08-28 16:28:42 +01:00
sc.exe config gitea depend= mariadb
` ``
This will ensure that when the Windows machine restarts, the automatic starting of Gitea is postponed until the database is ready and thus mitigate failed startups.
2024-08-06 16:44:42 -07:00
### Unregister as a service
2017-11-26 16:44:32 -05:00
2018-01-08 16:48:42 -06:00
To unregister Gitea as a service, open a command prompt (cmd) as an Administrator and run:
2017-11-26 16:44:32 -05:00
2024-06-06 22:49:46 +08:00
` ``sh
2019-12-13 00:13:38 -05:00
sc.exe delete gitea
2017-11-26 16:44:32 -05:00
` ``