refactor: Use systemctl as the 1st check as service manager command
This commit is contained in:
@@ -184,33 +184,22 @@ manage_service() {
|
|||||||
action="$2" # start, stop, restart, enable
|
action="$2" # start, stop, restart, enable
|
||||||
|
|
||||||
command_status=0
|
command_status=0
|
||||||
# Try service command
|
|
||||||
if command -v service >/dev/null 2>&1; then
|
|
||||||
file_log "INFO" "Using service command for $service_name $action"
|
|
||||||
case "$action" in
|
|
||||||
enable)
|
|
||||||
# Service command doesn't support enable
|
|
||||||
# We will do nothing here, and let the systemctl handle this
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
output=$(service "$service_name" "$action" 2>&1)
|
|
||||||
command_status=$?
|
|
||||||
if [ -n "$output" ]; then
|
|
||||||
file_log "INFO" "service $action output: $output"
|
|
||||||
fi
|
|
||||||
return $command_status
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Try systemctl first (systemd)
|
# Try systemctl first (systemd)
|
||||||
if command -v systemctl >/dev/null 2>&1; then
|
if command -v systemctl >/dev/null 2>&1; then
|
||||||
file_log "INFO" "Using systemctl for $service_name $action"
|
file_log "INFO" "Using systemctl for $service_name $action"
|
||||||
output=$(systemctl "$action" "$service_name" 2>&1)
|
output=$(systemctl "$action" "$service_name" 2>&1)
|
||||||
command_status=$?
|
command_status=$?
|
||||||
if [ -n "$output" ]; then
|
file_log "INFO" "systemctl $action output: $output"
|
||||||
file_log "INFO" "systemctl $action output: $output"
|
return $command_status
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Try service command
|
||||||
|
if command -v service >/dev/null 2>&1; then
|
||||||
|
file_log "INFO" "Using service command for $service_name $action"
|
||||||
|
output=$(service "$service_name" "$action" 2>&1)
|
||||||
|
command_status=$?
|
||||||
|
file_log "INFO" "service $action output: $output"
|
||||||
return $command_status
|
return $command_status
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -223,25 +212,19 @@ manage_service() {
|
|||||||
if command -v chkconfig >/dev/null 2>&1; then
|
if command -v chkconfig >/dev/null 2>&1; then
|
||||||
output=$(chkconfig "$service_name" on 2>&1)
|
output=$(chkconfig "$service_name" on 2>&1)
|
||||||
command_status=$?
|
command_status=$?
|
||||||
if [ -n "$output" ]; then
|
file_log "INFO" "chkconfig output: $output"
|
||||||
file_log "INFO" "chkconfig output: $output"
|
|
||||||
fi
|
|
||||||
return $command_status
|
return $command_status
|
||||||
elif command -v update-rc.d >/dev/null 2>&1; then
|
elif command -v update-rc.d >/dev/null 2>&1; then
|
||||||
output=$(update-rc.d "$service_name" defaults 2>&1)
|
output=$(update-rc.d "$service_name" defaults 2>&1)
|
||||||
command_status=$?
|
command_status=$?
|
||||||
if [ -n "$output" ]; then
|
file_log "INFO" "update-rc.d output: $output"
|
||||||
file_log "INFO" "update-rc.d output: $output"
|
|
||||||
fi
|
|
||||||
return $command_status
|
return $command_status
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
output=$("/etc/init.d/$service_name" "$action" 2>&1)
|
output=$("/etc/init.d/$service_name" "$action" 2>&1)
|
||||||
command_status=$?
|
command_status=$?
|
||||||
if [ -n "$output" ]; then
|
file_log "INFO" "init.d $action output: $output"
|
||||||
file_log "INFO" "init.d $action output: $output"
|
|
||||||
fi
|
|
||||||
return $command_status
|
return $command_status
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|||||||
Reference in New Issue
Block a user