Last active
January 26, 2017 00:41
-
-
Save ysc3839/75eb3857f6005cb070ce56c1577eecc2 to your computer and use it in GitHub Desktop.
znc init
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 | |
ACTION=$1 | |
CALLER=$2 | |
ansi_red="\033[1;31m"; | |
ansi_white="\033[1;37m"; | |
ansi_green="\033[1;32m"; | |
ansi_yellow="\033[1;33m"; | |
ansi_blue="\033[1;34m"; | |
ansi_bell="\007"; | |
ansi_blink="\033[5m"; | |
ansi_std="\033[m"; | |
ansi_rev="\033[7m"; | |
ansi_ul="\033[4m"; | |
start() { | |
[ "$CRITICAL" != "yes" -a "$CALLER" = "cron" ] && return 7 | |
[ "$ENABLED" != "yes" ] && return 8 | |
echo -e -n "$ansi_white Starting $DESC... " | |
if [ -n "`pidof $PROC`" ]; then | |
echo -e " $ansi_yellow already running. $ansi_std" | |
return 0 | |
fi | |
$PRECMD > /dev/null 2>&1 | |
$PREARGS $PROC $ARGS > /dev/null 2>&1 & | |
#echo $PREARGS $PROC $ARGS | |
$POSTCMD_ > /dev/null 2>&1 | |
COUNTER=0 | |
LIMIT=35 | |
while [ -z "`pidof $PROC`" -a "$COUNTER" -le "$LIMIT" ]; do | |
sleep 1s; | |
COUNTER=`expr $COUNTER + 1` | |
done | |
$POSTCMD > /dev/null 2>&1 | |
if [ -z "`pidof $PROC`" ]; then | |
echo -e " $ansi_red failed. $ansi_std" | |
logger "Failed to start $DESC from $CALLER." | |
return 255 | |
else | |
echo -e " $ansi_green done. $ansi_std" | |
logger "Started $DESC from $CALLER." | |
return 0 | |
fi | |
} | |
stop() { | |
case "$ACTION" in | |
stop | restart) | |
echo -e -n "$ansi_white Shutting down $PROC... " | |
killall $PROC 2>/dev/null | |
COUNTER=0 | |
LIMIT=10 | |
while [ -n "`pidof $PROC`" -a "$COUNTER" -le "$LIMIT" ]; do | |
sleep 1s; | |
COUNTER=`expr $COUNTER + 1` | |
done | |
;; | |
kill) | |
echo -e -n "$ansi_white Killing $PROC... " | |
killall -9 $PROC 2>/dev/null | |
;; | |
esac | |
if [ -n "`pidof $PROC`" ]; then | |
echo -e " $ansi_red failed. $ansi_std" | |
return 255 | |
else | |
echo -e " $ansi_green done. $ansi_std" | |
return 0 | |
fi | |
} | |
check() { | |
echo -e -n "$ansi_white Checking $DESC... " | |
if [ -n "`pidof $PROC`" ]; then | |
echo -e " $ansi_green alive. $ansi_std"; | |
return 0 | |
else | |
echo -e " $ansi_red dead. $ansi_std"; | |
return 1 | |
fi | |
} | |
reconfigure() { | |
SIGNAL=SIGHUP | |
echo -e "$ansi_white Sending $SIGNAL to $PROC... " | |
killall -$SIGNAL $PROC 2>/dev/null | |
} | |
for PROC in $PROCS; do | |
case $ACTION in | |
start) | |
start | |
;; | |
stop | kill ) | |
check && stop | |
;; | |
restart) | |
check > /dev/null && stop | |
start | |
;; | |
check) | |
check | |
;; | |
reconfigure) | |
reconfigure | |
;; | |
*) | |
echo -e "$ansi_white Usage: $0 (start|stop|restart|check|kill|reconfigure)$ansi_std" | |
exit 1 | |
;; | |
esac | |
done |
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 | |
# Give a r\w permissions for "nobody" user | |
find /opt/share/znc/ -type f | xargs chmod 666 | |
find /opt/share/znc/ -type d | xargs chmod 777 | |
# Add droproot to znc.conf | |
CONF=/opt/share/znc/configs/znc.conf | |
grep -Fq "LoadModule = droproot" $CONF || echo "LoadModule = droproot nobody nogroup" >> $CONF | |
# Fix library | |
PRECMD="export LD_LIBRARY_PATH=/opt/lib" | |
POSTCMD_="unset LD_LIBRARY_PATH" | |
ENABLED=yes | |
PROCS=znc | |
ARGS="-d /opt/share/znc" | |
PREARGS="" | |
DESC=$PROCS | |
PATH=/opt/sbin:/opt/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin | |
LD_LIBRARY_PATH=/lib:/opt/lib | |
. /opt/etc/init.d/rc.func |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment