You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

systemd任务启动失败提示“无此文件或目录”,Airflow自启动脚本求助

Troubleshooting "No such file or Directory" Error for Airflow Systemd Startup Script

Let's walk through why your systemd service is throwing that "No such file or Directory" error and fix it step by step—this is a common pitfall when setting up custom startup scripts with systemd.

1. Fix Path Issues in Your Script

Systemd runs in a minimal environment, so shortcuts like ~ won’t resolve to your user’s home directory, and it might not have the same PATH as your regular shell session. Here’s what to adjust:

  • Replace ~/airflow with the absolute path to your Airflow home (e.g., /home/ubuntu/airflow).
  • Use the full path for the airflow command (run which airflow to find it—likely /usr/local/bin/airflow).
  • Double-check that /home/ubuntu/Source/Bash/airflow-start-webserver.sh exists and uses absolute paths internally too.
  • Remove gnome-terminal entirely: Systemd doesn’t have access to a graphical session at boot, so launching a terminal will fail. Instead, run your webserver script directly in the background (add & at the end).

Here’s a revised version of your script with these fixes:

#!/bin/bash
set -x  # Enable debug output to track exactly where things fail
echo "Starting postgres service"
export AIRFLOW_HOME=/home/ubuntu/airflow
sudo service postgresql start
echo "Sleeping to let postgres initialize"
sleep 15
echo "Initializing Airflow database"
/usr/local/bin/airflow initdb
echo "Sleeping to let database setup complete"
sleep 15
# Run webserver script in the background instead of using gnome-terminal
/home/ubuntu/Source/Bash/airflow-start-webserver.sh &

2. Verify Script Permissions and Ownership

Make sure your script is executable and accessible to the user running the systemd service:

  • Add execute permissions:
    chmod +x /usr/local/bin/airflow-start-all.sh
    
  • If your systemd service runs as a specific user (e.g., ubuntu), ensure the script is owned by that user or has world-readable/execute permissions:
    chown ubuntu:ubuntu /usr/local/bin/airflow-start-all.sh
    

3. Fix Your Systemd Service File

Most of the time, the error comes from a misconfigured service file. Here’s a working example (save as /etc/systemd/system/airflow.service):

[Unit]
Description=Airflow Startup Service
After=postgresql.target network.target  # Wait for postgres and network to be ready

[Service]
User=ubuntu
Group=ubuntu
ExecStart=/usr/local/bin/airflow-start-all.sh  # Use the FULL path to your script
WorkingDirectory=/home/ubuntu  # Set working directory to your user's home
Restart=on-failure  # Restart if the service crashes

[Install]
WantedBy=multi-user.target

4. Debug with Systemd Logs

To pinpoint exactly which file/directory is missing, check the systemd logs in real-time:

sudo journalctl -u airflow.service -f

This will show you every step the service tries to run, so you can see which command triggers the "No such file or Directory" error.

Final Steps to Apply Changes

After making adjustments:

  1. Reload systemd to pick up the new service file:
    sudo systemctl daemon-reload
    
  2. Start the service and check its status:
    sudo systemctl start airflow.service
    sudo systemctl status airflow.service
    
  3. If you want it to start on boot:
    sudo systemctl enable airflow.service
    

内容的提问来源于stack exchange,提问作者mitroberts

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 10:12:45