LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
LinkBack Search this Thread
Old 05-17-2009, 01:52 AM   #1
bitpicker
Member
 
Registered: Jul 2003
Location: Germany
Distribution: Xubuntu, Ubuntu
Posts: 416
Blog Entries: 14

Rep: Reputation: 35
Delaying shutdown while cron job is running


I am trying to set up a local backup on my desktop system using rdiff-backup and an external harddrive. The backup as such is no problem. I would like to run it as a daily cronjob with anachron, which by itself is also no problem. But I don't keep my computer on, wasting energy, when I don't use it. Sometimes it is possible that I only need to actually use it for a couple of minutes for checking e-mail, then shut it down again. That's also why I want to use anachron, there is no specific time when the computer is definitely on.

I believe this might cause problems with rdiff-backup if the backup cron job is running and I issue the shutdown command. If the cron job gets terminated in the middle, rdiff-backup will log errors.

Now I could write a shutdown script which first checks for a backup process, then waits for it to end before shutdown, but I don't want to fiddle with the shutdown sequence. Shutdown is usually initiated by using the logoff button in Xfce, I don't want to do anything fancy to that (if it is even possible) which I'd have to remember if I switch systems, lose it through an update or whatever.

Is there a way to set up a cron job or a script to enable it to tell the system to wait with shutdown until it is finished?

Robin
 
Old 05-17-2009, 03:12 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,950
Blog Entries: 11

Rep: Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860
Or you could have two versions (invocations?) of your back-up script;
one that does the back-up, one that shuts the machine down after
back-up completed. No farting around with checks, cron-jobs or timers.
You choose what it's gonna do before you start it.



Cheers,
Tink
 
Old 05-18-2009, 04:07 AM   #3
bitpicker
Member
 
Registered: Jul 2003
Location: Germany
Distribution: Xubuntu, Ubuntu
Posts: 416
Blog Entries: 14

Original Poster
Rep: Reputation: 35
That would mean I have to invoke it manually, which is what I am doing now. I want the backup to be a background process managed by anachron so I don't have to start it or mind it.

I have since looked into trapping signals, but there seems to be no way to trap all the signals, sooner or later the shutdown process will issue a kill command and the backup will be stopped ungracefully.

I could write a shutdown script which will only actually shutdown or reboot the system if no backup task is running, but I still wish there was a better way.

Robin
 
Old 05-18-2009, 04:58 AM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,950
Blog Entries: 11

Rep: Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860
If you just add at the end of your back-up script:
halt
...

Nothing manual about it.


Cheers,
Tink
 
Old 05-18-2009, 07:58 AM   #5
bitpicker
Member
 
Registered: Jul 2003
Location: Germany
Distribution: Xubuntu, Ubuntu
Posts: 416
Blog Entries: 14

Original Poster
Rep: Reputation: 35
You are misunderstanding me; I don't want a backup script which runs then shuts down the system, that's trivial, I want a backup script which gets started automatically as a cron job and will delay a user-initiated shutdown of the system until it is finished.

Robin
 
Old 05-18-2009, 02:13 PM   #6
pcunix
Member
 
Registered: Dec 2004
Location: MA
Distribution: Various
Posts: 149

Rep: Reputation: 23
Quote:
Originally Posted by bitpicker View Post
You are misunderstanding me; I don't want a backup script which runs then shuts down the system, that's trivial, I want a backup script which gets started automatically as a cron job and will delay a user-initiated shutdown of the system until it is finished.

Robin
You need to modify your shutdown to pay attention to the backup. That could be as simple as having your backup script create a sentinel file while it runs; the modified shutdown script would look for that file and hold off while it still exists.
 
Old 05-19-2009, 06:25 AM   #7
bitpicker
Member
 
Registered: Jul 2003
Location: Germany
Distribution: Xubuntu, Ubuntu
Posts: 416
Blog Entries: 14

Original Poster
Rep: Reputation: 35
OK, if modifying the shutdown script is the only way of doing it, I'll have a look into it. Thanks for your input.

Robin
 
Old 05-19-2009, 06:35 AM   #8
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,361

Rep: Reputation: 1910Reputation: 1910Reputation: 1910Reputation: 1910Reputation: 1910Reputation: 1910Reputation: 1910Reputation: 1910Reputation: 1910Reputation: 1910Reputation: 1910
You can simply check for the existence of the process and sleep some minute until the process terminates:
Code:
while ps -C backup_command_name > /dev/null
do
  # backup process is still running... sleep 5 minutes
  sleep 300
done
/sbin/shutdown -h now
 
  


Reply

Tags
backup, cron, delay, shutdown


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Running a Cron Job landysaccount Linux - Newbie 6 02-04-2009 05:29 PM
cron job not running vincebs Linux - Software 34 10-30-2004 01:27 PM
shutdown cron job tapanga Linux - Newbie 1 06-08-2004 12:17 PM
Cron job not running? james_cwy Linux - Newbie 6 12-14-2003 08:24 PM
Cron Job Not Running pzorn Linux - General 4 10-02-2003 01:38 PM


All times are GMT -5. The time now is 09:40 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration