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