Created
November 1, 2011 08:33
-
-
Save ellisgeek/1330156 to your computer and use it in GitHub Desktop.
Webshell init.d
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/sh | |
### BEGIN INIT INFO | |
# Provides: webshell | |
# Default-Start: S 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
### END INIT INFO | |
set -e | |
WEBSHELL=/usr/sbin/webshell/webshell.py | |
#WEBSHELL_CERT=/etc/apache2/sitecert.pem | |
SHELL_CMD="ssh -2 -i /etc/ssh/keys/blake/private_keys/sshkey | |
blake@localhost" | |
if [[ ! -x $WEBSHELL ]] ; then | |
echo "Webshell not installed." | |
exit 0 | |
fi | |
#if [[ ! -r $WEBSHELL_CERT ]]; then | |
# echo -e "Webshell SSL certificate not found:\n\t$WEBSHELL_CERT | |
\nPlease modify /etc/init.d/webshell or create the SSL certificate." | |
# exit 0 | |
#fi | |
. /lib/lsb/init-functions | |
start() | |
{ | |
isRunning | |
if [[ $ISRUNNING == 0 ]] | |
then | |
echo -p 9327 -c \"$SHELL_CMD\" -d --ssl-disable | xargs $WEBSHELL | |
#echo -p 9327 -c \"$SHELL_CMD\" -d --ssl-cert=\"$WEBSHELL_CERT\" | | |
xargs $WEBSHELL | |
else | |
echo -e -n "\nWebshell is already running" | |
fi | |
isRunning | |
if [[ $ISRUNNING == 0 ]] | |
then | |
return 1 | |
else | |
return 0 | |
fi | |
} | |
stop() | |
{ | |
isRunning | |
if [[ $ISRUNNING > 0 ]]; then | |
if [ -r /var/run/webshell.pid ]; then | |
cat /var/run/webshell.pid | xargs kill | |
rm /var/run/webshell.pid | |
else | |
echo -e "\nPID file not found. Attempting to kill process..." | |
ps -C webshell.py -o pid= | xargs kill | |
fi | |
else | |
echo -e -n "\nWebshell process not found." | |
fi | |
isRunning | |
if [[ $ISRUNNING > 0 ]]; then | |
return 1 | |
else | |
return 0 | |
fi | |
} | |
isRunning() | |
{ | |
ISRUNNING=`ps -C webshell.py -o pid= | grep --count ^.*$` | |
} | |
case "$1" in | |
start) | |
log_begin_msg "Starting web shell (webshell.py)..." | |
if start; then | |
echo -e -n "\nDone" | |
log_end_msg 0 | |
else | |
log_end_msg 1 | |
fi | |
;; | |
stop) | |
log_begin_msg "Stopping web shell (webshell.py)..." | |
if stop; then | |
echo -e -n "\nDone" | |
log_end_msg 0 | |
else | |
log_end_msg 1 | |
fi | |
;; | |
reload|restart|force-reload) | |
log_begin_msg "Restarting web shell (webshell.py)..." | |
if stop; then | |
if start; then | |
echo -e -n "\nDone" | |
log_end_msg 0 | |
else | |
log_end_msg 1 | |
fi | |
else | |
log_end_msg 1 | |
fi | |
;; | |
*) | |
echo "Usage: $N {start|stop|restart|force-reload}" >&2 | |
exit 1 | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment