NeuroAgent

Why GitLab service not found after Ubuntu update

Fixing 'Unit gitlab.service not found' error after Ubuntu update. Step-by-step instructions to restore GitLab systemd service and alternative management methods.

Question

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?

NeuroAgent

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

The “Unit gitlab.service not found” error occurs due to several main reasons:

  1. Loss of service file: During a system update (apt upgrade), the GitLab service file in /etc/systemd/system/ may have been deleted or corrupted

  2. Version mismatch: GitLab is installed from the official repository, but the Ubuntu update may conflict with package versions

  3. Incorrect permissions: The service file may have lost the necessary execution permissions

  4. 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:

bash
# 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

bash
# 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:

bash
# 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

bash
# 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

bash
# 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

bash
# 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

bash
# 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

bash
# 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:

bash
# 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:

  1. Reinstalling GitLab with preserved configurations quickly restores the systemd service file
  2. Manually creating the service file ensures its presence in the correct location
  3. 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.

Sources

  1. Upgrading to GitLab 15.0 CE from GitLab 14.9.3 - DEV Community
  2. How To Install GitLab On Ubuntu - Easy Way - Itslinuxguide.com
  3. Upgrade Ubuntu LTS release on EC2 - Ubuntu on AWS documentation