Created
August 30, 2010 09:56
-
-
Save moriyoshi/557242 to your computer and use it in GitHub Desktop.
This file contains 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 | |
# | |
# Init file for daemonized Skype service | |
# | |
### BEGIN INIT INFO | |
# Provides: skype | |
# Required-Start: $local_fs $remote_fs $network | |
# Required-Stop: $local_fs $remote_fs $network | |
# Default-Start: 3 4 5 | |
# Default-Stop: 0 1 2 6 | |
# X-Interactive: false | |
# Short-Description: Start/stop daemonized Skype service | |
### END INIT INFO | |
# | |
# chkconfig: 345 80 10 | |
# | |
# processname: skype | |
# | |
# pidfile: /var/run/skype.pid | |
# | |
if [ -r /etc/rc.d/init.d/functions ]; then | |
. /etc/rc.d/init.d/functions | |
log_daemon_msg() { | |
msg=$1 | |
prog=$2 | |
echo -n $"$msg $prog: " | |
} | |
log_end_msg() { | |
if [ "$1" = "0" ]; then | |
success | |
elif [ "$1" = "1" ]; then | |
failure | |
fi | |
echo | |
} | |
elif [ -r /lib/lsb/init-functions ]; then | |
. /lib/lsb/init-functions | |
else | |
echo "Could not find a helper script needed to run this script." | |
exit 1 | |
fi | |
DAEMON_USER=skype | |
PROGNAME=`basename $0` | |
PIDFILE=/var/run/skype.pid | |
XSERVERNUM=20 | |
XAUTHFILE=/var/run/skype/Xauthority | |
LOGFILE=/var/log/skype/error.log | |
DBPATH=/srv/skype/conf | |
XAUTHPROTO=. | |
SKYPE=/opt/skype/skype | |
USERNAME=echo123 | |
PASSWORD=blah | |
[ -f /etc/sysconfig/skype ] && . /etc/sysconfig/skype | |
prog="skype" | |
RETVAL=0 | |
dircheck() { | |
if [ ! -d `dirname "$1"` ]; then | |
echo "`dirname \"$1\"` does not exist" | |
return 1 | |
else | |
return 0 | |
fi | |
} | |
start() { | |
log_daemon_msg "Starting" "skype" | |
if ! dircheck "$LOGFILE" || ! dircheck "$XAUTHFILE"; then | |
log_end_msg 1 | |
echo | |
RETVAL=1 | |
return | |
fi | |
MCOOKIE=`mcookie` && \ | |
sudo -u "$DAEMON_USER" env XAUTHORITY=$XAUTHFILE sh -c "xauth add \":$XSERVERNUM\" \"$XAUTHPROTO\" \"$MCOOKIE\" >> \"$LOGFILE\" 2>&1" && \ | |
sudo -u "$DAEMON_USER" env XAUTHORITY=$XAUTHFILE sh -c "Xvfb :$XSERVERNUM -screen 0 800x600x8 -nolisten tcp >> \"$LOGFILE\" 2>&1 & echo \$!" >"$PIDFILE" && | |
sleep 3 && \ | |
(sudo -u "$DAEMON_USER" env DISPLAY=:$XSERVERNUM XAUTHORITY=$XAUTHFILE SKYPE="$SKYPE" sh -c "echo \"$USERNAME $PASSWORD\" | nohup \"$SKYPE\" --dbpath=\"$DBPATH\" --pipelogin &") >> "$LOGFILE" 2>&1 && \ | |
(log_end_msg 0 && [ -d /var/lock/subsys ] && touch /var/lock/subsys/skype || true) \ | |
|| (RETVAL=$?; kill -TERM `cat $PIDFILE`; log_end_msg 1) | |
} | |
stop() { | |
log_daemon_msg "Stopping" "skype" | |
if [ -e "$PIDFILE" ]; then | |
kill -TERM `cat $PIDFILE` && \ | |
rm -f $PIDFILE && \ | |
if [ -d /var/lock/subsys ]; then rm -f /var/lock/subsys/skype; fi && \ | |
log_end_msg 0 || log_end_msg 1 | |
else | |
log_end_msg 1 | |
RETVAL=1 | |
fi | |
} | |
usage() { | |
echo "Usage: $PROGNAME {start|stop|restart}" | |
} | |
case $1 in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
restart) | |
stop | |
start | |
;; | |
*) | |
usage | |
RETVAL=255 | |
;; | |
esac | |
exit $RETVAL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment