forked from mesos/chronos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chronos.debian.init
executable file
·103 lines (95 loc) · 3.72 KB
/
chronos.debian.init
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
#!/bin/sh
# Start/stop the chronos.
#
### BEGIN INIT INFO
# Provides: chronos
# Required-Start: $remote_fs $syslog $time
# Required-Stop: $remote_fs $syslog $time
# Should-Start: $network $named slapd autofs ypbind nscd nslcd
# Should-Stop: $network $named slapd autofs ypbind nscd nslcd
# Default-Start: 2 3 4 5
# Default-Stop:
# Short-Description: chronos is airbnb's replacement for cron.
# Description: chronos is a distributed and fault-tolerant scheduler
# which runs on top of mesos. It's a framework and supports
# custom mesos executors as well as the default command
# executor. Thus by default, Chronos executes sh (on most
# systems bash) scripts. Chronos can be used to interact
# with systems such as Hadoop (incl. EMR), even if the
# mesos slaves on which execution happens do not have
# Hadoop installed. Included wrapper scripts allow
# transfering files and executing them on a remote machine
# in the background and using asynchronous callbacks to
# notify Chronos of job completion or failures.
# See https://github.com/airbnb/chronos for more info.
### END INIT INFO
PATH=/bin:/usr/bin:/sbin:/usr/sbin
DESC="chronos daemon"
NAME=chronos
DAEMON=/usr/bin/java
PIDFILE=/var/run/${NAME}.pid
SCRIPTNAME=$0
# set these to match your environment
CHRONOS_HOME=/home/asemenov/chronos
MESOS_HOME=/opt/mesos
if [ "$(id -u)" -ne "0" ]; then
echo "you must be root to start ${DESC}"
exit 1
fi
. /lib/lsb/init-functions
[ -r /etc/default/chronos ] && . /etc/default/chronos
# Read the system's locale and set cron's locale. This is only used for
# setting the charset of mails generated by cron. To provide locale
# information to tasks running under cron, see /etc/pam.d/cron.
#
# We read /etc/environment, but warn about locale information in
# there because it should be in /etc/default/locale.
set_environment () {
libmesos_file=$(find ${MESOS_HOME} -name "libmesos.dylib" -or -name "libmesos.so" | head -n1)
build_env=$(find ${MESOS_HOME} -name "mesos-build-env.sh" | head -n1)
chronos_jar_file=$(find ${CHRONOS_HOME} -name "chronos-*.jar" | grep -v sources | head -n1)
export MESOS_NATIVE_LIBRARY="${libmesos_file}"
. $build_env
EXTRA_OPTS="-cp $chronos_jar_file com.airbnb.scheduler.Main server "$CHRONOS_HOME"/config/local_scheduler_nozk.yml"
}
case "$1" in
start)
set_environment
log_daemon_msg "Starting periodic command scheduler" "cron"
### example starting chronos from command line
### java -cp $chronos_jar_file com.airbnb.scheduler.Main server "$CHRONOS_HOME"/config/local_scheduler_nozk.yml
### example startin chronos with start_daemon
### start_daemon -p $PIDFILE $DAEMON $EXTRA_OPTS
# best way to daemonize, imho
start-stop-daemon --start --quiet --background \
--pidfile $PIDFILE --make-pidfile \
--exec $DAEMON -- $EXTRA_OPTS
log_end_msg $?
;;
stop)
log_daemon_msg "Stopping periodic command scheduler" "${NAME}"
killproc -p $PIDFILE $DAEMON
RETVAL=$?
[ $RETVAL -eq 0 ] && [ -e "$PIDFILE" ] && rm -f $PIDFILE
log_end_msg $RETVAL
;;
restart)
log_daemon_msg "Restarting periodic command scheduler" "${NAME}"
$0 stop
sleep 5
$0 start
;;
reload|force-reload)
log_daemon_msg "Reloading configuration files for periodic command scheduler" "${NAME}"
# cron reloads automatically
log_end_msg 0
;;
status)
status_of_proc -p $PIDFILE $DAEMON $NAME && exit 0 || exit $?
;;
*)
log_action_msg "Usage: ${SCRIPTNAME} {start|stop|status|restart|reload|force-reload}"
exit 2
;;
esac
exit 0