7 Commits

5 changed files with 240 additions and 46 deletions

View File

@@ -1,5 +1,6 @@
Copyright 2020 Dave Eddy <dave@daveeddy.com> (https://www.daveeddy.com)
Forked as a contribution to Artix Linux by linuxer <linuxer@artixlinux.org>
Forked by nikolar <nikolar@artixlinux.org> (24. 12. 2022)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

View File

@@ -2,8 +2,8 @@
- This is the CLI Runit Service Manager {rsm}, forked from Void Service Manager {vsv} https://github.com/bahamas10/vsv/blob/master/vsv
- Terminal Commands are exactly the same as sv, but produces a beautified layout.
- Terminal Commands are exactly the same as sv, but produces a beautified layout.
![](https://imgur.com/S9zdEIU.png)
## Manage and view runit services.
@@ -102,6 +102,12 @@ $ make check
shellcheck rsm
```
Installation
------------
- You'll have to change the `$SVDIR` and `$RUNSVDIR` variables to your distro's
configuration to make the autocompletion work properly.
License
-------

33
autocompletion/bash/rsm Normal file
View File

@@ -0,0 +1,33 @@
#/usr/bin/env bash
_rsm_completions() {
SVDIR='/etc/runit/sv'
RUNSVDIR='/etc/runit/runsvdir/default'
if [ "${#COMP_WORDS[@]}" -eq 3 ]
then
cmd="${COMP_WORDS[1]}"
# notify-send "$cmd"
case "$cmd" in
status|enable|logs|alllogs|errorlogs)
COMPREPLY=($(compgen -W "$(ls -1 $SVDIR | xargs echo)" \
"${COMP_WORDS[2]}"))
;;
disable|start|stop|restart|reload)
COMPREPLY=($(compgen -W "$(ls -1 $RUNSVDIR | xargs echo)" \
"${COMP_WORDS[2]}"))
;;
esac
elif [ "${#COMP_WORDS[@]}" -eq 2 ]
then
COMPREPLY=($(compgen -W "status enable disable start \
stop restart reload logs alllogs errorlogs" "${COMP_WORDS[1]}"))
else
COMPREPLY=('wtf')
fi
return 0
}
complete -F _rsm_completions rsm

129
autocompletion/zsh/_rsm Normal file
View File

@@ -0,0 +1,129 @@
#compdef rsm
_rsm_all_services() {
local IFS=$'\n'
# Extract names and email addresses from gpg --list-keys
_values 'Active services' $(ls -1 "$SVDIR")
}
_rsm_active_services() {
local IFS=$'\n'
# Extract names and email addresses from gpg --list-keys
_values 'Active services' $(ls -1 "$RUNSVDIR")
}
_rsm_common_args() {
_arguments : \
'-c[Enable/disable color output, defaults to auto]:Enable color:(yes no auto)' \
'-d[Directory to look into, defaults to env SVDIR or /run/runit/service is unset]:directory:_files -/' \
'-h[Print this message and exit]' \
"-l[Show log processes, this is a shortcut for 'status -l']" \
"-t[Tree view, this is a shortcut for 'status -t']" \
"-u[User mode, this is a shortcut for '-d ~/runit/service']" \
'-v[Increase verbosity]' \
'-V[Print the version number and exit]'
}
_rsm_subcommands() {
local subcommands=(
'status:Default subcommand, show process status'
'enable:Enable the service(s) (remove the "down" file, does not start service'
'disable:Disable the service(s) (create the "down" file, does not stop service'
'start:Start the service'
'stop:Stop the service'
'restart:Restart the service'
'reload:Reload the service (send SIGHUP)'
"logs:Outputs the service's logfilenames and their access & error logs from /var/log/<serice>/"
'alllogs:The same like logs <service>'
"errorlogs:Outputs the service's logfilenames and their errorlogs from /var/log/<service>/"
)
_describe -t commands 'rsm' subcommands
}
_rsm() {
local -a args subcommands cmd havesubcmd tmpwords lastcmd SVDIR RUNSVDIR
# NOTE Change there variables to your configuration
SVDIR='/etc/runit/sv'
RUNSVDIR='/etc/runit/runsvdir/default'
havesubcmd=NONE
tmpwords=("${words[@]}")
while true
do
cmd="${tmpwords[2]}"
case "$cmd" in
-h|-V)
# Help and version options override everything else
return
;;
-c)
havesubcmd=OPTARG
shift tmpwords
;;
-d)
havesubcmd=OPTARG
shift tmpwords
;;
-*)
havesubcmd=OPT
shift tmpwords
;;
"")
break
;;
*)
if [ "$havesubcmd" = OPTARG ]
then
if [ "$lastcmd" = "-d" ]
then
SVDIR="$cmd"
fi
havesubcmd=OPT
shift tmpwords
else
havesubcmd=SUBCMD
break
fi
;;
esac
lastcmd="$cmd"
done
if [ "$havesubcmd" = SUBCMD ]
then
words=("${tmpwords[@]}")
cmd="${words[2]}"
# CURRENT=$((CURRENT - 1))
shift words
case "$cmd" in
status)
_rsm_active_services
_arguments : \
'-t[Enables tree mode (process tree)]' \
'-l[Enables log mode (show log processes)]'
;;
enable|logs|alllogs|errorlogs)
_rsm_all_services
;;
disable|start|stop|restart|reload)
_rsm_active_services
;;
*)
_rsm_subcommands
;;
esac
else
if [ "$havesubcmd" = NONE ] || [ "$havesubcmd" = OPT ]
then
_rsm_subcommands
_rsm_common_args
elif [ "$havesubcmd" = OPTARG ]
then
_rsm_common_args
fi
fi
return 0
}
_rsm

113
rsm
View File

@@ -1,16 +1,20 @@
#!/usr/bin/env bash
#
# Artix Linux service manager (runit)
# Forked and further developed, by: linuxer <linuxer@artixlinux.org>
# Forked and further developed, by: nikolar <nikolar@artixlinux.org>
# Fork Date: December 24, 2022
#
# Forked and further developed, by: linuxer <linuxer@artixlinux.org>
# Fork Date: August 15, 2020 as rsv
# Renamed and further developed as rsm from: January 10, 2021
# Renamed and further developed as rsm from: January 10, 2021
#
# Original Author (vsv): Dave Eddy <dave@daveeddy.com>
# Date: August 29, 2018
# License: MIT
RSM_VERSION='v1.4.5'
RSM_VERSION='v1.4.8'
export RUNSVDIR=${RUNSVDIR:-/etc/runit/runsvdir}
export SVDIR=${SVDIR:-/run/runit/service/}
export LOGDIR="/var/log/"
export RSVDIR="/run/runit/service/"
@@ -124,13 +128,14 @@ usage() {
cat <<EOF
$colormagenta ______ ____ __ __
$colormagenta | | \ \ / ___\ | \/ | $colorgreen Runit Service Manager for Artix Linux ($RSM_VERSION)
$colormagenta | |_/ / \____ | || | $colorgreen Source: https://gitea.artixlinux.org/linuxer/Runit-Service-Manager
$colormagenta | |_/ / \____ | || | $colorgreen Source: https://gitea.artixlinux.org/nikolar/Runit-Service-Manager
$colormagenta | | \ \ \____/ | || | $colorgreen MIT License
$logo $colorblue Manage and view runit services
$logo $colorblue Made specifically for Void Linux but should work anywhere
$logo $colorblue Author: Dave Eddy <dave@daveeddy.com> (bahamas10)
$logo $colorblue Forked specifically for Artix Linux and renamed to rsm, for further development
$logo $colorblue Maitained by nikolar <nikolar@artixlinux.org> (nikolar in #artix)
${coloryellow}USAGE:${colorgreen}
$progname [OPTIONS] [SUBCOMMAND] [<ARGS>]
@@ -477,7 +482,12 @@ do_enable_disable() {
rmsg 1 "failed to enable '$svc'"
ret=1
else
ln -s ${FLDIR}${svc} ${SVDIR}
if [ -L "${SVDIR}" ]
then
ln -s "${FLDIR}${svc}" "${SVDIR}"
else
ln -s "${FLDIR}${svc}" "${RUNSVDIR}/default" # default runlevel
fi
do_status
fi
;;
@@ -487,7 +497,12 @@ do_enable_disable() {
rmsg 1 "failed to disable '$svc'"
ret=1
else
unlink ${SVDIR}${svc}
if [ -L "${SVDIR}" ]
then
unlink "${SVDIR}${svc}"
else
unlink "${RUNSVDIR}/default/${svc}" # default runlevel
fi
do_status
fi
;;
@@ -520,32 +535,33 @@ do_show_logs() {
continue
fi
done
if [[ -f "${RSVDIR}${cmd}" ]]; then
if ! [[ -d ${RSVDIR}${cmd} ]]; then
printf "\n%20s\n" "${colorgreen}The following log files found:"
local logs_files_array=($(ls /var/log/$cmd/*.*))
if [ -h "${RSVDIR}${cmd}" ]
then
if [ -d "${RSVDIR}${cmd}" ]
then
# TODO check for logs before globing non-existent directories
printf "\n%20s\n" "${colorgreen}The following log files found:"
local logs_files_array=($(ls /var/log/$cmd/{*.*,current}))
printf "\n$colorblue"
printf '%s\n' "${logs_files_array[@]}"
printf '%s\n' "${logs_files_array[@]}"
printf "\n$colormagenta"
read -n 1 -s -r -p "Press any key to continue"
printf "\n"
printf "\n${colorcyan}Log files full output:\n"
printf "${coloryellow}\n"
printf "${coloryellow}${opt}"
tail -n 10 ${LOGDIR}${cmd}/*.* | more
printf "\n"
tail -n 10 ${LOGDIR}${cmd}/{*.*,current} | less
printf "\n"
fi
fi
if ! [[ -f "${RSVDIR}${cmd}" ]]; then
else
printf "\n%20s\n" "${colorred}The service's ${cmd} log files have not been found or do not exist"
fi
rmsg "$ret" "[$progname $cmd $*], exit code: $ret"
return "$ret"
}
@@ -568,31 +584,31 @@ do_show_err_logs() {
continue
fi
done
if [[ -f "${RSVDIR}${cmd}" ]]; then
if ! [[ -d ${RSVDIR}${cmd} ]]; then
printf "\n%20s\n" "${colorred}The following error log files found:"
if [ -h "${RSVDIR}${cmd}" ]
then
if ! [ -d ${RSVDIR}${cmd} ]
then
printf "\n%20s\n" "${colorred}The following error log files found:"
local logs_files_array=($(ls /var/log/$cmd/*error*.*))
printf "\n$colorblue"
printf '%s\n' "${logs_files_array[@]}"
printf '%s\n' "${logs_files_array[@]}"
printf "\n$colormagenta"
read -n 1 -s -r -p "Press any key to continue"
printf "\n"
printf "\n${colorcyan}Log files full output:\n"
printf "${coloryellow}\n"
printf "${coloryellow}${opt}"
tail -n 10 ${LOGDIR}${cmd}/*error*.* | more
tail -n 10 ${LOGDIR}${cmd}/*error*.* | more
printf "\n"
fi
fi
if ! [[ -f "${RSVDIR}${cmd}" ]]; then
else
printf "\n%20s\n" "${colorred}The service's ${cmd} error log files have not been found or do not exist"
fi
rmsg "$ret" "[$progname $cmd $*], exit code: $ret"
return "$ret"
}
@@ -611,14 +627,14 @@ do_sv_cmd() {
return "$ret"
}
colors_set=false
color_arg=
tree=false
log=false
do_usage=-1
verbosity=1
while getopts 'c:d:hltuvV' option; do
case "$option" in
c) setcolors "$OPTARG"; colors_set=true;;
c) color_arg="$OPTARG";;
d) SVDIR=$OPTARG;;
h) do_usage=0;;
l) log=true; cmd='status';;
@@ -631,7 +647,16 @@ while getopts 'c:d:hltuvV' option; do
done
shift "$((OPTIND - 1))"
$colors_set || setcolors auto
if [ -n "$NO_COLOR" ] && [ -z "$color_arg" ]
then
setcolors off
elif [ -n "$color_arg" ]
then
setcolors "$color_arg"
else
setcolors auto
fi
# we wait until the colors are optionally set to output the usage message
if ((do_usage > -1)); then
@@ -656,14 +681,14 @@ case "$cmd" in
do_enable_disable "$cmd" "$@"
;;
logs)
do_show_logs "$@"
;;
do_show_logs "$@"
;;
alllogs)
do_show_logs "$@"
;;
do_show_logs "$@"
;;
errorlogs)
do_show_err_logs "$@"
;;
do_show_err_logs "$@"
;;
*)
if $tree; then