Created
July 7, 2013 07:33
-
-
Save mitsutaka/5942681 to your computer and use it in GitHub Desktop.
Aerofs init script for linux
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 | |
USER=mitz | |
PATH=/sbin:/usr/sbin:/bin:/usr/bin | |
DESC="Aerofs CLI Client" | |
NAME=aerofs | |
START_DAEMON="/usr/bin/aerofs-cli" | |
STOP_DAEMON="/usr/bin/aerofs-sh shutdown" | |
PIDFILE=/var/run/$NAME.pid | |
SCRIPTNAME=/etc/init.d/$NAME | |
# Exit if the package is not installed | |
[ -x "$START_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() | |
{ | |
su -s /bin/sh -c "${START_DAEMON} ${DAEMON_ARGS} 2>&1 | logger" ${USER} & | |
} | |
# | |
# Function that stops the daemon/service | |
# | |
do_stop() | |
{ | |
su -s /bin/sh -c "${STOP_DAEMON} ${DAEMON_ARGS} 2>&1 | logger" ${USER} | |
} | |
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 | |
;; | |
status) | |
status_of_proc "$START_DAEMON" "$NAME" && exit 0 || exit $? | |
;; | |
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}" >&2 | |
exit 3 | |
;; | |
esac | |
: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment