mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-22 08:08:53 -05:00
Allow to specify the pid file from the config file.
This commit is contained in:
parent
db52edaa0d
commit
ed329fcf25
9
redis.c
9
redis.c
@ -171,6 +171,7 @@ struct redisServer {
|
||||
int maxidletime;
|
||||
int dbnum;
|
||||
int daemonize;
|
||||
char *pidfile;
|
||||
int bgsaveinprogress;
|
||||
struct saveparam *saveparams;
|
||||
int saveparamslen;
|
||||
@ -715,6 +716,7 @@ static void initServerConfig() {
|
||||
server.bindaddr = NULL;
|
||||
server.glueoutputbuf = 1;
|
||||
server.daemonize = 0;
|
||||
server.pidfile = "/var/run/redis.pid";
|
||||
server.dbfilename = "dump.rdb";
|
||||
ResetServerSaveParams();
|
||||
|
||||
@ -878,6 +880,8 @@ static void loadServerConfig(char *filename) {
|
||||
else {
|
||||
err = "argument must be 'yes' or 'no'"; goto loaderr;
|
||||
}
|
||||
} else if (!strcmp(argv[0],"pidfile") && argc == 2) {
|
||||
server.pidfile = zstrdup(argv[1]);
|
||||
} else {
|
||||
err = "Bad directive or wrong number of arguments"; goto loaderr;
|
||||
}
|
||||
@ -1899,6 +1903,9 @@ static void bgsaveCommand(redisClient *c) {
|
||||
static void shutdownCommand(redisClient *c) {
|
||||
redisLog(REDIS_WARNING,"User requested shutdown, saving DB...");
|
||||
if (saveDb(server.dbfilename) == REDIS_OK) {
|
||||
if (server.daemonize) {
|
||||
unlink(server.pidfile);
|
||||
}
|
||||
redisLog(REDIS_WARNING,"Server exit now, bye bye...");
|
||||
exit(1);
|
||||
} else {
|
||||
@ -3033,7 +3040,7 @@ static void daemonize(void) {
|
||||
if (fd > STDERR_FILENO) close(fd);
|
||||
}
|
||||
/* Try to write the pid file */
|
||||
fp = fopen("/var/run/redis.pid","w");
|
||||
fp = fopen(server.pidfile,"w");
|
||||
if (fp) {
|
||||
fprintf(fp,"%d\n",getpid());
|
||||
fclose(fp);
|
||||
|
@ -4,6 +4,10 @@
|
||||
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
|
||||
daemonize no
|
||||
|
||||
# When run as a daemon, Redis write a pid file in /var/run/redis.pid by default.
|
||||
# You can specify a custom pid file location here.
|
||||
pidfile /var/run/redis.pid
|
||||
|
||||
# Accept connections on the specified port, default is 6379
|
||||
port 6379
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user