summaryrefslogtreecommitdiffstats
path: root/servers/admin_user_mgmt_server_lin/debian/ulab-adminusermgmtserver.init
blob: 45f26c4599c20b1f1488f2c3a532ae45c38095a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/bin/sh
### BEGIN INIT INFO
# Provides:          ulab-adminusermgmtserver
# Required-Start:    $local_fs $remote_fs
# Required-Stop:     $local_fs $remote_fs
# Should-Start:      console-screen kbd acpid hal krb5-kdc nis
# Should-Stop:       console-screen kbd
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: uLab System Administration User Management Server
# Description:       uLab System Administration User Management Server
### END INIT INFO
# /etc/init.d/ulab-adminusermgmtserver: start or stop the uLab System Administration User Management Server
#
# description: uLab System Administration User Management Server
#

. /lib/lsb/init-functions

set -e

PATH=/opt/trinity/bin:/usr/bin:/sbin:/usr/sbin
DAEMON=/opt/trinity/bin/remotefpga_adminsysctlserver
PIDFILE=/var/run/remotefpga_authserver.pid
UPGRADEFILE=/var/run/remotefpga_authserver.upgrade

DESC="uLab System Administration User Management Server"

# If we upgraded the daemon, we can't use the --exec argument to
# start-stop-daemon since the inode will have changed.  The risk here is that
# in a situation where the daemon died, its pidfile was not cleaned up, and
# some other process is now running under that pid, start-stop-daemon will send
# signals to an innocent process.  However, this seems like a corner case.
# C'est la vie!
if [ -e $UPGRADEFILE ]; then
  SSD_ARGS="--pidfile $PIDFILE --startas $DAEMON"
else
  SSD_ARGS="--pidfile $PIDFILE --exec $DAEMON"
fi

stillrunning () {
  if expr "$(cat /proc/$DAEMONPID/cmdline 2> /dev/null)" : "$DAEMON" > /dev/null 2>&1; then
    true
  else
    # if the daemon does not remove its own pidfile, we will
    rm -f $PIDFILE $UPGRADEFILE
    false
  fi;
}

case "$1" in
  start)
    log_action_begin_msg "Starting $DESC"
    if start-stop-daemon --background --start --make-pidfile --quiet $SSD_ARGS -- $ARG; then
      log_action_end_msg 0
    else
      log_warning_msg "already running"
      log_action_end_msg 0
    fi
  ;;

  restart)
    /etc/init.d/ulab-adminusermgmtserver stop
    if [ -f $PIDFILE ]; then
      if stillrunning; then
        exit 1
      fi
    fi
    /etc/init.d/ulab-adminusermgmtserver start
  ;;

  reload)
    log_action_begin_msg "Reloading $DESC"
    if start-stop-daemon --stop --signal 1 --quiet $SSD_ARGS; then
      log_action_end_msg 0
    else
      log_failure_msg "not running"
      log_action_end_msg 1
    fi
  ;;

  force-reload)
    /etc/init.d/ulab-adminusermgmtserver reload
  ;;

  stop)
    log_action_begin_msg "Stopping $DESC"
    if [ ! -f $PIDFILE ]; then
      log_failure_msg "Not running ($PIDFILE not found)"
      log_action_end_msg 0
      exit 0
    else
      if start-stop-daemon --stop --quiet $SSD_ARGS; then
        log_action_end_msg 0
      else
        log_failure_msg "not running"
        log_action_end_msg 1
      fi
    fi
  ;;

  *)
    echo "Usage: /etc/init.d/ulab-adminusermgmtserver {start|stop|restart|reload|force-reload}"
    exit 1
    ;;
esac

exit 0