mirror of
https://github.com/AlexMacocian/ServerManagementUtils.git
synced 2026-07-15 15:19:58 +00:00
Fix setup-crontab
This commit is contained in:
@@ -120,9 +120,12 @@ EOF
|
||||
if [[ "$LAUNCHD_TYPE" == "daemon" ]]; then
|
||||
chown root:wheel "$plist_path"
|
||||
chmod 644 "$plist_path"
|
||||
local type_display="LaunchDaemon"
|
||||
else
|
||||
local type_display="LaunchAgent"
|
||||
fi
|
||||
|
||||
LogInformation "Created Launch${LAUNCHD_TYPE^} plist: $plist_path"
|
||||
LogInformation "Created $type_display plist: $plist_path"
|
||||
|
||||
# Use appropriate launchctl commands based on type
|
||||
if [[ "$LAUNCHD_TYPE" == "daemon" ]]; then
|
||||
@@ -131,10 +134,10 @@ EOF
|
||||
|
||||
# Load the plist
|
||||
if launchctl bootstrap system "$plist_path" 2>/dev/null; then
|
||||
LogInformation "Loaded LaunchDaemon for $script"
|
||||
LogInformation "Loaded $type_display for $script"
|
||||
return 0
|
||||
else
|
||||
LogError "Failed to load LaunchDaemon for $script"
|
||||
LogError "Failed to load $type_display for $script"
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
@@ -143,10 +146,10 @@ EOF
|
||||
|
||||
# Load the plist
|
||||
if launchctl load "$plist_path" 2>/dev/null; then
|
||||
LogInformation "Loaded LaunchAgent for $script"
|
||||
LogInformation "Loaded $type_display for $script"
|
||||
return 0
|
||||
else
|
||||
LogError "Failed to load LaunchAgent for $script"
|
||||
LogError "Failed to load $type_display for $script"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
@@ -267,6 +270,13 @@ ShowStatus() {
|
||||
|
||||
RemoveCrontabEntries() {
|
||||
local removed_count=0
|
||||
local type_display
|
||||
|
||||
if [[ "$LAUNCHD_TYPE" == "daemon" ]]; then
|
||||
type_display="LaunchDaemon"
|
||||
else
|
||||
type_display="LaunchAgent"
|
||||
fi
|
||||
|
||||
if [[ "$OS_TYPE" == "macos" ]]; then
|
||||
# Remove LaunchAgents/LaunchDaemons
|
||||
@@ -276,7 +286,7 @@ RemoveCrontabEntries() {
|
||||
local plist_path="${LAUNCHD_DIR}/${plist_name}"
|
||||
|
||||
if [[ -f "$plist_path" ]]; then
|
||||
LogInformation "Removing Launch${LAUNCHD_TYPE^} for $script_name..."
|
||||
LogInformation "Removing $type_display for $script_name..."
|
||||
|
||||
# Unload the agent/daemon
|
||||
if [[ "$LAUNCHD_TYPE" == "daemon" ]]; then
|
||||
@@ -289,14 +299,14 @@ RemoveCrontabEntries() {
|
||||
rm -f "$plist_path"
|
||||
((removed_count++))
|
||||
else
|
||||
LogDebug "No Launch${LAUNCHD_TYPE^} found for $script_name"
|
||||
LogDebug "No $type_display found for $script_name"
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ $removed_count -gt 0 ]]; then
|
||||
LogInformation "Removed $removed_count Launch${LAUNCHD_TYPE^}s"
|
||||
LogInformation "Removed $removed_count ${type_display}s"
|
||||
else
|
||||
LogWarning "No Launch${LAUNCHD_TYPE^}s were found to remove"
|
||||
LogWarning "No ${type_display}s were found to remove"
|
||||
fi
|
||||
else
|
||||
# Remove crontab entries
|
||||
|
||||
Reference in New Issue
Block a user