linux - Fail to redirect log to /var/log/syslog
2014-07
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=[email protected]: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 ?
It's happening because your script explicitly redirects all output to dmesg:
exec >/dev/kmsg 2>&1
I recently started using multiprocessing for my python code and now these two files are choking up all the space on my system.
./var/log/user.log: 8.1G
./var/log/syslog: 8.1G
I know it might be difficult to get a fix for this without going into the specifics of the code, I just want to know if it is safe to delete these files?
These are log files that are intended to for debugging and accountability of users. On your personal computer, you can absolutely delete them.
However, while that solves the problem temporarily, multiprocessing should not make entries in these files. What is written into these log files when you execute your program?
Not sure which distro you are using, but seems like you have a custom logging instance setup in /etc/syslog.conf.
Try to disable or, alternatively, if the logging info is useful, configure /etc/logrotate.conf to rotate those logs on a more regular basis in order to prevent them from filling up your filesystem.
When you delete these files the space won't be freed until the processes holding them open have exited. In other words, if your goal is to free up the space you'll also have to restart syslogd (which might not be easy, depending on your system)
You can see which processes are holding open the files using something like:
lsof|egrep '/var/log/(user.log|syslog)'