Created
May 14, 2014 21:04
-
-
Save tongpu/2aa15ee1743401c86f2b to your computer and use it in GitHub Desktop.
Taskserver Init and Logrotate configuration for Debian
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: taskd | |
# Required-Start: $local_fs $remote_fs $network $syslog | |
# Required-Stop: $local_fs $remote_fs $network $syslog | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: Starts Taskserver | |
# Description: Starts Taskserver using start-stop-daemon | |
### END INIT INFO | |
# Author: Lukas Grossar <[email protected]> | |
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin | |
DESC="Taskserver" | |
NAME=taskd | |
TASKDDATA=/opt/taskd | |
DAEMON=/usr/local/bin/$NAME | |
DAEMON_ARGS="server --data $TASKDDATA --daemon" | |
PIDFILE=/var/run/$NAME/$NAME.pid | |
SCRIPTNAME=/etc/init.d/$NAME | |
[ -x "$DAEMON" ] || exit 0 | |
. /lib/lsb/init-functions | |
check_run_dir() { | |
if [ ! -d /var/run/$NAME ]; then | |
mkdir /var/run/$NAME | |
chmod 0755 /var/run/$NAME | |
chown taskd:taskd /var/run/$NAME | |
fi | |
} | |
check_log_dir() { | |
if [ ! -d /var/log/$NAME ]; then | |
mkdir /var/log/$NAME | |
chmod 0755 /var/log/$NAME | |
chown taskd:adm /var/log/$NAME | |
fi | |
} | |
do_start() | |
{ | |
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \ | |
|| return 1 | |
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \ | |
$DAEMON_ARGS \ | |
|| return 2 | |
} | |
do_stop() | |
{ | |
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME | |
RETVAL="$?" | |
[ "$RETVAL" = 2 ] && return 2 | |
rm -f $PIDFILE | |
return "$RETVAL" | |
} | |
do_reload() { | |
start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME | |
return 0 | |
} | |
case "$1" in | |
start) | |
check_run_dir | |
check_log_dir | |
log_daemon_msg "Starting $DESC" "$NAME" | |
do_start | |
case "$?" in | |
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; | |
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; | |
esac | |
;; | |
stop) | |
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" | |
do_stop | |
case "$?" in | |
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; | |
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; | |
esac | |
;; | |
status) | |
status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $? | |
;; | |
reload|force-reload) | |
log_daemon_msg "Reloading $DESC" "$NAME" | |
do_reload | |
log_end_msg $? | |
;; | |
restart) | |
log_daemon_msg "Restarting $DESC" "$NAME" | |
do_stop | |
case "$?" in | |
0|1) | |
do_start | |
case "$?" in | |
0) log_end_msg 0 ;; | |
1) log_end_msg 1 ;; # Old process is still running | |
*) log_end_msg 1 ;; # Failed to start | |
esac | |
;; | |
*) | |
# Failed to stop | |
log_end_msg 1 | |
;; | |
esac | |
;; | |
*) | |
echo "Usage: $SCRIPTNAME {start|stop|status|restart|reload|force-reload}" >&2 | |
exit 3 | |
;; | |
esac |
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
/var/log/taskd/taskd.log { | |
weekly | |
missingok | |
rotate 4 | |
compress | |
delaycompress | |
notifempty | |
create 0640 taskd adm | |
postrotate | |
[ ! -f /var/run/taskd/taskd.pid ] || kill -USR1 `cat /var/run/taskd/taskd.pid` | |
endscript | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment