Fail to redirect log to /var/log/syslog

0

I have an upstart script that does the following

start on runlevel [2345]
stop on runlevel [06]

respawn

pre-start script
    exec >/dev/kmsg 2>&1
    REPO=git@github.com:blabla/bli
    mkdir -p /var/log
    mkdir -p /var/www
    echo "Fetching app from $REPO"
    girror $REPO /var/www
    if [ -f /var/www/package.json ]; then
        echo "Installing npm modules"
        cd /var/www
        npm install
    fi
end script

post-stop script
    exec >/dev/kmsg 2>&1
    echo "stopped"
end script

script
    exec >/dev/kmsg 2>&1
    export NODE_ENV=production
    export port=80
    echo "Starting app.js on port 80"
    cd /var/www
    node app.js
end script

I am running the script as root. The log files of the application suppose to go to /var/log/syslog but they don't go there.

However, I do see the app log when running dmesg | tail -f

Using kernel 3.5.0-46

Anyone know why it doesn't work ?

Michael

Posted 2014-03-05T23:51:48.573

Reputation: 109

Answers

2

It's happening because your script explicitly redirects all output to dmesg:

exec >/dev/kmsg 2>&1

user1686

Posted 2014-03-05T23:51:48.573

Reputation: 283 655

I have the exact script running on a different ubuntu machine on AWS and it is redirecting okay. – Michael – 2014-03-06T00:12:10.067

@Michael: What kernel version is it running? – user1686 – 2014-03-06T00:13:17.580

the problematic one is running 3.5.0-46-generic #70~precise1-Ubuntu the one that works is running 3.2.0-31-virtual #50-Ubuntu – Michael – 2014-03-06T00:16:19.790

is it possible that on the working machine, all dmesg input is also redirected to /var/log/syslog ? btw, I am usually using rsyslog to send the log to a remote machine, it always mirrors what I have in /var/log/www to the remote machine like this – Michael – 2014-03-06T00:17:55.297

2@Michael: No. Rather, on the working machine, there is no dmesg input at all. Kernels before 3.5 did not have a writable /dev/kmsg device, so the exec line fails, the script ignores errors, and simply continues logging to where it was redirected previously (by Upstart). – user1686 – 2014-03-06T00:19:09.070

but the working machine is the one with the older kernel, so how come it is able to write to /dev/kmsg successfully ? isn't it suppose to be the opposite ? – Michael – 2014-03-06T00:22:29.493

1@Michael: Your original question does say the opposite – you wrote that it does not work because logs go to dmesg and not syslog. – user1686 – 2014-03-06T00:25:16.250

is there any way I can redirect it as I want in the newer kernel ? – Michael – 2014-03-06T00:26:32.497

@Michael: By removing the exec >/dev/kmsg lines? – user1686 – 2014-03-06T00:26:59.570

removing the lines and restarting did not work :( – Michael – 2014-03-06T00:41:55.137

let us continue this discussion in chat

– Michael – 2014-03-06T00:59:45.163