0

I'm trying to get a couple of programs to restart via cron every x hours (like for example syslog-ng using "/etc/init.d/syslog-ng restart"). However, the following always gets returned:

Stopping syslog-ng: [FAILED]
rm: cannot remove `/var/lock/subsys/syslog-ng': Permission denied
Starting syslog-ng: Error opening file for reading; filename='/proc/kmsg', error='Permission denied (13)'
Error initializing source driver; source='s_sys'
[FAILED]

Which file permissions do I need to change in order to be able to restart the programs with cron?

Thanks a lot.

timetofly
  • 205
  • 3
  • 8
  • 1
    whose crontab is the job running as? – Bart Silverstrim Sep 27 '10 at 19:17
  • 3
    and out of curiosity, why are you restarting the syslog ever couple of hours? Usually it's one of those "fire and forget" processes. – Bart Silverstrim Sep 27 '10 at 19:18
  • Expanding on Bart's line of thought...what exactly are you trying to accomplish here? It's very likely there's a much easier method than trying to restart a service regularly. – EEAA Sep 27 '10 at 19:27
  • Bart: It's running as a cpanel user, which ErikA says is the same user as the specific cpanel username. Syslog-ng is only one of the programs I want to restart, but the reason I want it is that I found that a specific program of mine doesn't write to a log file after it has been rotated by logrotate. The new log file that logrotate creates remains empty, and only a restart of syslog makes it write to the necessary file. – timetofly Sep 27 '10 at 20:12
  • that's a problem of logrotate. you could either use kill -9 HUP `pidof syslogd` in logroate postscript or use truncate (a very delayed answer :p) – Nikolaidis Fotis Jan 19 '11 at 22:29

1 Answers1

0

Which user's crontab are you running this from? If it is root's crontab, no additional permissions should be needed. If running it from a non-privileged user's crontab, then you'll need to grant that user permission to run the desired command using sudo.

EEAA
  • 109,363
  • 18
  • 175
  • 245
  • Hey, I'm using cron through cPanel. Do you know what user that is? Could you please provide me a link to instructions to do this? Which file do I change the permissions for? – timetofly Sep 27 '10 at 19:22
  • Are you the owner of this server? If so, then you'll still need to go in via ssh and, using the `visudo` command, grant your user permissions to run the command using escalated privileges. There are guides aplenty available if you just do a google search for "sudo howto". If you're not the owner of the server, then you're out of luck, as there's no way a hosting company is going to let you arbitrarily restart services on their machine. – EEAA Sep 27 '10 at 19:25
  • Yes, I'm the owner. How do I find out who the owner is of cPanel's cron? – timetofly Sep 27 '10 at 19:37
  • In all the cPanel setups I've used, the system user is the same as the user you use to sign into cPanel. The question remains, though...what exactly are you trying to accomplish. It's highly unlikely that restarting syslog regularly is an appropriate solution to whatever you're trying to accomplish. – EEAA Sep 27 '10 at 19:41
  • Thanks for the reply. Syslog-ng is just one of them--I have some personalized software that also needs regular restarts. One more question: wouldn't it just be easier to download the sudo file using WinSCP and editing it using a text editing program rather than through visudo? – timetofly Sep 27 '10 at 20:04
  • It may be easier, but it's not a good idea. `visudo` does syntax checking on the file before you save it. You're running a linux server. You really need to be comfortable with at least one commeand-line editor, even if it's `nano`. – EEAA Sep 27 '10 at 20:08
  • @user54625, that greatly increases the likelihood of completely breaking your system. See the question [Why do I have to edit with visudo](http://serverfault.com/questions/26303/why-do-i-have-to-edit-etc-sudoers-with-visudo/26306#26306). – Zoredache Sep 27 '10 at 20:10
  • Thanks for the help. For some reason, this isn't working for me, though. I've updated sudoers to include "admin ALL=(ALL) NOPASSWD: ALL", and ran the command "sudo /etc/init.d/syslog-ng restart" with cron, but cron is returning "sudo: must be setuid root". Any suggestions? How do I figure out if in fact that is the correct username? Surely there's a direct way to know what username cpanel's cron uses? – timetofly Sep 27 '10 at 20:35
  • If it's complaining that sudo must be setuid root, then something got messed up on your system. You can re-set uid root on sudo by running (as root) `$ chmod +s /usr/bin/sudo`. – EEAA Sep 27 '10 at 21:13