# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: LLDP daemon
-# Description: This script controls lldpd, a 802.1ab
-# implementation. lldpd also supports CDP,
-# EDP and various other protocols.
+# Description: lldpd is a 802.1AB implementation, a L2 network
+# discovery protocol. It also supports CDP, EDP and
+# various other protocols.
### END INIT INFO
# Do NOT "set -e"
--- /dev/null
+# lldpd - LLDP daemon
+#
+# lldpd is a 802.1AB implementation, a L2 network discovery
+# protocol. It also supports CDP, EDP and various other protocols.
+
+description "LLDP daemon"
+
+start on net-device-up IFACE=lo
+stop on runlevel [06]
+
+expect stop
+respawn
+
+pre-start script
+ CHROOT=/var/run/lldpd
+ [ -d $CHROOT/etc ] || mkdir -p $CHROOT/etc
+ [ -f $CHROOT/etc/localtime ] || [ ! -f /etc/localtime ] || \
+ cp /etc/localtime $CHROOT/etc/localtime
+end script
+
+script
+ . /etc/default/lldpd
+ exec lldpd $DAEMON_ARGS
+end script
/* Signals */
log_debug("event", "register signals");
+ sigignore(SIGHUP);
evsignal_add(evsignal_new(cfg->g_base, SIGUSR1,
levent_dump, cfg->g_base),
NULL);
- evsignal_add(evsignal_new(cfg->g_base, SIGHUP,
- levent_stop, cfg->g_base),
- NULL);
evsignal_add(evsignal_new(cfg->g_base, SIGINT,
levent_stop, cfg->g_base),
NULL);
{ -1, 0 }
};
+/**
+ * Tell if we have been started by upstart.
+ */
+static int
+lldpd_started_by_upstart()
+{
+ const char *upstartjob = getenv("UPSTART_JOB");
+ if (!(upstartjob && !strcmp(upstartjob, "lldpd")))
+ return 0;
+ log_debug("main", "running with upstart, don't fork but stop");
+ raise(SIGSTOP);
+ return 1;
+}
+
int
lldpd_main(int argc, char *argv[])
{
/* Disable SIGPIPE */
signal(SIGPIPE, SIG_IGN);
- /* Detach if needed */
- if (!debug) {
+ /* Daemonization, unless started by upstart or debug */
+ if (!lldpd_started_by_upstart() && !debug) {
int pid;
char *spid;
log_debug("main", "daemonize");