start() {
echo "Starting Tracking_INOUT script..."
if [ -f "PID_FILE" ] && kill -0 (cat "$PID_FILE") 2>/dev/null; then
echo "Script already running."
return 1
fi
code
nohup /bin/sh -c "
while true; do
echo \"[$(date)] Starting script\" >> $LOG_FILE
$PYTHON $SCRIPT >> $LOG_FILE 2>&1
echo \"[$(date)] Script crashed. Restarting in 5 seconds...\" >> $LOG_FILE
sleep 5
done
" &
echo $! > "$PID_FILE"
echo "Script started with PID $(cat $PID_FILE)"
}
stop() {
echo "Stopping Tracking_INOUT script..."
if [ -f "PIDFILE"];thenkill(cat "PID_FILE") 2>/dev/null && echo "Stopped."
rm -f "PID_FILE"
else
echo "PID file not found. Is the script running?"
fi
}
status() {
if [ -f "PID_FILE" ] && kill -0 (cat "PIDFILE")2>/dev/null;thenecho"Running(PID(cat $PID_FILE))"
else
echo "Not running"
fi
}
case "1"instart)start;;stop)stop;;restart)stop;sleep1;start;;status)status;;∗)echo"Usage:0 {start|stop|restart|status}" ;;
esac
exit 0
Assistant
The script you provided is designed to run a Python script (Tracking_INOUT.py) on boot and restart it if it crashes. Here's how to ensure it works correctly:
Script Installation:
Save the script to /etc/init.d/tracking_inout.
Make it executable: chmod +x /etc/init.d/tracking_inout.
Add it to the default runlevels: update-rc.d tracking_inout defaults.
Start the service: /etc/init.d/tracking_inout start.
Script Improvements:
Added checks to ensure the Python script and interpreter exist.
Consider implementing log rotation to manage log file size.
Alternative for systemd:
If MaixiCAM uses systemd, create a systemd service file instead.
Here's the improved script with added checks:
sh
User
fYI, the os I'm using: Linux maixcam-51a1
Assistant
The script you provided is designed to run a Python script (Tracking_INOUT.py) on boot and restart it if it crashes. Here's how to ensure it works correctly:
Script Installation:
Save the script to /etc/init.d/tracking_inout.
Make it executable: chmod +x /etc/init.d/tracking_inout.
Add it to the default runlevels: update-rc.d tracking_inout defaults.
Start the service: /etc/init.d/tracking_inout start.
Script Improvements:
Added checks to ensure the Python script and interpreter exist.
Consider implementing log rotation to manage log file size.
Alternative for systemd:
If MaixiCAM uses systemd, create a systemd service file instead.