restart.sh
Overview
restart.sh is a lightweight shell script designed to restart a service or application managed by the InfiniFlow project. It achieves this by sequentially invoking two other scripts: stop.sh and start.sh, which are responsible for stopping and starting the service respectively.
This script is typically used in deployment, maintenance, or development workflows to quickly restart the service with a clean state, ensuring that any running instances are properly terminated before launching new ones.
Detailed Explanation
Script Breakdown
#!/bin/bash
#
# License and copyright header
#
set -e
bash "$(dirname "$0")/stop.sh"
bash "$(dirname "$0")/start.sh"
Shebang Line (
#!/bin/bash)
Specifies that the script should be executed in the Bash shell environment.set -e
This Bash option causes the script to immediately exit if any command within it returns a non-zero exit status (i.e., an error). This is important for ensuring that if stopping the service fails, the script does not proceed to start it again, preventing potential conflicts or inconsistent states.bash "$(dirname "$0")/stop.sh"
Runs thestop.shscript located in the same directory asrestart.sh, stopping the running service.bash "$(dirname "$0")/start.sh"
Runs thestart.shscript located in the same directory, starting the service after it has been stopped.
Parameters
This script does not accept any parameters or command-line arguments.
Return Values
The script returns an exit status of
0on successful execution of bothstop.shandstart.sh.If either
stop.shorstart.shfails (returns a non-zero exit status), the script immediately exits with that error code.
Usage Example
To restart the service, navigate to the directory containing restart.sh and run:
./restart.sh
Or, if the script is not executable, run it via bash:
bash restart.sh
Important Implementation Details
The use of
set -eensures that failures in stopping or starting the service cause the script to terminate early, which is a best practice for scripts managing critical service lifecycle actions.The script uses
dirname "$0"to dynamically determine the directory whererestart.shresides, enabling it to reliably locatestop.shandstart.sheven if the script is invoked from a different working directory.This modular approach (delegating stop and start operations to separate scripts) promotes separation of concerns, easier maintenance, and reusability of the stop and start scripts independently.
Interaction with Other System Components
stop.sh: This script is expected to gracefully stop the running service or application. Its implementation details (e.g., stopping systemd services, killing processes, cleaning up resources) are abstracted away fromrestart.sh.start.sh: This script is responsible for starting the service or application. It may involve launching binaries, setting environment variables, or initializing dependencies.
Together, these three scripts form a small service lifecycle management toolkit within the InfiniFlow project. restart.sh acts as the orchestrator for restarting, relying on the capabilities provided by stop.sh and start.sh.
Diagram: Workflow of restart.sh
flowchart TD
A[Start: Execute restart.sh] --> B[Invoke stop.sh]
B -->|Success| C[Invoke start.sh]
B -->|Failure| D[Exit with error]
C -->|Success| E[Exit successfully]
C -->|Failure| D
Explanation:
The script begins by running
stop.sh.If stopping succeeds, it proceeds to run
start.sh.If either step fails, the script exits immediately with an error code, preventing partial restarts.
Summary
Purpose: Restart the service by stopping it then starting it again.
Functionality: Executes
stop.shandstart.shsequentially with error checking.Key Features:
Immediate exit on failure (
set -e)Dynamic script path resolution
Simple, modular orchestration of service lifecycle
Interaction: Acts as a controller script using
stop.shandstart.shscripts.Usage: Run to restart the InfiniFlow service safely and reliably.
This script is an essential utility in the InfiniFlow deployment and management workflow, ensuring clean restarts of services with minimal user intervention.