2015-08-08 21:04:55 -07:00
|
|
|
#!/bin/bash
|
|
|
|
|
2016-07-06 12:37:17 -07:00
|
|
|
# SVC - SV Commander - frontend for the sv command
|
2015-08-08 21:04:55 -07:00
|
|
|
|
|
|
|
###############################################################################################
|
|
|
|
## Copyright (c) 2015, Justin Moore
|
|
|
|
##
|
2016-07-06 12:37:17 -07:00
|
|
|
## Permission to use, copy, modify, and/or distribute this software
|
|
|
|
## for any purpose with or without fee is hereby granted,
|
2015-08-08 21:04:55 -07:00
|
|
|
## provided that the above copyright notice and this permission notice appear in all copies.
|
|
|
|
##
|
2016-07-06 12:37:17 -07:00
|
|
|
## 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,
|
2015-08-08 21:04:55 -07:00
|
|
|
## ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
##############################################################################################
|
2019-11-10 06:18:50 -07:00
|
|
|
RED='\033[0;31m'
|
|
|
|
LRED="\033[1;31m"
|
|
|
|
BLUE="\033[0;34m"
|
|
|
|
LBLUE="\033[1;34m"
|
|
|
|
GREEN="\033[0;32m"
|
|
|
|
LGREEN="\033[1;32m"
|
|
|
|
YELLOW="\033[1;33m"
|
|
|
|
CYAN="\033[0;36m"
|
|
|
|
LCYAN="\033[1;36m"
|
|
|
|
PURPLE="\033[0;35m"
|
|
|
|
LPURPLE="\033[1;35m"
|
|
|
|
BWHITE="\e[1m"
|
|
|
|
NC='\033[0m' # No Color
|
2015-08-08 21:04:55 -07:00
|
|
|
|
|
|
|
case $1 in
|
|
|
|
|
|
|
|
link | --link-service )
|
2019-11-10 06:20:16 -07:00
|
|
|
ln -v -s /etc/sv/"${2}" /var/service/
|
2015-08-08 21:04:55 -07:00
|
|
|
;;
|
|
|
|
|
|
|
|
unlink | --remove-service )
|
2019-11-10 06:20:16 -07:00
|
|
|
rm -v /var/service/"${2}"
|
2015-08-08 21:04:55 -07:00
|
|
|
;;
|
2016-07-06 12:37:17 -07:00
|
|
|
|
2015-08-08 21:04:55 -07:00
|
|
|
linked | --linked-services )
|
|
|
|
cd /etc/sv && find -xtype l -exec ls -l {} \;
|
|
|
|
;;
|
|
|
|
|
|
|
|
list | ls | --list )
|
|
|
|
|
|
|
|
echo
|
2019-11-10 06:18:50 -07:00
|
|
|
echo -e "${LGREEN}Contents of /etc/sv/${NC}\n"
|
2015-08-08 21:04:55 -07:00
|
|
|
ls /etc/sv
|
|
|
|
echo
|
2019-11-10 06:18:50 -07:00
|
|
|
echo -e "${LCYAN}Contents of /var/service${NC}\n"
|
2015-08-08 21:04:55 -07:00
|
|
|
echo
|
|
|
|
ls /var/service
|
|
|
|
echo
|
|
|
|
;;
|
|
|
|
|
|
|
|
up )
|
|
|
|
sv s /var/service/*
|
|
|
|
;;
|
|
|
|
|
|
|
|
start )
|
2019-11-10 06:18:50 -07:00
|
|
|
sv start "${2}"
|
2015-08-08 21:04:55 -07:00
|
|
|
;;
|
|
|
|
|
|
|
|
restart )
|
2019-11-10 06:18:50 -07:00
|
|
|
sv restart "${2}"
|
2015-08-08 21:04:55 -07:00
|
|
|
;;
|
|
|
|
|
|
|
|
stop )
|
2019-11-10 06:18:50 -07:00
|
|
|
sv stop "${2}"
|
2015-08-08 21:04:55 -07:00
|
|
|
;;
|
|
|
|
|
|
|
|
--help | -h | help )
|
|
|
|
echo
|
|
|
|
echo " sc - Service Commander - frontend for the sv command"
|
|
|
|
echo
|
|
|
|
echo " Usage: sc link | unlink | linked | list | up | start | restart | stop <service>"
|
|
|
|
echo
|
|
|
|
echo
|
|
|
|
echo " For detailed help, see the commands below:"
|
|
|
|
echo
|
|
|
|
echo
|
|
|
|
echo " help-all"
|
|
|
|
echo " help-link"
|
|
|
|
echo " help-unlink"
|
|
|
|
echo " help-linked"
|
|
|
|
echo " help-list"
|
|
|
|
echo " help-up"
|
|
|
|
echo " help-start"
|
|
|
|
echo " help-restart"
|
|
|
|
echo " help-stop"
|
|
|
|
echo
|
|
|
|
;;
|
|
|
|
|
|
|
|
help-link )
|
|
|
|
echo
|
|
|
|
echo "link : Creates a symlink from /etc/sv/<name> -> /var/service/<name>"
|
|
|
|
echo
|
|
|
|
;;
|
2016-07-06 12:37:17 -07:00
|
|
|
|
2015-08-08 21:04:55 -07:00
|
|
|
help-unlink )
|
|
|
|
echo
|
|
|
|
echo "unlink : Removes symlink from /etc/sv/<name> -> /var/service/<name>"
|
|
|
|
echo
|
|
|
|
;;
|
|
|
|
|
|
|
|
help-linked )
|
|
|
|
echo
|
|
|
|
echo "linked : Lists all symlinked items in /etc/sv"
|
|
|
|
echo
|
|
|
|
;;
|
|
|
|
|
|
|
|
help-list )
|
|
|
|
echo
|
|
|
|
echo "list : List the contents of /etc/sv and /var/service"
|
|
|
|
echo
|
|
|
|
;;
|
|
|
|
|
|
|
|
help-up )
|
|
|
|
echo
|
|
|
|
echo "up : Lists all currently running services"
|
|
|
|
echo
|
|
|
|
;;
|
|
|
|
|
|
|
|
help-start )
|
|
|
|
echo
|
|
|
|
echo "start : Uses the 'sv' command to start a service"
|
|
|
|
echo
|
|
|
|
;;
|
|
|
|
|
|
|
|
help-restart )
|
|
|
|
echo
|
|
|
|
echo "restart : Uses the 'sv' command to restart a service"
|
|
|
|
echo
|
|
|
|
;;
|
|
|
|
|
|
|
|
help-stop )
|
|
|
|
echo
|
|
|
|
echo "stop : Uses the 'sv' command to stop a service"
|
|
|
|
echo
|
|
|
|
;;
|
|
|
|
|
|
|
|
help-all )
|
|
|
|
echo
|
|
|
|
echo "link : Creates a symlink from /etc/sv/<name> -> /var/service/<name>"
|
|
|
|
echo "unlink : Removes symlink from /etc/sv/<name> -> /var/service/<name>"
|
|
|
|
echo "linked : Lists all symlinked items in /etc/sv"
|
|
|
|
echo "list : List the contents of /etc/sv and /var/service"
|
|
|
|
echo "up : Lists all currently running services"
|
|
|
|
echo "start : Uses the 'sv' command to start a service"
|
|
|
|
echo "restart : Uses the 'sv' command to restart a service"
|
|
|
|
echo "stop : Uses the 'sv' command to stop a service"
|
|
|
|
echo
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo
|
|
|
|
echo " sc - Service Commander - frontend for the sv command"
|
|
|
|
echo
|
|
|
|
echo " Usage: sc link | unlink | linked | list | up | start | restart | stop <service>"
|
|
|
|
echo
|
|
|
|
echo
|
|
|
|
echo " For detailed help, see the commands below:"
|
|
|
|
echo
|
|
|
|
echo
|
|
|
|
echo " help-all"
|
|
|
|
echo " help-link"
|
|
|
|
echo " help-unlink"
|
|
|
|
echo " help-linked"
|
|
|
|
echo " help-list"
|
|
|
|
echo " help-up"
|
|
|
|
echo " help-start"
|
|
|
|
echo " help-restart"
|
|
|
|
echo " help-stop"
|
|
|
|
echo
|
|
|
|
|
|
|
|
;;
|
|
|
|
esac
|