source: trunk/debathena/debathena/pyhesiodfs/debian/debathena-pyhesiodfs.init @ 24948

Revision 24948, 3.8 KB checked in by geofft, 14 years ago (diff)
In pyhesiodfs: * Set /proc/$pid/oom_adj to -17 (never OOM kill this process). Code loosely adapted from ssh's initscript.
RevLine 
[23151]1#! /bin/sh
[23080]2### BEGIN INIT INFO
[23151]3# Provides:          debathena-pyhesiodfs
4# Required-Start:    openafs-client
5# Required-Stop:     openafs-client
6# Should-Start:      $local_fs $network
7# Default-Start:     2 3 4 5
8# Default-Stop:      0 1 6
9# Short-Description: Hesiod automounter for Athena lockers
10# Description:       Auto-create symlinks from /mit/LOCKER to AFS using Hesiod lookups.
[23080]11### END INIT INFO
12
[23151]13# Author: Evan Broder <broder@mit.edu>, Geoffrey Thomas <geofft@mit.edu>
14
15# Do NOT "set -e"
16
17# PATH should only include /usr/* if it runs after the mountnfs.sh script
18PATH=/sbin:/usr/sbin:/bin:/usr/bin
19DESC="Debathena /mit automounter"
[23080]20NAME=debathena-pyhesiodfs
[23151]21DAEMON=/usr/bin/pyhesiodfs
[23080]22pyhesiodfs_dir="/mit"
[24219]23DAEMON_ARGS="-f $pyhesiodfs_dir -o nonempty"
[23151]24PIDFILE=/var/run/$NAME.pid
25SCRIPTNAME=/etc/init.d/$NAME
[24948]26oom_adj=-17
[23080]27
[23151]28# Exit if the package is not installed
29[ -x "$DAEMON" ] || exit 0
[23080]30
[23151]31# Read configuration variable file if it is present
32[ -r /etc/default/$NAME ] && . /etc/default/$NAME
[23080]33
[24948]34
35# Are we in a virtual environment that doesn't support modifying
36# /proc/self/oom_adj?
37if grep -q 'envID:.*[1-9]' /proc/self/status; then
38    unset oom_adj
39fi
40
[23151]41# Load the VERBOSE setting and other rcS variables
[23235]42: ${VERBOSE:=yes}
[23237]43if [ -f /lib/init/vars.sh ]; then
[23235]44    . /lib/init/vars.sh
45elif [ -f /etc/default/rcS ]; then
46    . /etc/default/rcS
47fi
[23151]48
49# Define LSB log_* functions.
50# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
51. /lib/lsb/init-functions
52
53#
54# Function that starts the daemon/service
55#
56do_start()
57{
58    # Return
59    #   0 if daemon has been started
60    #   1 if daemon was already running
61    #   2 if daemon could not be started
62   
63    # Try to make sure fuse is setup
64    [ -e /dev/fuse ] || modprobe fuse || return 2
65   
66    if cat /proc/mounts | grep " $pyhesiodfs_dir " >/dev/null 2>&1; then
67        return 1
68    fi
69   
70    mkdir -p "$pyhesiodfs_dir"
71    chown root:pyhesiodfs "$pyhesiodfs_dir"
72    chmod 770 "$pyhesiodfs_dir"
73   
74    start-stop-daemon --start --quiet --pidfile $PIDFILE \
75        --chuid pyhesiodfs:pyhesiodfs --background \
76        --make-pidfile \
77        --exec $DAEMON -- \
78        $DAEMON_ARGS \
79        || return 2
[24948]80
81    if [ -n "$oom_adj" ] && [ -w /proc/"$(cat "$PIDFILE")"/oom_adj ]; then
82        echo "$oom_adj" > /proc/"$(cat "$PIDFILE")"/oom_adj
83    fi
[23151]84}
85
86#
87# Function that stops the daemon/service
88#
89do_stop()
90{
91    # Return
92    #   0 if daemon has been stopped
93    #   1 if daemon was already stopped
94    #   2 if daemon could not be stopped
95    #   other if a failure occurred
96   
97    if cat /proc/mounts | grep " $pyhesiodfs_dir " >/dev/null 2>&1; then
98        umount -l "$pyhesiodfs_dir" || return 2
99        # Many daemons don't delete their pidfiles when they exit.
100        rm -f "$PIDFILE"
101    else
102        return 1
103    fi
104}
105
[23080]106case "$1" in
[23151]107    start)
108        [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
109        do_start
110        case "$?" in
111            0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
112            2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
113        esac
114        ;;
115    stop)
116        [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
117        do_stop
118        case "$?" in
119            0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
120            2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
121        esac
122        ;;
123    restart|force-reload)
124        log_daemon_msg "Restarting $DESC" "$NAME"
125        do_stop
126        case "$?" in
127            0|1)
128                do_start
129                case "$?" in
130                    0) log_end_msg 0 ;;
131                    1) log_end_msg 1 ;; # Old process is still running
132                    *) log_end_msg 1 ;; # Failed to start
133                esac
134                ;;
135            *)
136                # Failed to stop
137                log_end_msg 1
138                ;;
139        esac
140        ;;
141    *)
142        echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
143        exit 3
144        ;;
[23080]145esac
146
[23151]147:
Note: See TracBrowser for help on using the repository browser.