15 Commits

Author SHA1 Message Date
95ebba50e3 Verbosity handling improvement, corrections of the services filtering output and help 2021-02-26 01:38:42 +02:00
0506889700 Fixed hanging on output, if no logs are found for a nonexist service 2021-02-02 20:30:43 +02:00
59d2325f73 Fixed: Incorrect status of services, on rsm list after enable <service> - rsm lists all right after enable/disable <service> 2021-01-23 21:50:34 +02:00
0477798c9e Code review, removed locals from logs() and errorlogs() and added them as globals 2021-01-21 21:01:25 +02:00
750cde1aa1 Improved -h switch output, changed color of the error log files output title 2021-01-21 20:12:07 +02:00
16f8b86d1b Fixed bug of improper listing logs, when script runs on /usr/bin 2021-01-21 13:07:54 +02:00
3bd632a39b Update README.md 2021-01-19 22:53:42 +02:00
b17e0376bc logs <svc> / alllogs <svc> / errorlogs <svc> added to rsm, as commands 2021-01-19 22:33:57 +02:00
250654bfdb New release number, 1.3.9 2021-01-13 21:06:00 +02:00
edbabda2df Updated Screenshot at README.md, with verbociry on 2021-01-13 21:01:43 +02:00
9d13a0576b Verbocity on by default, for better output 2021-01-13 20:57:59 +02:00
27bcdec74f Better code comments 2021-01-13 19:46:52 +02:00
6815946574 Tiny code beautification, to fit the rest part of the code 2021-01-13 04:55:57 +02:00
f4e12ec2e1 Updated README.md with the enable command, in details 2021-01-13 02:01:01 +02:00
533d0e6250 fixed link/unlink service, on enable/disable rsm commands 2021-01-12 23:36:08 +02:00
2 changed files with 137 additions and 11 deletions

View File

@@ -1,11 +1,10 @@
# `rsm` - Runit Service Manager
===================================
- 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.
![](https://imgur.com/jxQUIGb.png)
![](https://imgur.com/S9zdEIU.png)
## Manage and view runit services.
@@ -18,10 +17,12 @@ Quick Examples:
- `rsm status` - same as above
- `rsm stop <svc>` - stop a service
- `rsm start <svc>` - start a service
- `rsm restart <svc>` - restart a service
- `rsm restart <svc>` - restart a service, or start service right after `rsm enable <svc>`
- `rsm enable <svc>` - enable a service (autostart at boot)
- `rsm disable <svc>` - disable a service (no autostart at boot)
- `rsm hup <svc>` - refresh a service (`SIGHUP`)
- `rsm logs <svc>` or `rsm alllogs <svc>` - lists all logs for a service (access and error)
- `rsm errorlogs <svc>` - lists all error logs for a service
Status:

141
rsm
View File

@@ -1,14 +1,21 @@
#!/usr/bin/env bash
#
# Void Linux service manager (runit)
# Artix Linux service manager (runit)
# 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
#
# Author: Dave Eddy <dave@daveeddy.com>
# Original Author (vsv): Dave Eddy <dave@daveeddy.com>
# Date: August 29, 2018
# License: MIT
RSM_VERSION='v1.3.7'
RSM_VERSION='v1.4.5'
export SVDIR=${SVDIR:-/run/runit/service/}
export LOGDIR="/var/log/"
export RSVDIR="/run/runit/service/"
export FLDIR=${FLDIR:-/etc/runit/sv/}
charup='✔'
chardown='X'
@@ -116,13 +123,14 @@ usage() {
cat <<EOF
$colormagenta ______ ____ __ __
$colormagenta | | \ \ / ___\ | \/ | $colorgreen Runit Service Manager ($RSM_VERSION)
$colormagenta | | \ \ / ___\ | \/ | $colorgreen Runit Service Manager for Artix Linux ($RSM_VERSION)
$colormagenta | |_/ / \____ | || | $colorgreen Source: https://gitea.artixlinux.org/linuxer/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
${coloryellow}USAGE:${colorgreen}
$progname [OPTIONS] [SUBCOMMAND] [<ARGS>]
@@ -130,7 +138,7 @@ $progname [-u] [-d <dir>] [-h] [-t] [SUBCOMMAND] [...]
${coloryellow}OPTIONS:${colorgreen}
${colorgreen}-c <yes|no|auto> $cr Enable/disable color output, defaults to auto
${colorgreen}-d <dir> $cr Directory to look into, defaults to env SVDIR or /var/service if unset
${colorgreen}-d <dir> $cr Directory to look into, defaults to env SVDIR or /run/runit/service is unset
${colorgreen}-h $cr Print this message and exit
${colorgreen}-l $cr Show log processes, this is a shortcut for 'status -l'
${colorgreen}-t $cr Tree view, this is a shortcut for 'status -t'
@@ -160,6 +168,10 @@ ${colorgreen}start <service> $cr Start the service
${colorgreen}stop <service> $cr Stop the service
${colorgreen}restart <service> $cr Restart the service
${colorgreen}reload <service> $cr Reload the service (send SIGHUP)
${colorgreen}logs <service> $cr Outputs the service's logfilenames and their access & error logs from /var/log/<serice>/
${colorgreen}alllogs <service> $cr The same like logs <service>
${colorgreen}errorlogs <service> $cr Outputs the service's logfilenames and their errorlogs from /var/log/<serice>/
${coloryellow}EXAMPLES:${colorgreen}
${colorgreen}$progname $cr Show service status in /var/service
@@ -379,7 +391,9 @@ do_status() {
fi
if [[ -n $filter && $svc != *"$filter"* ]]; then
verbose "filtering out '$svc' because match '$filter'"
if [[ $verbosity != 1 ]]; then
verbose "filtering out '$svc' because it does not match '$filter'"
fi
continue
fi
@@ -449,7 +463,7 @@ do_enable_disable() {
fi
# ensure service exists
if ! [[ -d $svc ]]; then
if ! [[ -d ${FLDIR}${svc} ]]; then
rmsg -1 "service directory '$svc' does not exist" >&2
continue
fi
@@ -462,6 +476,9 @@ do_enable_disable() {
if ! rm -f "$file"; then
rmsg 1 "failed to enable '$svc'"
ret=1
else
ln -s ${FLDIR}${svc} ${SVDIR}
do_status
fi
;;
disable)
@@ -469,6 +486,9 @@ do_enable_disable() {
if ! disable_message "$svc" > "$file"; then
rmsg 1 "failed to disable '$svc'"
ret=1
else
unlink ${SVDIR}${svc}
do_status
fi
;;
*)
@@ -482,6 +502,101 @@ do_enable_disable() {
return "$ret"
}
# show logs
do_show_logs() {
local cmd=$1
local svc
local ret=0
local file
shift
# Loop all arguments as services
msg "Running $progname $cmd $*"
for svc in "$@"; do
# Validate service name
if ! [[ $svc =~ $svc_re ]]; then
rmsg -1 "unexpected characters in name: '$svc'" >&2
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/*.*))
printf "\n$colorblue"
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"
fi
fi
if ! [[ -f "${RSVDIR}${cmd}" ]]; then
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"
}
# show error logs
do_show_err_logs() {
local cmd=$1
local svc
local ret=0
local file
shift
# Loop all arguments as services
msg "Running $progname $cmd $*"
for svc in "$@"; do
# Validate service name
if ! [[ $svc =~ $svc_re ]]; then
rmsg -1 "unexpected characters in name: '$svc'" >&2
continue
fi
done
if [[ -f "${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 "\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
printf "\n"
fi
fi
if ! [[ -f "${RSVDIR}${cmd}" ]]; then
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"
}
# handle any other subcommand
do_sv_cmd() {
if (($# < 2)); then
@@ -500,7 +615,7 @@ colors_set=false
tree=false
log=false
do_usage=-1
verbosity=0
verbosity=1
while getopts 'c:d:hltuvV' option; do
case "$option" in
c) setcolors "$OPTARG"; colors_set=true;;
@@ -540,6 +655,16 @@ case "$cmd" in
enable|disable)
do_enable_disable "$cmd" "$@"
;;
logs)
do_show_logs "$@"
;;
alllogs)
do_show_logs "$@"
;;
errorlogs)
do_show_err_logs "$@"
;;
*)
if $tree; then
rmsg -1 "-t can only be specified with 'status'"