Files
api/plugin/source/dynamix.unraid.net/etc/rc.d/rc.unraid-api
T
Pujit Mehrotra 184b76de1c chore: include node_modules in api slackware package (#1415)
instead of vendoring & uploading separately.

## Summary by CodeRabbit

- **Chores**
- Updated build process to retain the `node_modules` directory, removing
compression and archiving steps.
- Improved plugin installation by cleaning up outdated dependency
archives before reinstalling, enhancing system stability.
- Removed vendor store file references and related bundling steps from
the plugin build and installation process.
- Enhanced dependency restoration during service start to log warnings
without aborting on failure.
- Simplified dependency management scripts by removing vendor store URL
handling and download functionality.
- Streamlined build workflows by removing artifact upload/download and
validation steps related to node modules archives.
- Updated Docker Compose configuration to remove unused volume mounts
for node modules archives.
- Added repository cleanup commands to remove top-level `node_modules`
directories and common build artifact folders for easier maintenance.
2025-06-11 12:07:32 -04:00

156 lines
3.6 KiB
Bash
Executable File

#!/bin/bash
# unraid-api-handler
# shellcheck source=/dev/null
source /etc/profile
flash="/boot/config/plugins/dynamix.my.servers"
[[ ! -d "${flash}" ]] && echo "Please reinstall the Unraid Connect plugin" && exit 1
[[ ! -f "${flash}/env" ]] && echo 'env=production' >"${flash}/env"
unraid_binary_path="/usr/local/bin/unraid-api"
api_base_dir="/usr/local/unraid-api"
scripts_dir="/usr/local/share/dynamix.unraid.net/scripts"
# Ensure script permissions
if [ -d "$scripts_dir" ]; then
chmod +x "$scripts_dir"/*.sh 2>/dev/null
fi
# Placeholder functions for plugin installation/uninstallation
install() {
true
}
uninstall() {
true
}
# Service control functions
start() {
echo "Starting Unraid API service..."
# Restore vendored API plugins if they were installed
if [ -x "$scripts_dir/dependencies.sh" ]; then
"$scripts_dir/dependencies.sh" restore || {
echo "Failed to restore API plugin dependencies! Continuing with start, but API plugins may be unavailable."
}
else
echo "Warning: dependencies.sh script not found or not executable"
fi
# Create log directory if it doesn't exist
mkdir -p /var/log/unraid-api
# Copy env file if needed
if [ -f "${api_base_dir}/.env.production" ] && [ ! -f "${api_base_dir}/.env" ]; then
cp "${api_base_dir}/.env.production" "${api_base_dir}/.env"
fi
# Start the flash backup service if available
if [ -x "/etc/rc.d/rc.flash_backup" ]; then
echo "Starting flash backup service..."
/etc/rc.d/rc.flash_backup start
fi
# Start the API service
if [ -x "${unraid_binary_path}" ]; then
"${unraid_binary_path}" start
return $?
else
echo "Error: Unraid API binary not found or not executable at ${unraid_binary_path}"
return 1
fi
}
stop() {
echo "Stopping Unraid API service..."
if [ -x "${unraid_binary_path}" ]; then
"${unraid_binary_path}" stop
return $?
else
echo "Error: Unraid API binary not found or not executable at ${unraid_binary_path}"
return 1
fi
}
restart() {
stop
sleep 2
start
}
status() {
if [ -x "${unraid_binary_path}" ]; then
"${unraid_binary_path}" status
return $?
else
echo "Error: Unraid API binary not found or not executable at ${unraid_binary_path}"
return 1
fi
}
case "$1" in
'start')
start
;;
'stop')
stop
;;
'restart'|'reload')
restart
;;
'status')
status
;;
'install')
install "$2"
;;
'uninstall')
uninstall
;;
'ensure')
if [ -x "$scripts_dir/dependencies.sh" ]; then
# First clean up old dependencies
"$scripts_dir/dependencies.sh" cleanup
# Then ensure new dependencies are installed
"$scripts_dir/dependencies.sh" ensure "$2"
else
echo "Error: dependencies.sh script not found or not executable"
exit 1
fi
;;
'cleanup-dependencies')
if [ -x "$scripts_dir/dependencies.sh" ]; then
"$scripts_dir/dependencies.sh" cleanup
else
echo "Error: dependencies.sh script not found or not executable"
exit 1
fi
;;
'archive-dependencies')
if [ -x "$scripts_dir/dependencies.sh" ]; then
"$scripts_dir/dependencies.sh" archive
else
echo "Error: dependencies.sh script not found or not executable"
exit 1
fi
;;
'redownload-vendor-archive')
if [ -x "$scripts_dir/dependencies.sh" ]; then
if [ -n "$2" ] && [ -n "$3" ]; then
"$scripts_dir/dependencies.sh" redownload "$2" "$3"
else
echo "Usage: $0 redownload-vendor-archive <archive_path> <version>"
exit 1
fi
else
echo "Error: dependencies.sh script not found or not executable"
exit 1
fi
;;
*)
# Pass all other commands to unraid-api
"${unraid_binary_path}" "$@"
;;
esac