-
-
Save bborysenko/c2b58b593b3c813b2171 to your computer and use it in GitHub Desktop.
Xvfb init script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # xvfb - this script starts and stops Xvfb | |
| # | |
| # chkconfig: 345 95 50 | |
| # description: Starts xvfb on display 99 | |
| # processname: Xvfb | |
| # pidfile: /var/log/xvfb/xvfb.pid | |
| # Source function library. | |
| . /etc/rc.d/init.d/functions | |
| log_dir=/var/log/xvfb | |
| error_log=$log_dir/xvfb_error.log | |
| std_log=$log_dir/xvfb_std.log | |
| pid_file=$log_dir/xvfb.pid | |
| xvfb=$( which Xvfb ) | |
| user=YOUR_USER | |
| screen_options=":99 -ac -screen 0 1024x768x8" | |
| start() { | |
| if test -f $pid_file | |
| then | |
| PID=`cat $pid_file` | |
| if ps --pid $PID >/dev/null; | |
| then | |
| echo "Xvfb is already running: $PID" | |
| exit 0 | |
| else | |
| echo "Removing stale pid file: $pid_file" | |
| fi | |
| fi | |
| echo -n "Starting Xvfb..." | |
| su $user -c "$xvfb $screen_options -nolisten tcp >$std_log 2>$error_log &" | |
| if [ $? == "0" ]; then | |
| success | |
| else | |
| failure | |
| fi | |
| echo | |
| ps -C Xvfb -o pid,cmd | grep Xvfb | awk {'print $1 '} > $pid_file | |
| } | |
| stop() { | |
| if test -f $pid_file | |
| then | |
| echo -n "Stopping Xvfb..." | |
| PID=`cat $pid_file` | |
| su $user -c "kill -15 $PID" | |
| if kill -9 $PID ; | |
| then | |
| sleep 2 | |
| test -f $pid_file && rm -f $pid_file | |
| success | |
| else | |
| echo "Xvfb could not be stopped..." | |
| failure | |
| fi | |
| else | |
| echo "Xvfb is not running." | |
| failure | |
| fi | |
| echo | |
| } | |
| status() { | |
| if test -f $pid_file | |
| then | |
| PID=`cat $pid_file` | |
| if ps --pid $PID >/dev/null ; | |
| then | |
| echo "Xvfb is running...$PID" | |
| else | |
| echo "Xvfb isn't running..." | |
| fi | |
| else | |
| echo "Xvfb isn't running..." | |
| fi | |
| } | |
| case "$1" in | |
| start) | |
| $1 | |
| ;; | |
| stop) | |
| $1 | |
| ;; | |
| restart) | |
| stop | |
| start | |
| ;; | |
| status) | |
| $1 | |
| ;; | |
| *) | |
| echo "Usage: $SELF start|stop|restart|status" | |
| exit 1 | |
| ;; | |
| esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment