Provide an option to daemonise ckpool
This commit is contained in:
parent
c019a746f5
commit
1df924e73d
21
src/ckpool.c
21
src/ckpool.c
@ -1201,6 +1201,7 @@ static void *watchdog(void *arg)
|
||||
static struct option long_options[] = {
|
||||
{"standalone", no_argument, 0, 'A'},
|
||||
{"config", required_argument, 0, 'c'},
|
||||
{"daemonise", no_argument, 0, 'D'},
|
||||
{"ckdb-name", required_argument, 0, 'd'},
|
||||
{"group", required_argument, 0, 'g'},
|
||||
{"handover", no_argument, 0, 'H'},
|
||||
@ -1218,6 +1219,7 @@ static struct option long_options[] = {
|
||||
#else
|
||||
static struct option long_options[] = {
|
||||
{"config", required_argument, 0, 'c'},
|
||||
{"daemonise", no_argument, 0, 'D'},
|
||||
{"group", required_argument, 0, 'g'},
|
||||
{"handover", no_argument, 0, 'H'},
|
||||
{"help", no_argument, 0, 'h'},
|
||||
@ -1267,7 +1269,7 @@ int main(int argc, char **argv)
|
||||
ckp.initial_args[ckp.args] = strdup(argv[ckp.args]);
|
||||
ckp.initial_args[ckp.args] = NULL;
|
||||
|
||||
while ((c = getopt_long(argc, argv, "Ac:d:g:HhkLl:n:PpS:s:", long_options, &i)) != -1) {
|
||||
while ((c = getopt_long(argc, argv, "Ac:Dd:g:HhkLl:n:PpS:s:", long_options, &i)) != -1) {
|
||||
switch (c) {
|
||||
case 'A':
|
||||
ckp.standalone = true;
|
||||
@ -1275,6 +1277,9 @@ int main(int argc, char **argv)
|
||||
case 'c':
|
||||
ckp.config = optarg;
|
||||
break;
|
||||
case 'D':
|
||||
ckp.daemon = true;
|
||||
break;
|
||||
case 'd':
|
||||
ckp.ckdb_name = optarg;
|
||||
break;
|
||||
@ -1500,6 +1505,20 @@ int main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
if (ckp.daemon) {
|
||||
int fd;
|
||||
|
||||
if (fork())
|
||||
exit(0);
|
||||
setsid();
|
||||
fd = open("/dev/null",O_RDWR, 0);
|
||||
if (fd != -1) {
|
||||
dup2(fd, STDIN_FILENO);
|
||||
dup2(fd, STDOUT_FILENO);
|
||||
dup2(fd, STDERR_FILENO);
|
||||
}
|
||||
}
|
||||
|
||||
write_namepid(&ckp.main);
|
||||
open_process_sock(&ckp, &ckp.main, &ckp.main.us);
|
||||
launch_logger(&ckp.main);
|
||||
|
||||
@ -141,6 +141,9 @@ struct ckpool_instance {
|
||||
/* Are we running without ckdb */
|
||||
bool standalone;
|
||||
|
||||
/* Should we daemonise the ckpool process */
|
||||
bool daemon;
|
||||
|
||||
/* Bitcoind data */
|
||||
int btcds;
|
||||
char **btcdurl;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user