Running Redis in a dismantled form and using Upstart to manage it does not work

I wrote an Upstart script for Redis as follows:

description "Redis Server"

start on runlevel [2345]
stop on shutdown
expect daemon

exec sudo -u redis /usr/local/bin/redis-server /etc/redis/redis.conf

respawn
respawn limit 10 5

Then I configure redis through redis.conf to:

daemonize yes

All the documentation and my own experiments say that Redis plugs twice in demonized form and โ€œwait for the daemonโ€ should work, but the Upstart script always holds on to the PID of the previous parent (PID-1). Has anyone got this job?

+5
source share
2 answers

Other people have the same problem. See this meaning .

daemonize, Redis , ( getppid). , . , getppid, fork - ( setsid), Linux .

. faq.

daemonize Redis :

void daemonize(void) {
    int fd;

    if (fork() != 0) exit(0); /* parent exits */
    setsid(); /* create a new session */

    /* Every output goes to /dev/null. If Redis is daemonized but
     * the 'logfile' is set to 'stdout' in the configuration file
     * it will not log at all. */
    if ((fd = open("/dev/null", O_RDWR, 0)) != -1) {
        dup2(fd, STDIN_FILENO);
        dup2(fd, STDOUT_FILENO);
        dup2(fd, STDERR_FILENO);
        if (fd > STDERR_FILENO) close(fd);
    }
}

Upstart :

expect daemon
Specifies that the job main process is a daemon, and will fork twice after being run.
init(8) will follow this daemonisation, and will wait for this to occur before running
the job post-start script or considering the job to be running.
Without this stanza init(8) is unable to supervise daemon processes and will
believe them to have stopped as soon as they daemonise on startup.

expect fork
Specifies that the job main process will fork once after being run. init(8) will
follow this fork, and will wait for this to occur before running the job post-start
script or considering the job to be running.
Without this stanza init(8) is unable to supervise forking processes and will believe
them to have stopped as soon as they fork on startup.

Redis, fork fork, .

+3

, upstart config, upstart 1.5 ubuntu 12.04, redis.conf daemonize yes:

description "redis server"

start on (local-filesystems and net-device-up IFACE=eth0)
stop on shutdown

setuid redis
setgid redis
expect fork

exec /opt/redis/redis-server /opt/redis/redis.conf

respawn
+6

All Articles