Why can’t GitLab service be found after updating Ubuntu?
After updating the system (apt update & apt upgrade), when I try to restart the GitLab service with the command service gitlab restart, the terminal gives the error “Unit gitlab.service not found.”. However, GitLab itself is working fine. How can I solve this problem?
After updating Ubuntu, GitLab continues to work, but systemd cannot find the gitlab.service file as the GitLab package’s service configuration may have been deleted or corrupted during the update.
Table of Contents
- Main Causes of the Problem
- Checking GitLab Status
- Restoring the GitLab systemd Service
- Alternative Restart Methods
- Preventing Similar Issues in the Future
- Conclusion
Main Causes of the Problem
The “Unit gitlab.service not found” error occurs due to several main reasons:
-
Loss of service file: During a system update (
apt upgrade), the GitLab service file in/etc/systemd/system/may have been deleted or corrupted -
Version mismatch: GitLab is installed from the official repository, but the Ubuntu update may conflict with package versions
-
Incorrect permissions: The service file may have lost the necessary execution permissions
-
Missing service package: The package containing the GitLab systemd configuration may have been removed during the update
Checking GitLab Status
Before restoring the service, you need to check the current status of GitLab:
# Check if GitLab is running
sudo gitlab-ctl status
# Check if ports are listening
sudo netstat -tlnp | grep -E '80|443|8080|9090'
# Check availability via curl
curl http://localhost
If GitLab is running, the problem lies only with the systemd configuration, not with the application itself.
Restoring the GitLab systemd Service
Method 1: Reinstalling the GitLab package
# Update package list
sudo apt update
# Reinstall GitLab while preserving configurations
sudo apt reinstall gitlab-ce
Method 2: Manually creating the service file
If reinstallation doesn’t help, create the service file manually:
# Create the service file
sudo nano /etc/systemd/system/gitlab.service
# File content:
[Unit]
Description=GitLab server
After=network.target
[Service]
Type=simple
User=git
Group=git
WorkingDirectory=/var/opt/gitlab
ExecStart=/opt/gitlab/embedded/bin/gitlab-ctl start
ExecReload=/opt/gitlab/embedded/bin/gitlab-ctl restart
TimeoutStartSec=0
KillMode=process
Restart=always
RestartSec=30
[Install]
WantedBy=multi-user.target
Method 3: Using the official configuration script
# Reconfigure GitLab
sudo gitlab-ctl reconfigure
# Reload systemd
sudo systemctl daemon-reload
# Check if the service exists
systemctl status gitlab.service
Method 4: Checking and restoring paths
# Check if the service file exists in standard locations
find / -name "*gitlab*" -path "*/systemd/*" 2>/dev/null
# Check if the executable exists
ls -la /opt/gitlab/embedded/bin/gitlab-ctl
# If files are in place but the service is not visible
sudo systemctl daemon-reload
Alternative Restart Methods
If the systemd service still doesn’t work, use alternative methods to manage GitLab:
Using GitLab Omnibus
# Restart via GitLab Omnibus
sudo gitlab-ctl restart
# Stop and start
sudo gitlab-ctl stop
sudo gitlab-ctl start
# Check status
sudo gitlab-ctl status
Direct process management
# Find GitLab processes
ps aux | grep gitlab
# Kill and restart processes
sudo pkill -f gitlab
sudo gitlab-ctl restart
Preventing Similar Issues in the Future
Regular maintenance
# Always create a backup before system updates
sudo gitlab-backup create
# Update GitLab separately from the system
sudo apt update
sudo apt install gitlab-ce
# Check service integrity after updates
sudo gitlab-ctl status
systemctl is-active gitlab.service
Status monitoring
Add a check to cron:
# Edit crontab
sudo crontab -e
# Add the check
*/5 * * * * /usr/bin/systemctl is-active --quiet gitlab.service || /usr/bin/gitlab-ctl restart
Conclusion
The issue with the missing gitlab.service after an Ubuntu update is typically resolved through several methods:
- Reinstalling GitLab with preserved configurations quickly restores the systemd service file
- Manually creating the service file ensures its presence in the correct location
- Using GitLab Omnibus provides alternative management methods that don’t depend on systemd
To prevent similar issues in the future:
- Always back up GitLab before updates
- Update GitLab separately from system packages
- Regularly check service status after updates
- Set up monitoring for automatic service recovery
If GitLab continues to work but systemd doesn’t see the service, you can safely use direct management via gitlab-ctl until the systemd configuration is fully restored.