Just wanting to share a script...
Here is a vnc server script (assumes vncserver is installed at /usr/local/bin/vncserver). Note: written for TightVNC 1.2.9 but should work for any vncserver):
Usage:
rc.vncserver start|stop [console_num]
-or-
rc.vncserver start_all|stop_all|status
First create a config file (/etc/rc.d/rc.vncserver.conf by default):
Code:
# configuration file for VNC
# format:
# number user options
1 someuser -name 1152 -geometry 1152x864
Then create the startup script (/etc/rc.d/rc.vncserver by default):
Code:
#!/bin/sh
CONF_FILE=/etc/rc.d/rc.vncserver.conf
if [ ! -f ${CONF_FILE} ] ; then
echo "Unable to find configuration file"
exit 1
fi
start_number()
{
VNCNUM=$1
LINE=`/usr/bin/cat ${CONF_FILE} | /usr/bin/grep -P "^${VNCNUM}\b"`
if [ "$LINE" = "" ] ; then
echo "No definition found for terminal ${VNCNUM}"
return 1
fi
RUN_AS_USER=`echo "${LINE}" | cut -d" " -f2`
# make sure the user exists
if ! /usr/bin/grep "${RUN_AS_USER}" /etc/passwd 1> /dev/null ; then
echo "No such user: ${RUN_AS_USER}"
return 2
fi
VNC_ARGS=`echo "${LINE}" | cut -d " " -f 3-15`
#echo "/bin/su - ${RUN_AS_USER} -c ""/usr/local/bin/vncserver :${VNCNUM} ${VNC_ARGS}"""
/bin/su - ${RUN_AS_USER} -c "/usr/local/bin/vncserver :${VNCNUM} ${VNC_ARGS}"
}
stop_number()
{
VNCNUM=$1
LINE=`/usr/bin/cat ${CONF_FILE} | /usr/bin/grep -P "^${VNCNUM}\b"`
if [ "$LINE" = "" ] ; then
echo "No definition found for terminal ${VNCNUM}"
return 1
fi
RUN_AS_USER=`echo "${LINE}" | cut -d" " -f2`
# make sure the user exists
if ! /usr/bin/grep "${RUN_AS_USER}" /etc/passwd 1> /dev/null ; then
echo "No such user: ${RUN_AS_USER}"
return 2
fi
VNC_ARGS=`echo "${LINE}" | cut -d " " -f 3-15`
#echo "/bin/su - ${RUN_AS_USER} -c ""/usr/local/bin/vncserver -kill :${VNCNUM}"""
if [ -f "/home/${RUN_AS_USER}/.vnc/linux:${VNCNUM}.pid" ] ; then
/bin/su - ${RUN_AS_USER} -c "/usr/local/bin/vncserver -kill :${VNCNUM}"
fi
}
status_number()
{
VNCNUM=$1
LINE=`/usr/bin/cat ${CONF_FILE} | /usr/bin/grep -P "^${VNCNUM}\b"`
if [ "$LINE" = "" ] ; then
echo "No definition found for terminal ${VNCNUM}"
return 1
fi
RUN_AS_USER=`echo "${LINE}" | cut -d" " -f2`
# make sure the user exists
if ! /usr/bin/grep "${RUN_AS_USER}" /etc/passwd 1> /dev/null ; then
echo "No such user: ${RUN_AS_USER}"
return 2
fi
VNC_ARGS=`echo "${LINE}" | cut -d " " -f 3-15`
if [ -f "/home/${RUN_AS_USER}/.vnc/linux:${VNCNUM}.pid" ] ; then
echo ":${VNCNUM} running as ${RUN_AS_USER}. PID: `cat /home/${RUN_AS_USER}/.vnc/linux:${VNCNUM}.pid`"
else
echo ":${VNCNUM} is not running"
fi
}
start_all()
{
for num in `/usr/bin/cat ${CONF_FILE} | /usr/bin/grep -v -P "^\s*#" | cut -d" " -f1` ; do
start_number $num
done
}
stop_all()
{
for num in `/usr/bin/cat ${CONF_FILE} | /usr/bin/grep -v -P "^\s*#" | cut -d" " -f1` ; do
stop_number $num
done
}
status()
{
for num in `/usr/bin/cat ${CONF_FILE} | /usr/bin/grep -v -P "^\s*#" | cut -d" " -f1` ; do
status_number $num
done
}
case "$1" in
'start')
if [ "$2" = "" ] ; then
echo "Console number missing"
exit 2
fi
start_number $2
;;
'start_all')
start_all
;;
'status')
status
;;
'stop_all')
stop_all
;;
'stop')
if [ "$2" = "" ] ; then
echo "Console number missing"
exit 2
fi
stop_number $2
;;
*)
echo "Usage:"
echo "rc.vncserver start|stop [console_num]"
echo " -or-"
echo "rc.vncserver start_all|stop_all|status"
exit 0
;;
esac
The *_all commands are not the best in performance since it searches the config file more than once, but it does not seem to hurt (I'm a better perl programmer then bash).
Enjoy