sapling/eden/fs/service/Systemd.cpp
Matt Glazar c20d275a6b Make 'eden start' run a bare minimum systemd service (opt-in)
Summary:
Add the plumbing necessary to make 'eden start' start a systemd user service. This is only enabled if you opt in using EDEN_EXPERIMENTAL_SYSTEMD.

Currently, only fake_edenfs works. The real edenfs doesn't work yet because it needs root access to configure mount points.

'eden restart', 'eden stop', etc. are not affected by this diff (and are probably broken with EDEN_EXPERIMENTAL_SYSTEMD enabled).

Reviewed By: simpkins

Differential Revision: D10849390

fbshipit-source-id: c087a6498951ff100e5c80bd07ad869b2709e1b3
2018-12-06 16:01:43 -08:00

43 lines
1.1 KiB
C++

/*
* Copyright (c) 2018-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
#include "eden/fs/service/Systemd.h"
#include <folly/String.h>
#include <folly/logging/xlog.h>
#include <gflags/gflags.h>
#include "eden/fs/eden-config.h"
#if EDEN_HAVE_SYSTEMD
#include <systemd/sd-daemon.h>
#endif
namespace facebook {
namespace eden {
#if EDEN_HAVE_SYSTEMD
DEFINE_bool(
experimentalSystemd,
false,
"EXPERIMENTAL: Run edenfs as if systemd controls its lifecycle");
void Systemd::notifyReady() {
// TODO(strager): Move READY=1 into a systemd-specific StartupLogger.
auto rc = sd_notify(/*unset_environment=*/false, "READY=1");
if (rc < 0) {
XLOG(ERR) << "sd_notify READY=1 failed: " << folly::errnoStr(-rc);
} else if (rc == 0) {
XLOG(WARN)
<< "sd_notify READY=1 failed: $NOTIFY_SOCKET is unset. edenfs was probably not started by systemd.";
}
}
#endif
} // namespace eden
} // namespace facebook