Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cat /etc/init.d/adergunov
- #! /bin/sh
- ### BEGIN INIT INFO
- # Provides: Adergunov
- # Default-Start: 2 3 4 5
- # Default-Stop: 0 1 6
- # Short-Description: Initscript for adergunov
- # Description: This file should be used to construct scripts for
- # adergunov to be placed in /etc/init.d.
- ### END INIT INFO
- # Author: Alexander Ivanov <alexander.vl.ivanov@gmail.com>
- # Do NOT "set -e"
- # PATH should only include /usr/* if it runs after the mountnfs.sh script
- PATH=/sbin:/usr/sbin:/bin:/usr/bin
- DESC="Daemon of the adergunov"
- NAME=adergunov
- RUN_DIR=/var/run/$NAME
- LOG_DIR=/var/log/$NAME
- UPLOAD_DIR=/srv/www/adergunov/media/upload
- PIDFILE=$RUN_DIR/$NAME.pid
- SOCKET=$RUN_DIR/$NAME.socket
- #HOST=127.0.0.1
- #PORT=8080
- RUN_AS_USER=www-data
- RUN_AS_GROUP=www-data
- DAEMON=/usr/bin/env
- # Don`t and spaces or new-lines to DAEMON_ARGS
- DAEMON_ARGS="python /srv/www/adergunov/bin/django runfcgi pidfile=$PIDFILE socket=$SOCKET outlog=$LOG_DIR/out.log errlog=$LOG_DIR/err.log minspare=1 maxspare=2 maxchildren=5"
- SCRIPTNAME=/etc/init.d/$NAME
- # Exit if the package is not installed
- [ -x "$DAEMON" ] || exit 0
- # Read configuration variable file if it is present
- [ -r /etc/default/$NAME ] && . /etc/default/$NAME
- # Load the VERBOSE setting and other rcS variables
- . /lib/init/vars.sh
- # Define LSB log_* functions.
- # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
- . /lib/lsb/init-functions
- #
- # Function that starts the daemon/service
- #
- do_start()
- {
- # Return
- # 0 if daemon has been started
- # 1 if daemon was already running
- # 2 if daemon could not be started
- if ( [ -f $PIDFILE ] && ps --pid $(cat $PIDFILE) > /dev/null ); then
- echo -n "$NAME already running."
- return 1
- else
- if [ -f $PIDFILE ]; then
- rm -f $PIDFILE
- fi
- # check directories and permissions
- mkdir -p $RUN_DIR $LOG_DIR $UPLOAD_DIR
- chown -R $RUN_AS_USER:$RUN_AS_GROUP $RUN_DIR $LOG_DIR
- chmod -R a-x,u=rwX,g=rX,o= $RUN_DIR $LOG_DIR
- find $UPLOAD_DIR ! -perm a-x,ug=rwX,o=rX -exec chmod a-x,ug=rwX,o=rX {} \;
- find $UPLOAD_DIR \( ! -user $RUN_AS_USER -or ! -group $RUN_AS_GROUP \) -exec chown $RUN_AS_USER:$RUN_AS_GROUP {} \;
- start-stop-daemon --start --quiet --pidfile $PIDFILE \
- --chuid ${RUN_AS_USER} --group ${RUN_AS_USER}\
- --exec $DAEMON -- $DAEMON_ARGS \
- || return 2
- fi
- }
- #
- # Function that stops the daemon/service
- #
- do_stop()
- {
- # Return
- # 0 if daemon has been stopped
- # 1 if daemon was already stopped
- # 2 if daemon could not be stopped
- # other if a failure occurred
- start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE
- RETVAL="$?"
- [ "$RETVAL" = 2 ] && return 2
- pkill -TERM -f "$DAEMON_ARGS" && sleep 5
- pkill -KILL -f "$DAEMON_ARGS" && sleep 1
- pgrep -f "$DAEMON_ARGS" && return 2
- # Many daemons don't delete their pidfiles when they exit.
- rm -f $PIDFILE
- return "$RETVAL"
- }
- #
- # Function that sends a SIGHUP to the daemon/service
- #
- do_reload() {
- #
- # If the daemon can reload its configuration without
- # restarting (for example, when it is sent a SIGHUP),
- # then implement that here.
- #
- start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE
- sleep 1
- do_start
- [ "$?" = 2 ] && return 2
- return 0
- }
- case "$1" in
- start)
- [ "$VERBOSE" != no ] && 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
- ;;
- reload)
- #
- # If do_reload() is not implemented then leave this commented out
- # and leave 'force-reload' as an alias for 'restart'.
- #
- do_reload
- log_end_msg $?
- ;;
- restart|force-reload)
- #
- # If the "reload" option is implemented then remove the
- # 'force-reload' alias
- #
- 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|restart|reload|force-reload}" >&2
- echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
- exit 3
- ;;
- esac
- :
Add Comment
Please, Sign In to add comment