3 # Locate the service in the user's $SVDIR or /etc/sv
4 function find_service
{
6 svdir
=$
(svdir
2>/dev
/null
)
7 if [ -d "$svdir/../sv/$service" ];then
8 echo "$svdir/../sv/$service"
9 elif [ -d "$svdir/../Service/$service" ];then
10 echo "$svdir/../Service/$service"
11 elif [ -d "$svdir/../Services/$service" ];then
12 echo "$svdir/../Services/$service"
13 elif [ "$svdir" != "/etc/sv/$service" -a -d "/etc/sv/$service" ];then
14 echo "/etc/sv/$service"
18 # Set to user's $SVDIR or /service
21 #echo "using /service" >&2
24 #echo "using $SVDIR" >&2
30 # Add sudo if we don't own the directory in question
31 function check_owner
{
33 if [ ! -w $lndir ];then
38 # Symlink a service (from find_service's path to `svdir`/$service)
40 echo "Enabling $1" >&2
42 svdir
=$
(find_service
$service)
43 if [ -z "$svdir" -o ! -d "$svdir" ];then
44 echo "No such service '$service'" >&2
48 if [ -L "$ln_dir/$service" ];then
49 echo "Service already enabled!" >&2
50 echo " $(sv s $ln_dir/$service)" >&2
53 $
(check_owner
$ln_dir) ln -s $svdir $ln_dir
56 # Remove a symlink of a service (from find_service's path to `svdir`/$service)
58 echo "Disabling $1" >&2
61 if [ ! -L "$ln_dir/$service" ];then
62 echo "Service not enabled!" >&2
65 $
(check_owner
$ln_dir) rm $ln_dir/$service
68 # Generic list, of one service or all
72 $
(check_owner
$svdir) sv s
"$svdir/"$1
74 echo "Listing All Services"
75 $
(check_owner
$svdir) sv s
"$svdir/"*
83 sv-enable
) echo "sv-enable <service> - Enable a service and start it (will restart on boots)";;
84 sv-disable
) echo "sv-disable <service> - Disable a service from starting (also stop the service)";;
85 svls
) echo "svls [<service>] - Show list of services (Default: all services, pass a service name to see just one)";;
86 sv-find
) echo "sv-find <service> - Find a service, if it exists";;
87 sv-list
) echo "sv-list - List available services";;
88 *) echo "Invalid command (sv-list svls sv-find sv-enable sv-disable)";;
94 cmd
=$
(basename $0) # Get the command
97 while getopts h options
100 h
) echo $
(usage
$cmd)
106 sv-enable
) enable $@
;;
107 sv-disable
) disable $@
;;
109 sv-find
) find_service $@
;;
110 sv-list
) find $
(find_service
) -maxdepth 1 -mindepth 1 -type d
-exec basename {} \
; ;;