mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
parent
bd95aba7a5
commit
c360cb7b1f
@ -13,6 +13,7 @@
|
|||||||
#include <ccan/io/io.h>
|
#include <ccan/io/io.h>
|
||||||
#include <ccan/noerr/noerr.h>
|
#include <ccan/noerr/noerr.h>
|
||||||
#include <ccan/pipecmd/pipecmd.h>
|
#include <ccan/pipecmd/pipecmd.h>
|
||||||
|
#include <ccan/read_write_all/read_write_all.h>
|
||||||
#include <ccan/take/take.h>
|
#include <ccan/take/take.h>
|
||||||
#include <ccan/tal/grab_file/grab_file.h>
|
#include <ccan/tal/grab_file/grab_file.h>
|
||||||
#include <ccan/tal/path/path.h>
|
#include <ccan/tal/path/path.h>
|
||||||
@ -24,6 +25,7 @@
|
|||||||
#include <common/version.h>
|
#include <common/version.h>
|
||||||
#include <common/wireaddr.h>
|
#include <common/wireaddr.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
#include <lightningd/bitcoind.h>
|
#include <lightningd/bitcoind.h>
|
||||||
#include <lightningd/chaintopology.h>
|
#include <lightningd/chaintopology.h>
|
||||||
#include <lightningd/invoice.h>
|
#include <lightningd/invoice.h>
|
||||||
@ -39,6 +41,8 @@ char *bitcoin_datadir;
|
|||||||
|
|
||||||
struct backtrace_state *backtrace_state;
|
struct backtrace_state *backtrace_state;
|
||||||
|
|
||||||
|
int pid_fd;
|
||||||
|
|
||||||
static struct lightningd *new_lightningd(const tal_t *ctx)
|
static struct lightningd *new_lightningd(const tal_t *ctx)
|
||||||
{
|
{
|
||||||
struct lightningd *ld = tal(ctx, struct lightningd);
|
struct lightningd *ld = tal(ctx, struct lightningd);
|
||||||
@ -70,6 +74,7 @@ static struct lightningd *new_lightningd(const tal_t *ctx)
|
|||||||
ld->topology = new_topology(ld, ld->log);
|
ld->topology = new_topology(ld, ld->log);
|
||||||
ld->debug_subdaemon_io = NULL;
|
ld->debug_subdaemon_io = NULL;
|
||||||
ld->daemon = false;
|
ld->daemon = false;
|
||||||
|
ld->pidfile = NULL;
|
||||||
|
|
||||||
return ld;
|
return ld;
|
||||||
}
|
}
|
||||||
@ -250,6 +255,28 @@ static void daemonize_but_keep_dir(void)
|
|||||||
tal_free(cwd);
|
tal_free(cwd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void pidfile_create(const struct lightningd *ld)
|
||||||
|
{
|
||||||
|
char *pid;
|
||||||
|
const tal_t *tmpctx = tal_tmpctx(NULL);
|
||||||
|
|
||||||
|
/* Create PID file */
|
||||||
|
pid_fd = open(ld->pidfile, O_WRONLY|O_CREAT, 0640);
|
||||||
|
if (pid_fd < 0)
|
||||||
|
err(1, "Failed to open PID file");
|
||||||
|
|
||||||
|
/* Lock PID file */
|
||||||
|
if (lockf(pid_fd, F_TLOCK, 0) < 0)
|
||||||
|
/* Problem locking file */
|
||||||
|
err(1, "lightningd already running? Error locking PID file");
|
||||||
|
|
||||||
|
/* Get current PID and write to PID fie */
|
||||||
|
pid = tal_fmt(tmpctx, "%d\n", getpid());
|
||||||
|
write_all(pid_fd, pid, strlen(pid));
|
||||||
|
|
||||||
|
tal_free(tmpctx);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
struct lightningd *ld;
|
struct lightningd *ld;
|
||||||
@ -280,6 +307,9 @@ int main(int argc, char *argv[])
|
|||||||
/* Handle options and config; move to .lightningd */
|
/* Handle options and config; move to .lightningd */
|
||||||
newdir = handle_opts(ld, argc, argv);
|
newdir = handle_opts(ld, argc, argv);
|
||||||
|
|
||||||
|
/* Create PID file */
|
||||||
|
pidfile_create(ld);
|
||||||
|
|
||||||
/* Ignore SIGPIPE: we look at our write return values*/
|
/* Ignore SIGPIPE: we look at our write return values*/
|
||||||
signal(SIGPIPE, SIG_IGN);
|
signal(SIGPIPE, SIG_IGN);
|
||||||
|
|
||||||
@ -384,6 +414,8 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
shutdown_subdaemons(ld);
|
shutdown_subdaemons(ld);
|
||||||
|
close(pid_fd);
|
||||||
|
remove(ld->pidfile);
|
||||||
|
|
||||||
tal_free(ld);
|
tal_free(ld);
|
||||||
opt_free_table();
|
opt_free_table();
|
||||||
|
@ -142,6 +142,9 @@ struct lightningd {
|
|||||||
/* Transaction filter matching what we're interested in */
|
/* Transaction filter matching what we're interested in */
|
||||||
struct txfilter *owned_txfilter;
|
struct txfilter *owned_txfilter;
|
||||||
|
|
||||||
|
/* PID file */
|
||||||
|
char *pidfile;
|
||||||
|
|
||||||
/* May be useful for non-developers debugging in the field */
|
/* May be useful for non-developers debugging in the field */
|
||||||
char *debug_subdaemon_io;
|
char *debug_subdaemon_io;
|
||||||
|
|
||||||
|
@ -449,6 +449,10 @@ static void setup_default_config(struct lightningd *ld)
|
|||||||
ld->config = testnet_config;
|
ld->config = testnet_config;
|
||||||
else
|
else
|
||||||
ld->config = mainnet_config;
|
ld->config = mainnet_config;
|
||||||
|
|
||||||
|
/* Set default PID file name to be per-network */
|
||||||
|
tal_free(ld->pidfile);
|
||||||
|
ld->pidfile = tal_fmt(ld, "lightningd-%s.pid", get_chainparams(ld)->network_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -560,6 +564,9 @@ void register_opts(struct lightningd *ld)
|
|||||||
opt_register_arg("--bitcoin-rpcconnect", opt_set_talstr, NULL,
|
opt_register_arg("--bitcoin-rpcconnect", opt_set_talstr, NULL,
|
||||||
&ld->topology->bitcoind->rpcconnect,
|
&ld->topology->bitcoind->rpcconnect,
|
||||||
"bitcoind RPC host to connect to");
|
"bitcoind RPC host to connect to");
|
||||||
|
opt_register_arg("--pid-file=<file>", opt_set_talstr, opt_show_charp,
|
||||||
|
&ld->pidfile,
|
||||||
|
"Specify pid file");
|
||||||
|
|
||||||
opt_register_arg(
|
opt_register_arg(
|
||||||
"--channel-update-interval=<s>", opt_set_u32, opt_show_u32,
|
"--channel-update-interval=<s>", opt_set_u32, opt_show_u32,
|
||||||
|
Loading…
Reference in New Issue
Block a user