Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
b13b47d1c0 | |||
8173828c62 | |||
3ead5f0492 | |||
a921025ce9 | |||
33d35654fc |
13
LICENSE
Normal file
13
LICENSE
Normal file
@@ -0,0 +1,13 @@
|
||||
Copyright (c) 2017+, Jack L. Frost <fbt@fleshless.org>
|
||||
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any purpose with or without
|
||||
fee is hereby granted, provided that the above copyright notice and this permission notice appear
|
||||
in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
|
||||
SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
|
||||
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
OF THIS SOFTWARE.
|
10
README.md
Normal file
10
README.md
Normal file
@@ -0,0 +1,10 @@
|
||||
ssm
|
||||
===
|
||||
|
||||
Yet another service manager.
|
||||
|
||||
Services
|
||||
--------
|
||||
A service is a script in the ssm's init.d directory.
|
||||
By default it's /etc/ssm/init.d for system services and $XDG_CONFIG_HOME/ssm/init.d for user ones.
|
||||
ssm creates relevant dirs if they don't exist.
|
28
ssm
28
ssm
@@ -96,7 +96,7 @@ pid_wait() {
|
||||
|
||||
## See if NAME is a function
|
||||
is_function() {
|
||||
declare name=$1 name_tupe
|
||||
declare name=$1 name_type
|
||||
|
||||
name_type=$( type -t "$name" )
|
||||
|
||||
@@ -109,7 +109,7 @@ is_function() {
|
||||
|
||||
## Simple timer
|
||||
timer() {
|
||||
declare cnt timeout=$1
|
||||
declare cnt=0 timeout=$1
|
||||
shift
|
||||
|
||||
while ! "$@"; do
|
||||
@@ -188,6 +188,8 @@ depend_ready() {
|
||||
super_start() {
|
||||
(( service_running )) && return 3
|
||||
|
||||
rm -f "$service_stopped_flag"
|
||||
|
||||
[[ -f "${service_command[0]}" ]] || return 9
|
||||
|
||||
depend "${service_depends[@]}" || return 7
|
||||
@@ -250,6 +252,7 @@ super_stop() {
|
||||
|
||||
nullexec kill -n "$service_stop_signal" "$service_pid" || return 1
|
||||
pid_wait "$service_pid" || return 5
|
||||
> "$service_stopped_flag"
|
||||
|
||||
return 0
|
||||
fi
|
||||
@@ -273,7 +276,7 @@ info() {
|
||||
"Name" "$service_name"
|
||||
"Type" "$_type"
|
||||
"$_status_label" "$_status"
|
||||
"Exec" "$service_command ${service_args[*]}"
|
||||
"Exec" "${service_command[*]} ${service_args[*]}"
|
||||
"Respawn" "${service_respawn:-false}"
|
||||
)
|
||||
|
||||
@@ -312,12 +315,14 @@ restart() {
|
||||
"$0" "$service_name" start
|
||||
}
|
||||
|
||||
logs() { "${PAGER:-less}" "$service_logfile"; }
|
||||
logs() { ${PAGER:-less} "$service_logfile"; }
|
||||
|
||||
## Status is a bit of a special case. It's talkative.
|
||||
status() {
|
||||
(( service_running )) && return 0
|
||||
(( service_enabled )) && return 0
|
||||
(( service_stopped )) && return 7
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
@@ -410,6 +415,7 @@ main() {
|
||||
default service_reload_signal 1
|
||||
default service_ready_flag "$rundir/$service_name.ready"
|
||||
default service_enabled_flag "$rundir/$service_name.enabled"
|
||||
default service_stopped_flag "$rundir/$service_name.stopped"
|
||||
|
||||
# default does not support arrays
|
||||
[[ "$service_signals" ]] || service_signals=( 1 10 12 )
|
||||
@@ -430,9 +436,20 @@ main() {
|
||||
service_enabled=1
|
||||
fi
|
||||
|
||||
# Let's see if the service was deliberately stopped
|
||||
if [[ -f "$service_stopped_flag" ]]; then
|
||||
# Ooh, it was.
|
||||
service_stopped=1
|
||||
fi
|
||||
|
||||
# Check if action is even defined
|
||||
is_function "$2" || die 17 "Function $2 is not defined for $service_name."
|
||||
|
||||
# cd into the workdir, if defined.
|
||||
[[ "$service_workdir" ]] && {
|
||||
cd "$service_workdir" || die $?
|
||||
}
|
||||
|
||||
# Run pre_$action function
|
||||
if is_function "pre_$2"; then
|
||||
"pre_$2" || {
|
||||
@@ -475,7 +492,8 @@ main() {
|
||||
else
|
||||
result "$res" \
|
||||
0 "$service_name is running" \
|
||||
1 "$service_name is not running"
|
||||
1 "$service_name is not running" \
|
||||
7 "$service_name was stopped"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
Reference in New Issue
Block a user