CygwinCronNotes

From $1

Table of contents
[MISSING]

Running cron as the local system service account turns out to have unintended consequences. It looks like it might be best to run it as a real user:

  • Read /usr/share/doc/Cygwin/cron.README (very different from /usr/share/doc/cron)
  • Verified that the user-ID to run cron has the "login as a service" right
  • Run cron_diagnose.sh and make it happy.

cygrunsrv --stop cron
cygrunsrv --remove cron
cygserver-config
cygrunsrv -I cron -p /usr/sbin/cron -a -D -d cron -e "CYGWIN=tty ntsec"
cygrunsrv -S cron

Test with a crontab of:

 *   *   *   *   *  date > /tmp/cron.log.txt

Other diagnostic hints:

  • Starting cron from the command-line (type cron and hit enter - after you stopped the cron service) gives better messages.
  • You may need to manually delete /var/run/cron.pid and /var/log/cron.log


Getting ssh (and rsync over ssh) to work on Cygwin is problematic. Cron jobs run as the 'system' account under windows, and permissions aren't exactly cygwin permissions and they aren't exactly windows permissions.


When I tried to do this, I had problems with access rights (with NTFS). The service is by default run by the SYSTEM user, so you need to make sure that this user has right to read and execute all relevant files (rsync, rsyncd.conf, cygwin1.dll, cygrunsrv, if not more). On my system, SYSTEM had no such rights by default, so I had to add those rights manually (right click on the files and go for the security tab).

You could try to make the service run as a different user from the Service manager. If you make that work, please let me know as I've never managed to (I get the same errors as those you describe below, but it doesn't seem to have anything to do with access rights).


cd /root
# create a private key with no pass phrase.
# You want to make sure no one ever gets access to this file
# (else they'll be able to log into your remote host)
ssh-keygen -f backup.private.key -t rsa -C "backupkey" -N ""
# pop the public key into a variable
public_key=`cat backup.private.key.pub`
# add a backup user on the remote machine, install the public key
ssh $remotehost "adduser backupuser;mkdir ~backupuser/.ssh;echo "$public_key" > ~backupuser/.ssh/authorized_keys"
# back on the localhost setup a job that will do the backup
echo "
#!/bin/bash
# invoked by /etc/cron.daily/rsyncbackupcronjob.sh
ssh-add /root/backup.private.key
# copy a directory to the backup server
rsync --delete --compress --archive --rsh=ssh $directory_to_backup backupuser@$remote_host:backups/
" > /root/rsyncbackup.sh
chmod +x /root/rsyncbackup.sh
# and then you need a job to lauch the previous one.  This job will execute nightly
via cron
echo "#!/bin/bash
ssh-agent /root/rsyncbackup.sh" > /etc/cron.daily/rsyncbackupcronjob.sh
chmod +x /etc/cron.daily/rsyncbackupcronjob.sh
}


I had to set cygwin=nontsec for my rsync service for the cron jobs to work correctly between 2 win2k servers (both ntfs, I set it up a while back now though.) Otherwise the files were owned by SYSTEM if i remember rightly, and needed to be chowned/chmodded before they were any use. With nontsec they just inherited the directories permissions. Havent tried over ssh though. I was using rsync in server mode as a service.


 

Tags:
none
 
Images (0)
 
Comments (0)
You must login to post a comment.