forked from ChrisTitusTech/linutil
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0f79e00
commit 45a880a
Showing
8 changed files
with
115 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#!/bin/sh -e | ||
|
||
checkInitManager() { | ||
for manager in $1; do | ||
if command_exists "$manager"; then | ||
INIT_MANAGER="$manager" | ||
printf "%b\n" "${CYAN}Using ${manager} to interact with init system${RC}" | ||
break | ||
fi | ||
done | ||
|
||
if [ -z "$INIT_MANAGER" ]; then | ||
printf "%b\n" "${RED}Can't find a supported init system${RC}" | ||
exit 1 | ||
fi | ||
} | ||
|
||
startService() { | ||
case "$INIT_MANAGER" in | ||
systemctl) | ||
"$ESCALATION_TOOL" "$INIT_MANAGER" start "$1" | ||
;; | ||
rc-service) | ||
"$ESCALATION_TOOL" "$INIT_MANAGER" "$1" start | ||
;; | ||
esac | ||
} | ||
|
||
stopService() { | ||
case "$INIT_MANAGER" in | ||
systemctl) | ||
"$ESCALATION_TOOL" "$INIT_MANAGER" stop "$1" | ||
;; | ||
rc-service) | ||
"$ESCALATION_TOOL" "$INIT_MANAGER" "$1" stop | ||
;; | ||
esac | ||
} | ||
|
||
enableService() { | ||
case "$INIT_MANAGER" in | ||
systemctl) | ||
"$ESCALATION_TOOL" "$INIT_MANAGER" enable "$1" | ||
;; | ||
rc-service) | ||
"$ESCALATION_TOOL" rc-update add "$1" | ||
;; | ||
esac | ||
} | ||
|
||
disableService() { | ||
case "$INIT_MANAGER" in | ||
systemctl) | ||
"$ESCALATION_TOOL" "$INIT_MANAGER" disable "$1" | ||
;; | ||
rc-service) | ||
"$ESCALATION_TOOL" rc-update del "$1" | ||
;; | ||
esac | ||
} | ||
|
||
startAndEnableService() { | ||
case "$INIT_MANAGER" in | ||
systemctl) | ||
"$ESCALATION_TOOL" "$INIT_MANAGER" enable --now "$1" | ||
;; | ||
rc-service) | ||
enableService "$1" | ||
startService "$1" | ||
;; | ||
esac | ||
} | ||
|
||
isServiceActive() { | ||
case "$INIT_MANAGER" in | ||
systemctl) | ||
"$ESCALATION_TOOL" "$INIT_MANAGER" is-active --quiet "$1" | ||
;; | ||
rc-service) | ||
"$ESCALATION_TOOL" "$INIT_MANAGER" "$1" status --quiet | ||
;; | ||
esac | ||
} | ||
|
||
checkInitManager 'systemctl rc-service' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters