Compare commits
	
		
			17 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 0506889700 | |||
| 59d2325f73 | |||
| 0477798c9e | |||
| 750cde1aa1 | |||
| 16f8b86d1b | |||
| 3bd632a39b | |||
| b17e0376bc | |||
| 250654bfdb | |||
| edbabda2df | |||
| 9d13a0576b | |||
| 27bcdec74f | |||
| 6815946574 | |||
| f4e12ec2e1 | |||
| 533d0e6250 | |||
| 3a69fa0a14 | |||
| b9aad0805e | |||
| f27c7d4a1b | 
							
								
								
									
										107
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										107
									
								
								README.md
									
									
									
									
									
								
							| @@ -1,7 +1,108 @@ | ||||
| # Runit-Service-Manager | ||||
| # `rsm` - Runit Service Manager | ||||
|  | ||||
| - This is the CLI Runit Service Manager {rsv}, forked from Void Service Manager {vsv}  https://github.com/bahamas10/vsv/blob/master/vsv | ||||
| - 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. | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
| ## Manage and view runit services. | ||||
|  | ||||
| Usage | ||||
| ----- | ||||
|  | ||||
| Quick Examples: | ||||
|  | ||||
| - `rsm` - show all services | ||||
| - `rsm status` - same as above | ||||
| - `rsm stop <svc>` - stop a service | ||||
| - `rsm start <svc>` - start 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: | ||||
|  | ||||
| The `status` subcommand has the following fields: | ||||
|  | ||||
| - `SERVICE` - the service (directory) name. | ||||
| - `STATE` - the service state: output from `.../$service/supervise/stat`. | ||||
| - `ENABLED` - if the service is enabled (lacks the `.../$service/down` file). | ||||
| - `PID` - the pid of the process being monitored. | ||||
| - `COMMAND` - arg0 from the pid being monitored (first field of `/proc/$pid/cmdline`. | ||||
| - `TIME` - time the service has been in whatever state it is in. | ||||
|  | ||||
| Command Usage: | ||||
|  | ||||
|     [rsm]    Manage and view runit services | ||||
|     [rsm]    Made specifically for Void Linux but should work anywhere | ||||
|     [rsm]    Author: Dave Eddy <dave@daveeddy.com> (bahamas10) | ||||
|  | ||||
|     USAGE: | ||||
|     rsm [OPTIONS] [SUBCOMMAND] [<ARGS>] | ||||
|     rsm [-u] [-d <dir>] [-h] [-t] [SUBCOMMAND] [...] | ||||
|  | ||||
|     OPTIONS: | ||||
|     -c <yes|no|auto>          Enable/disable color output, defaults to auto | ||||
|     -d <dir>                  Directory to look into, defaults to env SVDIR or /var/service if unset | ||||
|     -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 | ||||
|  | ||||
|     ENV: | ||||
|     SVDIR                     The directory to use, passed to the 'sv' command, can | ||||
|                               be overridden with '-d <dir>' | ||||
|  | ||||
|     SUBCOMMANDS: | ||||
|     status [-lt] [filter]     Default subcommand, show process status | ||||
|                               '-t' enables tree mode (process tree) | ||||
|                               '-l' enables log mode (show log processes) | ||||
|                               'filter' is an optional string to match service names against | ||||
|  | ||||
|     enable <svc> [...]        Enable the service(s) (remove the "down" file, does not start service) | ||||
|  | ||||
|     disable <svc> [...]       Disable the service(s) (create the "down" file, does not stop service) | ||||
|  | ||||
|     Any other subcommand gets passed directly to the 'sv' command, see sv(1) for the | ||||
|     full list of subcommands and information about what each does specifically. | ||||
|     Common subcommands: | ||||
|  | ||||
|     start <service>           Start the service | ||||
|     stop <service>            Stop the service | ||||
|     restart <service>         Restart the service | ||||
|     reload <service>          Reload the service (send SIGHUP) | ||||
|  | ||||
|     EXAMPLES: | ||||
|     rsm                       Show service status in /var/service | ||||
|     rsm status                Same as above | ||||
|     rsm -t                    Show service status + pstree output | ||||
|     rsm status -t             Same as above | ||||
|     rsm status tty            Show service status for any service that matches tty* | ||||
|     rsm check uuidd           Check the uuidd svc, wrapper for 'sv check uuidd' | ||||
|     rsm restart sshd          Restart sshd, wrapper for 'sv restart sshd' | ||||
|     rsm -u                    Show service status in ~/runit/service | ||||
|     rsm -u restart ssh-agent  Restart ssh-agent in ~/runit/service/ssh-agent | ||||
|  | ||||
| Syntax | ||||
| ------ | ||||
|  | ||||
| This project uses: | ||||
|  | ||||
| - Bash Style Guide: https://www.daveeddy.com/bash/ | ||||
| - `shellcheck`: https://github.com/koalaman/shellcheck | ||||
|  | ||||
| ``` | ||||
| $ make check | ||||
| shellcheck rsm | ||||
| ``` | ||||
|  | ||||
| License | ||||
| ------- | ||||
|  | ||||
| MIT License | ||||
|   | ||||
							
								
								
									
										141
									
								
								rsm
									
									
									
									
									
								
							
							
						
						
									
										141
									
								
								rsm
									
									
									
									
									
								
							| @@ -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.4' | ||||
| RSM_VERSION='v1.4.4' | ||||
|  | ||||
| export SVDIR=${SVDIR:-/run/runit/service/} | ||||
| export LOGDIR="/var/log/" | ||||
| export RSVDIR="/run/runit/service/" | ||||
| export FLDIR=${FLDIR:-/etc/runit/sv/} | ||||
|  | ||||
|  | ||||
| charup='✔' | ||||
| chardown='X' | ||||
| @@ -115,14 +122,15 @@ usage() { | ||||
| 	logo=$(getlogo) | ||||
|  | ||||
| 	cat <<EOF | ||||
| $colormagenta ______   ____   _  _ | ||||
| $colormagenta | | \ \ / ___\ | \/ |  $colorgreen Runit Service Manager ($RSV_VERSION) | ||||
| $colormagenta | |_/ / \____  | || |  $colorgreen Source: https://github.com/bahamas10/vsv | ||||
| $colormagenta ______   ____  __  __ | ||||
| $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>] | ||||
| @@ -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 | ||||
| @@ -449,7 +461,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 +474,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 +484,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 +500,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 +613,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;; | ||||
| @@ -510,7 +623,7 @@ while getopts 'c:d:hltuvV' option; do | ||||
| 		t) tree=true; cmd='status';; | ||||
| 		u) SVDIR=~/runit/service;; | ||||
| 		v) ((verbosity++));; | ||||
| 		V) echo "$RSV_VERSION"; exit 0;; | ||||
| 		V) echo "$RSM_VERSION"; exit 0;; | ||||
| 		*) do_usage=1;; | ||||
| 	esac | ||||
| done | ||||
| @@ -540,6 +653,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'" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user