Understanding the Error
Failed to start servicename.service: Unit servicename.service not found.
Fix 1: Check Correct Service Name
# List all services
systemctl list-units --type=service
systemctl list-unit-files | grep -i keyword
# Common name variations
mysql vs mysqld vs mariadb
apache2 vs httpd
nginx vs nginx
php8.1-fpm vs php-fpm
Fix 2: Service Not Installed
# Check if package is installed
dpkg -l | grep keyword # Debian/Ubuntu
rpm -qa | grep keyword # CentOS/RHEL
# Install missing service
sudo apt install packagename -y
sudo yum install packagename -y
Fix 3: Service Disabled or Masked
# Check if masked
systemctl is-enabled servicename
# Unmask if needed
sudo systemctl unmask servicename
Fix 4: Custom Service Not in System Path
# Create service file manually
sudo nano /etc/systemd/system/myservice.service
# Example content:
[Unit]
Description=My Custom Service
After=network.target
[Service]
ExecStart=/path/to/your/script
Restart=always
User=username
[Install]
WantedBy=multi-user.target
# Reload and enable
sudo systemctl daemon-reload
sudo systemctl enable myservice --now
Fix 5: Use SysV Init Instead
Some older services use /etc/init.d/:
# Check
ls /etc/init.d/ | grep keyword
# Start with
sudo /etc/init.d/servicename start