Skip to content

Instantly share code, notes, and snippets.

@motchang
Last active June 17, 2016 07:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save motchang/b1a3d265bb2a7fe5cd6be1de0a43af24 to your computer and use it in GitHub Desktop.
Save motchang/b1a3d265bb2a7fe5cd6be1de0a43af24 to your computer and use it in GitHub Desktop.
/etc/init.d/xvfb
#!/bin/bash
#
# Xvfb
#
# chkconfig: - 90 30
# description: Xvfb
# Source function library.
. /etc/init.d/functions
lockfile="/var/lock/subsys/xvfb"
pidfile="/var/run/xvfb.pid"
logfile="/var/log/xvfb.log"
prog="Xvfb"
USER=root
XVFB=/usr/bin/Xvfb
OPTION=":99 -screen 0 1024x768x8"
RETVAL=0
start() {
# http://superuser.com/questions/870702/aws-ec2-linux-headless-firefox-issue-xvfb-undefined-symbol-pixman-glyph-cache
if [ -f "/usr/local/lib/libpixman-1.so.0" ]
then
nm -g /usr/local/lib/libpixman-1.so.0 | grep -q pixman_glyph_cache_create
sym_exist=$?
if [ ${sym_exist} -ne 0 ]
then
rm -f /usr/local/lib/libpixman-1.so.0
fi
fi
echo -n $"Starting ${prog}: "
sudo -u ${USER} ${XVFB} ${OPTION} >> ${logfile} 2>&1 &
RETVAL=$?
pid=$!
echo ${pid} > ${pidfile}
[ ${RETVAL} -eq 0 ] && echo_success || echo_failure
echo
[ ${RETVAL} -eq 0 ] && touch ${lockfile}
return ${RETVAL}
}
stop() {
echo -n $"Stopping ${prog}: "
killproc -p ${pidfile} ${prog}
RETVAL=$?
echo
[ ${RETVAL} -eq 0 ] && rm -f ${lockfile} ${pidfile}
return ${RETVAL}
}
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status -p ${pidfile} ${prog}
RETVAL=$?
;;
restart)
restart
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment