Introduction
Your Linux systemd service is not starting automatically when the system boots, despite being enabled. The service works fine when started manually with systemctl start, but doesn't come up after a reboot. This can affect web servers, databases, application services, custom daemons, or any systemd-managed service that needs to run at system startup.
The issue manifests as services showing as enabled but inactive after reboot, services starting in the wrong order, services failing due to missing dependencies, or services being skipped entirely during boot. This impacts system reliability, requires manual intervention after reboots, and can cause cascading failures for dependent services.
Symptoms
```bash # Service is enabled but not running after reboot $ systemctl status myservice ● myservice.service - My Application Service Loaded: loaded (/etc/systemd/system/myservice.service; enabled; vendor preset: enabled) Active: inactive (dead)
# Service failed during boot $ systemctl status myservice ● myservice.service - My Application Service Loaded: loaded (/etc/systemd/system/myservice.service; enabled; vendor preset: disabled) Active: failed (Result: dependency) Main PID: 1234 (code=exited, status=1/FAILURE)
# Boot logs show service failure $ journalctl -b | grep myservice Apr 08 18:00:15 server systemd[1]: Failed to start My Application Service. Apr 08 18:00:15 server systemd[1]: Dependency failed for My Application Service.
# Service shows as masked $ systemctl is-enabled myservice masked
# Service dependencies not met $ systemctl status myservice ● myservice.service - My Application Service Loaded: loaded (/etc/systemd/system/myservice.service; enabled) Active: inactive (dead) Condition: start condition failed at Mon 2026-04-08 18:00:00 UTC
# Common error messages Job for myservice.service failed because the service did not take the steps required by its unit configuration. Unit myservice.service cannot be started because it is masked. Dependency failed for myservice.service. Failed to start myservice.service: Unit not found. myservice.service: Unit not found. ```
Common Causes
- 1.Service not properly enabled: Using
enablewithout--nowflag, or the enable command didn't create proper symlinks in target directories. - 2.Incorrect service target: Service is configured to start in
multi-user.targetbut system boots tographical.target, or vice versa. WrongWantedBydirective. - 3.Missing dependencies: Service depends on network, database, or other services that aren't available yet when it tries to start. Missing
After=orRequires=directives. - 4.Service masked: The service has been masked (intentionally disabled) with
systemctl mask, preventing it from starting even if enabled. - 5.Failed preconditions: Service has
ConditionPathExists,ConditionFileIsExecutable, or other conditions that aren't met at boot time. - 6.Boot order issues: Service starts before required resources are available (network, filesystems, other services).
- 7.Incorrect service file location: Service file in wrong directory, or not recognized by systemd.
- 8.ExecStart path issues: The binary or script specified in
ExecStartdoesn't exist at boot, has wrong permissions, or isn't in the expected location. - 9.User/Group issues: Service configured to run as a user that doesn't exist yet, or home directory isn't available.
- 10.Environment variables missing: Service requires environment variables set in user profile that aren't available in systemd context.
Step-by-Step Fix
- 1.Check logs for specific error messages
- 2.Verify configuration settings
- 3.Test network connectivity
- 4.Review recent changes
- 5.Apply corrective action
- 6.Verify the fix
Step 1: Check Service Current Status
Diagnose why the service isn't starting:
```bash # Check if service is enabled systemctl is-enabled myservice
# Check service status systemctl status myservice
# Check if masked systemctl is-active myservice systemctl is-enabled myservice
# View service file systemctl cat myservice
# Check what target the service is in systemctl show myservice -p WantedBy
# Check dependencies systemctl list-dependencies myservice --before systemctl list-dependencies myservice --after
# Check if service started in current boot journalctl -b -u myservice
# Check for failed services after boot systemctl list-units --state=failed
# Check all enabled services systemctl list-unit-files --state=enabled | grep myservice
# Check where service symlinks are ls -la /etc/systemd/system/multi-user.target.wants/ | grep myservice ls -la /etc/systemd/system/default.target.wants/ | grep myservice
# Check if there are dependency cycles systemd-analyze verify /etc/systemd/system/myservice.service
# Analyze boot sequence systemd-analyze blame | head -20 systemd-analyze critical-chain myservice
# Check default target systemctl get-default ```
Step 2: Properly Enable the Service
Ensure the service is correctly enabled:
```bash # Enable service to start on boot sudo systemctl enable myservice
# Enable and start immediately sudo systemctl enable --now myservice
# Check symlinks were created ls -la /etc/systemd/system/multi-user.target.wants/myservice.service # or ls -la /etc/systemd/system/default.target.wants/myservice.service
# Reload systemd daemon sudo systemctl daemon-reload
# Verify enable status systemctl is-enabled myservice
# If service was previously disabled sudo systemctl reenable myservice
# Reset failed state if needed sudo systemctl reset-failed myservice
# If service is masked, unmask it sudo systemctl unmask myservice
# Then enable sudo systemctl enable myservice ```
Create a properly configured service file:
# Create or edit service file
sudo nano /etc/systemd/system/myservice.service```ini [Unit] Description=My Application Service Documentation=https://example.com/docs After=network.target network-online.target Wants=network-online.target # Add dependencies if needed Requires=postgresql.service After=postgresql.service
[Service] Type=simple User=myuser Group=mygroup WorkingDirectory=/opt/myapp Environment="PATH=/usr/local/bin:/usr/bin:/bin" Environment="NODE_ENV=production" EnvironmentFile=/etc/myapp/environment
# Main command ExecStart=/usr/bin/node /opt/myapp/app.js # Or for Python # ExecStart=/usr/bin/python3 /opt/myapp/main.py # Or for a shell script # ExecStart=/opt/myapp/start.sh
# Restart configuration Restart=on-failure RestartSec=5s
# Security settings NoNewPrivileges=true PrivateTmp=true
# Logging StandardOutput=journal StandardError=journal SyslogIdentifier=myservice
# Resource limits LimitNOFILE=65536 TimeoutStartSec=300 TimeoutStopSec=30
[Install] WantedBy=multi-user.target ```
After creating/editing:
```bash # Reload systemd sudo systemctl daemon-reload
# Enable the service sudo systemctl enable myservice
# Start it sudo systemctl start myservice
# Check status systemctl status myservice
# Verify it's enabled for boot systemctl is-enabled myservice ```
Step 3: Configure Proper Dependencies
Ensure correct boot order with dependencies:
```ini [Unit] Description=My Web Application
# Start after network is ready After=network.target network-online.target Wants=network-online.target
# If service needs DNS resolution After=nss-lookup.target
# If service needs database Requires=postgresql.service After=postgresql.service
# If service needs Redis Wants=redis.service After=redis.service
# If service needs filesystem mount RequiresMountsFor=/data After=local-fs.target
# If service needs another local service Requires=another-service.service After=another-service.service
[Service] Type=simple ExecStart=/usr/bin/myapp Restart=always
[Install] WantedBy=multi-user.target ```
Check network availability:
```bash # Check if network-online.target exists systemctl list-units --type=target | grep network
# For services needing network, ensure network-online.target is available systemctl status network-online.target
# If using NetworkManager systemctl status NetworkManager-wait-online.service
# If using systemd-networkd systemctl status systemd-networkd-wait-online.service
# Check what services provide network-online.target systemctl show -p WantedBy network-online.target ```
Conditional dependencies:
```ini [Unit] Description=My Service
# Start after these if they exist After=network.target network-online.target
# Require these (fail if missing) Requires=network.target
# Want these but don't fail if missing Wants=network-online.target
# Bind to another service (stop when it stops) BindsTo=database.service
# Part of another service (restart when it restarts) PartOf=parent.service ```
Step 4: Fix Service Type and ExecStart
Ensure correct service type configuration:
```ini [Service] # Type=simple (default) - service runs in foreground # Use when ExecStart process is the main process Type=simple ExecStart=/usr/bin/node /app/server.js
# Type=forking - service forks and parent exits # Use for traditional daemon behavior Type=forking ExecStart=/usr/sbin/apache2 start PIDFile=/run/apache2/apache2.pid
# Type=oneshot - service runs once and exits # Use for setup scripts, backups Type=oneshot ExecStart=/opt/scripts/setup.sh RemainAfterExit=yes
# Type=notify - service notifies systemd when ready # Use when service supports sd_notify Type=notify ExecStart=/usr/bin/myapp --notify
# Type=idle - delay until all jobs are dispatched Type=idle ExecStart=/usr/bin/myapp
# For services with multiple commands Type=oneshot ExecStart=/opt/scripts/start.sh ExecStop=/opt/scripts/stop.sh RemainAfterExit=yes
# Or use ExecStartPre for preparation Type=simple ExecStartPre=/opt/scripts/prepare.sh ExecStart=/usr/bin/myapp ExecStartPost=/opt/scripts/notify.sh ```
Fix ExecStart issues:
```bash # Check if binary/script exists ls -la /usr/bin/myapp ls -la /opt/myapp/start.sh
# Check permissions chmod +x /opt/myapp/start.sh
# Check shebang head -1 /opt/myapp/start.sh # Should be #!/bin/bash or similar
# Check if path is correct which node which python3
# Test command manually /usr/bin/node /opt/myapp/app.js
# Check if user can execute su - myuser -c "/usr/bin/node /opt/myapp/app.js"
# If using script, ensure it's executable sudo chmod 755 /opt/myapp/start.sh
# Test the exact ExecStart command sudo -u myuser /opt/myapp/start.sh ```
Step 5: Handle Environment Variables
Ensure environment is available at boot:
```ini [Service] # Set environment directly Environment="NODE_ENV=production" Environment="DATABASE_URL=postgresql://localhost/mydb" Environment="PATH=/usr/local/bin:/usr/bin:/bin"
# Load from file EnvironmentFile=/etc/myapp/config.env EnvironmentFile=-/etc/myapp/optional.env # - prefix means ignore if missing
# Set working directory WorkingDirectory=/opt/myapp
# Set user and group User=myuser Group=mygroup
# Home directory for user Home=/home/myuser ```
Create environment file:
# Create environment file
sudo mkdir -p /etc/myapp
sudo nano /etc/myapp/config.env# /etc/myapp/config.env
NODE_ENV=production
DATABASE_URL=postgresql://user:pass@localhost/mydb
REDIS_URL=redis://localhost:6379
LOG_LEVEL=info
PORT=3000# Set permissions
sudo chmod 600 /etc/myapp/config.env
sudo chown myuser:mygroup /etc/myapp/config.envCommon environment issues:
```bash # Check user environment su - myuser -c 'echo $PATH' su - myuser -c 'env'
# If using Node.js, ensure node is in PATH which node # Add to service file: # Environment="PATH=/usr/bin:/usr/local/bin"
# If using pyenv/nvm # Source in ExecStart: # ExecStart=/bin/bash -c 'source /home/user/.nvm/nvm.sh && node /app/server.js'
# Or set full path to binary # ExecStart=/home/user/.nvm/versions/node/v18/bin/node /app/server.js
# Check if environment file is loaded systemctl show myservice -p Environment ```
Step 6: Fix User and Permission Issues
Ensure user and permissions are correct:
```bash # Check if user exists id myuser
# Create user if needed sudo useradd -r -s /bin/false myuser
# Create user with home directory sudo useradd -r -m -d /opt/myapp myuser
# Check group getent group mygroup
# Create group if needed sudo groupadd mygroup
# Add user to group sudo usermod -aG mygroup myuser
# Check home directory ls -la /home/myuser ls -la /opt/myapp
# Ensure user owns files sudo chown -R myuser:mygroup /opt/myapp
# Check user can read files sudo -u myuser ls -la /opt/myapp
# Check user can execute binary sudo -u myuser test -x /usr/bin/node && echo "Executable"
# Check user can write to log directory sudo -u myuser touch /var/log/myapp/test.log
# Create necessary directories sudo mkdir -p /var/log/myapp sudo mkdir -p /run/myapp sudo mkdir -p /var/lib/myapp
# Set ownership sudo chown myuser:mygroup /var/log/myapp sudo chown myuser:mygroup /run/myapp sudo chown myuser:mygroup /var/lib/myapp
# For PID files, use RuntimeDirectory # In service file: # RuntimeDirectory=myapp # This creates /run/myapp with correct permissions ```
Service file with user configuration:
```ini [Service] User=myuser Group=mygroup
# Creates /run/myapp with correct permissions RuntimeDirectory=myapp RuntimeDirectoryMode=0755
# Working directory WorkingDirectory=/opt/myapp
# Home for user Home=/opt/myapp
# Read-only paths ReadOnlyPaths=/etc/myapp ReadWritePaths=/var/log/myapp /var/lib/myapp
# Protect system ProtectSystem=strict ProtectHome=true NoNewPrivileges=true ```
Step 7: Debug Boot-Time Service Failures
Investigate why service fails at boot:
```bash # Check boot logs journalctl -b -u myservice
# Check previous boot if service failed journalctl -b -1 -u myservice
# Check system boot log journalctl -b | grep -A5 -B5 myservice
# Enable debug logging for systemd sudo systemctl edit --full systemd-journald # Add: LogLevel=debug
# Restart journald sudo systemctl restart systemd-journald
# Check service in detail systemd-analyze verify /etc/systemd/system/myservice.service
# Run service in debug mode sudo systemctl stop myservice sudo /usr/bin/myapp --debug # Or whatever debug flag
# Check for SELinux/AppArmor denials sudo ausearch -m avc -ts recent | grep myservice sudo dmesg | grep -i denied | grep myservice
# For SELinux sudo semanage fcontext -a -t bin_t "/opt/myapp(/.*)?" sudo restorecon -Rv /opt/myapp
# For AppArmor sudo aa-status sudo journalctl -k | grep myservice
# Check for dependency issues systemctl list-dependencies myservice --all --plain
# What started myservice systemctl show myservice -p TriggeredBy
# What myservice triggers systemctl show myservice -p Triggers ```
Simulate boot-time start:
```bash # Stop the service sudo systemctl stop myservice
# Simulate clean boot environment # Unset all environment variables sudo -E systemctl start myservice
# Or use systemd-run to simulate sudo systemd-run --unit=test-myservice --scope /usr/bin/myapp
# Check if it starts systemctl status test-myservice
# Check what's different systemctl show myservice -p Environment ```
Step 8: Fix Common Boot Scenarios
Handle specific boot scenarios:
```bash # Service needs to start after network is truly online
# Check network wait service systemctl status systemd-networkd-wait-online.service # or systemctl status NetworkManager-wait-online.service
# Configure service ```
```ini [Unit] Description=My Web Service After=network-online.target Wants=network-online.target
[Service] Type=simple ExecStart=/usr/bin/myapp Restart=on-failure
[Install] WantedBy=multi-user.target ```
```bash # Service needs specific mount
# Check mount status findmnt /data systemctl list-units --type=mount
# Configure service ```
```ini [Unit] Description=My Data Service RequiresMountsFor=/data After=local-fs.target
[Service] Type=simple ExecStart=/usr/bin/myapp --data /data ```
```bash # Service runs in container or chroot
# Check container/network namespace ip netns list
# For services in containers ```
```ini [Unit] Description=Container Service
[Service] Type=simple ExecStart=/usr/bin/docker run --name mycontainer myimage ExecStop=/usr/bin/docker stop mycontainer ExecStopPost=/usr/bin/docker rm mycontainer ```
Step 9: Test Service Boot Behavior
Verify service starts correctly on boot:
```bash # Test service start sudo systemctl start myservice systemctl status myservice
# Check if it auto-restarts sudo systemctl kill myservice sleep 5 systemctl status myservice
# Simulate boot (systemd) sudo systemctl isolate multi-user.target
# Check what target system boots to systemctl get-default
# If booting to graphical.target, ensure service is in right target sudo systemctl set-default multi-user.target # or sudo systemctl set-default graphical.target
# Enable for specific target sudo systemctl enable myservice --now
# Check target relationships systemctl list-dependencies multi-user.target --type=service systemctl list-dependencies graphical.target --type=service
# Test reboot (schedule maintenance first!) sudo reboot
# After reboot, check systemctl status myservice journalctl -b -u myservice ```
Create verification script:
```bash #!/bin/bash # verify_service_boot.sh
SERVICE=${1:-"myservice"}
echo "=== Service Boot Verification ===" echo "Service: $SERVICE" echo ""
echo "1. Service Status" systemctl status $SERVICE --no-pager echo ""
echo "2. Is Enabled" systemctl is-enabled $SERVICE echo ""
echo "3. Service File" systemctl cat $SERVICE echo ""
echo "4. Dependencies" systemctl list-dependencies $SERVICE --before --no-pager echo ""
echo "5. Boot Logs" journalctl -b -u $SERVICE --no-pager | tail -20 echo ""
echo "6. Symlink Check" ls -la /etc/systemd/system/multi-user.target.wants/$SERVICE.service 2>/dev/null || \ ls -la /etc/systemd/system/default.target.wants/$SERVICE.service 2>/dev/null || \ echo "No symlink found!" echo ""
echo "7. Default Target" systemctl get-default echo ""
echo "8. Verification" if systemctl is-enabled $SERVICE | grep -q "enabled"; then echo "✓ Service is enabled" else echo "✗ Service is NOT enabled" fi
if systemctl is-active $SERVICE | grep -q "active"; then echo "✓ Service is running" else echo "✗ Service is NOT running" fi ```
Step 10: Monitor and Alert on Service Failures
Set up monitoring for boot failures:
# Create a service that checks other services
sudo nano /etc/systemd/system/service-health-check.service```ini [Unit] Description=Service Health Check After=network.target multi-user.target
[Service] Type=oneshot ExecStart=/opt/scripts/check-services.sh RemainAfterExit=yes
[Install] WantedBy=multi-user.target ```
# Create check script
sudo mkdir -p /opt/scripts
sudo nano /opt/scripts/check-services.sh```bash #!/bin/bash # /opt/scripts/check-services.sh
SERVICES=("nginx" "postgresql" "redis" "myservice") ALERT_WEBHOOK="https://hooks.slack.com/services/YOUR/WEBHOOK"
for service in "${SERVICES[@]}"; do if ! systemctl is-active --quiet $service; then message="⚠️ Service $service is not running after boot on $(hostname)" curl -s -X POST -H 'Content-type: application/json' \ --data "{\"text\":\"$message\"}" \ $ALERT_WEBHOOK
# Try to start the service systemctl start $service fi done ```
sudo chmod +x /opt/scripts/check-services.sh
sudo systemctl enable service-health-check.servicePrevention
| Step | Action | Verified |
|---|---|---|
| 1 | Checked service current status | ☐ |
| 2 | Properly enabled the service | ☐ |
| 3 | Configured proper dependencies | ☐ |
| 4 | Fixed service type and ExecStart | ☐ |
| 5 | Handled environment variables | ☐ |
| 6 | Fixed user and permission issues | ☐ |
| 7 | Debugged boot-time failures | ☐ |
| 8 | Fixed common boot scenarios | ☐ |
| 9 | Tested service boot behavior | ☐ |
| 10 | Set up monitoring and alerts | ☐ |
Verification
- 1.Check service is enabled:
- 2.```bash
- 3.systemctl is-enabled myservice
- 4.# Should show "enabled"
- 5.
` - 6.Check symlink exists:
- 7.```bash
- 8.ls -la /etc/systemd/system/multi-user.target.wants/myservice.service
- 9.
` - 10.Test start:
- 11.```bash
- 12.sudo systemctl start myservice
- 13.systemctl status myservice
- 14.
` - 15.Check boot logs:
- 16.```bash
- 17.journalctl -b -u myservice
- 18.
` - 19.Test reboot:
- 20.```bash
- 21.sudo reboot
- 22.# After reboot
- 23.systemctl status myservice
- 24.
`
Related Issues
- [Fix Systemd Service Failed to Start](/articles/fix-systemd-service-failed-to-start)
- [Fix Linux Service Dependency Failed](/articles/fix-linux-service-dependency-failed)
- [Fix Systemd Unit Not Found](/articles/fix-systemd-unit-not-found)
- [Fix Linux Service Permission Denied](/articles/fix-linux-service-permission-denied)
- [Fix Nginx Failed to Start on Boot](/articles/fix-nginx-failed-to-start-on-boot)
Related Articles
- [Fix Debug Not Hitting Breakpoint Typescript Vscode Issue in Systems](debug-not-hitting-breakpoint-typescript-vscode)
- [Fix Docker Extension Container Empty Vscode Issue in Systems](docker-extension-container-empty-vscode)
- [Fix Extension Host Crashed Memory Limit Vscode Issue in Systems](extension-host-crashed-memory-limit-vscode)
- [Fix File Watcher Enospc Limit Linux Vscode Issue in Systems](file-watcher-enospc-limit-linux-vscode)
- [Fix Android Emulator Not Starting](fix-android-emulator-not-starting)
<script type="application/ld+json"> { "@context": "https://schema.org", "@type": "TechArticle", "headline": "Fix Linux Systemd Service Failed to Start Automatically", "description": "Learn how to fix systemd service not starting automatically on boot. Includes service configuration, dependencies, target management, and diagnostic tools.", "url": "https://www.fixwikihub.com/fix-systemd-service-failed-start-automatically", "publisher": { "@type": "Organization", "name": "FixWikiHub", "url": "https://www.fixwikihub.com" }, "author": { "@type": "Person", "name": "FixWikiHub Editorial Team" }, "datePublished": "2025-12-12T22:51:39.933Z", "dateModified": "2025-12-12T22:51:39.933Z" } </script>