/usr/sbin/svsetup is in svtools 0.6-2.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | #!/bin/sh
#
# svsetup
# Service setup tool for daemontools
# Klaus Reimer <k@ailis.de>
TITLE=svsetup
VERSION=0.6
AUTHOR="Klaus Reimer"
EMAIL=k@ailis.de
COPYRIGHT="Copyright (C) 2000-2011 by $AUTHOR"
SVCUSER=root
DELSVCUSER=0
LOGUSER=root
DELLOGUSER=0
DONTLOG=0
showHelp() {
echo "Usage: $TITLE [OPTION]... CMD SERVICE"
echo "Service setup tool for daemontools"
echo ""
echo " -u USER Specify service user name (Default: $SVCUSER)"
echo " -l USER Specify log user name (Default: $LOGUSER)"
echo " -n Do not setup logging with multilog"
echo " -e ETCDIR Specify cfg directory (Default: /etc/sv/SERVICE)"
echo " -L LOGDIR Specify log directory (Default: /var/log/sv/SERVICE)"
echo " -s SERVICEDIR Specify service directory (Default: automatically"
echo " detected)"
echo " -d Delete service user on removal"
echo " -D Delete log user on removal"
echo " -h, --help Display help and exit"
echo " -V, --version Display version and exit"
echo ""
echo " CMD Specifies action to perform:"
echo " CREATE Create new service"
echo " REMOVE Delete existing service"
echo " ENABLE Enable service"
echo " DISABLE Disable service"
echo ""
echo " SERVICE Specifies the service name"
echo ""
echo "NOTE: If you REMOVE a service and specify a service user (with -u)"
echo "and/or a log user (with -l) these users (except root) are removed, too,"
echo "if you also specify the option -d and/or -D! This happens without any"
echo "confirmation requests and the users are deleted even if they were not"
echo "created by svsetup!"
echo ""
echo "If you create a new service a default run script is created. If"
echo "there is already a run script in ETCDIR this existing runscript is used"
echo "instead."
echo ""
echo "Report bugs to $AUTHOR <$EMAIL>"
}
showVersion() {
echo "$TITLE $VERSION"
echo ""
echo "$COPYRIGHT"
echo "This is free software; you can redistribute it and/or modify it under"
echo "the terms of the GNU General Public License as published by the Free"
echo "Software Foundation; either version 2 of the License, or (at your"
echo "option) any later version."
}
while getopts ":hVu:l:e:L:s:n-:dD" NAME
do
case "$NAME" in
d)
DELSVCUSER=1
;;
D)
DELLOGUSER=1
;;
u)
SVCUSER=$OPTARG
;;
l)
LOGUSER=$OPTARG
;;
n)
DONTLOG=1
;;
e)
ETCDIR=$OPTARG
;;
L)
LOGDIR=$OPTARG
;;
h)
showHelp
exit 0
;;
V)
showVersion
exit 0
;;
-)
case "$OPTARG" in
help)
showHelp
exit 0
;;
version)
showVersion
exit 0
;;
*)
echo "Unknown option: $OPTARG"
showHelp
exit 1
esac
;;
*)
echo "Unknown option: $OPTARG"
showHelp
exit 1
esac
done
shift `expr $OPTIND - 1`
if [ $# -ne 2 ]
then
showHelp
exit 1
fi
ACTION=$1
SERVICE=$2
if [ "$ETCDIR" = "" ]; then ETCDIR="/etc/sv/$SERVICE"; fi
if [ "$LOGDIR" = "" ]; then LOGDIR="/var/log/sv/$SERVICE"; fi
if [ "$SVDIR" = "" ]
then
if ! SVDIR=`svdir 2>&1`
then
echo "$TITLE: $SVDIR" >&2
exit 1
fi
fi
case "$ACTION" in
CREATE|create)
if ! grep -q "^$SVCUSER:" /etc/passwd
then
adduser --quiet --system --no-create-home --disabled-password --home $ETCDIR --gecos "Daemontools service" $SVCUSER
fi
if [ $DONTLOG -eq 0 ] && ! grep -q "^$LOGUSER:" /etc/passwd
then
adduser --quiet --system --no-create-home --disabled-password --home $LOGDIR --gecos "Daemontools service logging" $LOGUSER
fi
if [ ! -d $ETCDIR ]
then
install -d -o root -g root -m 0755 $ETCDIR
fi
if [ ! -f $ETCDIR/run ]
then
echo "#!/bin/sh" > $ETCDIR/run
echo "exec 2>&1" >> $ETCDIR/run
echo "exec setuidgid $SVCUSER $SERVICE" >> $ETCDIR/run
fi
chmod +x $ETCDIR/run
if [ $DONTLOG -eq 0 ]
then
install -d -o $LOGUSER -g root -m 0750 $LOGDIR
install -d -o root -g root -m 0755 $ETCDIR/log
if [ ! -e $ETCDIR/log/main ]
then
ln -sf $LOGDIR $ETCDIR/log/main
fi
echo "#!/bin/sh" > $ETCDIR/log/run
echo "exec setuidgid $LOGUSER multilog t ./main" >> $ETCDIR/log/run
chmod +x $ETCDIR/log/run
chmod +t $ETCDIR
fi
;;
REMOVE|remove)
rm -f $SVDIR/$SERVICE
svc -dx $ETCDIR/log 2>/dev/null
svc -dx $ETCDIR 2>/dev/null
rm -rf $ETCDIR/log $ETCDIR/supervise $LOGDIR
if [ $DELSVCUSER -eq 1 ] && [ "$SVCUSER" != "root" ]; then userdel $SVCUSER 2>/dev/null; fi
if [ $DELLOGUSER -eq 1 ] && [ "$LOGUSER" != "root" ]; then userdel $LOGUSER 2>/dev/null; fi
;;
ENABLE|enable)
if [ ! -e $SVDIR/$SERVICE ]
then
ln -sf $ETCDIR $SVDIR/$SERVICE
fi
;;
DISABLE|disable)
rm -f $SVDIR/$SERVICE
svc -dx $ETCDIR/log 2>/dev/null
svc -dx $ETCDIR
;;
*)
echo "Unknown command: $ACTION"
showHelp
exit 1
esac
exit 0
|