90 lines
2.3 KiB
Plaintext
90 lines
2.3 KiB
Plaintext
|
#!/sbin/runscript
|
||
|
# Ilya Dmitrichenko < errordeveloper - at -at- g m a i l -dot- com
|
||
|
# Distributed under the terms of the GNU General Public License v2
|
||
|
|
||
|
# Originally written for Gentoo, but should work on other platforms :)
|
||
|
# http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=2&chap=4
|
||
|
|
||
|
depend() {
|
||
|
use net debug
|
||
|
}
|
||
|
|
||
|
start() {
|
||
|
|
||
|
## SVCNAME is the name of this file in /etc/init.d/
|
||
|
## so one can creat /etc/extra-screens.d/ and put
|
||
|
## the screenrc files there, then simlink the files
|
||
|
## /etc/init.d/screen -> /etc/init.d/extra-screens
|
||
|
for SCREENRC in /etc/${SVCNAME}.d/* ; do
|
||
|
|
||
|
SESSION="$(basename $SCREENRC)"
|
||
|
|
||
|
## I don't think there may be a security issue,
|
||
|
## provided that users will not be have write
|
||
|
## permission in /etc/screen.d/ and if anyone
|
||
|
## gained access to mod the session file, they
|
||
|
## are in already anyhow!
|
||
|
BELONGS="$(stat $SCREENRC --printf=%U)"
|
||
|
|
||
|
MYSHELL="$(getent passwd $BELONGS | cut -d: -f7)"
|
||
|
|
||
|
|
||
|
COMMAND="/usr/bin/screen -- -U -D -m -c ${SCREENRC} -S ${SESSION} -t ${SESSION}"
|
||
|
|
||
|
## Why on earth would one write this ???
|
||
|
#HOMEDIR="$(getent passwd $BELONGS | cut -d: -f6)"
|
||
|
|
||
|
ebegin "Starting ${SVCNAME} session ${SESSION} for ${BELONGS}"
|
||
|
|
||
|
PIDFILE="/var/run/${SVCNAME}.${BELONGS}.${SESSION}.pid"
|
||
|
|
||
|
start-stop-daemon \
|
||
|
--env TERM="rxvt" \
|
||
|
--env HOME="~${BELONGS}" \
|
||
|
--env SHELL="${MYSHELL}" \
|
||
|
--env SCREEN_SESSION=${SESSION} \
|
||
|
--user $BELONGS \
|
||
|
--chdir "~${BELONGS}" \
|
||
|
--make-pidfile \
|
||
|
--background \
|
||
|
--pidfile=${PIDFILE} \
|
||
|
--exec ${COMMAND}
|
||
|
eend $?
|
||
|
done
|
||
|
|
||
|
#screen -li || /bin/true
|
||
|
}
|
||
|
|
||
|
stop() {
|
||
|
|
||
|
## Perhaps we should determin this by pidfiles ...
|
||
|
## but this way is not bad either!
|
||
|
for SCREENRC in /etc/${SVCNAME}.d/* ; do
|
||
|
|
||
|
SESSION="$(basename $SCREENRC)"
|
||
|
BELONGS="$(stat $SCREENRC --printf=%U)"
|
||
|
|
||
|
PIDFILE="/var/run/${SVCNAME}.${BELONGS}.${SESSION}.pid"
|
||
|
PROCESS="$(cat ${PIDFILE})"
|
||
|
|
||
|
if [ -e /proc/${PROCESS}/status ]; then
|
||
|
|
||
|
grep -i "Name:" /proc/${PROCESS}/status | grep -iq "screen" || continue
|
||
|
|
||
|
ebegin "Stopping ${SVCNAME} session ${SESSION} for ${BELONGS} (PID: ${PROCESS})"
|
||
|
|
||
|
## It will CERTAINly kill the righ screen!
|
||
|
CERTAIN="${PROCESS}.${SESSION}"
|
||
|
env TERM="urxvt" \
|
||
|
start-stop-daemon \
|
||
|
--user ${BELONGS} \
|
||
|
--exec /usr/bin/screen -- -S $CERTAIN -X quit
|
||
|
eend $?
|
||
|
|
||
|
fi
|
||
|
|
||
|
rm -f $PIDFILE
|
||
|
|
||
|
done
|
||
|
}
|