LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian
User Name
Password
Debian This forum is for the discussion of Debian Linux.

Notices


Reply
  Search this Thread
Old 10-18-2015, 03:03 PM   #1
Punkta
LQ Newbie
 
Registered: Oct 2015
Posts: 6

Rep: Reputation: Disabled
How to launch LSB script from rc0.d?


Hello here!
I am a newbie in Linux. I've Debian 8.2 & LXDE on my desktop PC. I'd like to make a script to empty a trash can automatically. I've found an aversome script here. I changed it a little and added an "INIT INFO" block. Here it is:
Code:
#! /bin/sh
### BEGIN INIT INFO
# Provides:          empty-trash
# Required-Start:    
# Required-Stop:
# Default-Start:     5
# Default-Stop:
# Short-Description: Empty Trash
### END INIT INFO

DAYS=-1
find /home/username/.local/share/Trash -type f -mtime +$DAYS -delete
find /home/username/.local/share/Trash/files/* -depth -type d -exec rmdir --ignore-fail-on-non-empty {} +
exit 0
"DAYS=-1" - it is just for test, it will be increased.

After creating the file (~./empty-trash) I did the following:
Code:
# mv empty-trash /etc/init.d/
# cd /etc/init.d
# chown root:root empty-trash
# chmod +x empty-trash
# update-rc.d empty-trash defaults
...and my script worked fine. But I'd like to launch it at shutdown.
I "uninstalled" the script an edited it:
Code:
# update-rc.d -f empty-trash remove
# leafpad /etc/init.d/empty-trash
Here is the edited script:
Code:
#! /bin/sh
### BEGIN INIT INFO
# Provides:          empty-trash
# Required-Start:    
# Required-Stop:     $all
# Default-Start:
# Default-Stop:      0
# Short-Description: Empty Trash
### END INIT INFO

DAYS=-1
find /home/username/.local/share/Trash -type f -mtime +$DAYS -delete
find /home/username/.local/share/Trash/files/* -depth -type d -exec rmdir --ignore-fail-on-non-empty {} +
exit 0
I saved the script and launched:
Code:
# update-rc.d empty-trash defaults
...and my script stopped to work.

What am I doing wrong? Can anybody help me, please?

Sorry for my bad English and thanks in advance!
 
Old 10-19-2015, 12:19 PM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,748

Rep: Reputation: 5927Reputation: 5927Reputation: 5927Reputation: 5927Reputation: 5927Reputation: 5927Reputation: 5927Reputation: 5927Reputation: 5927Reputation: 5927Reputation: 5927
The $all means run as the last script which is not going to work for runlevel 0. I would say you want the script to first but using $local_fs for the Required-Stop will at least start your your script prior to the local file systems unmounting.
 
Old 10-19-2015, 06:22 PM   #3
Punkta
LQ Newbie
 
Registered: Oct 2015
Posts: 6

Original Poster
Rep: Reputation: Disabled
Thank you for the response but it is incorrect in this case. It is correct for 'S' scripts but it is impossible to launch any 'S' script in runlevel 0 because a 'S' script will be called later than the last 'K' script. But the last 'K' script refers to halt.

With 'Required-Stop: $all' it places a symlink to my script at the first place in /etc/rc0.d but it still does not work. BTW, I already tried 'Required-Stop: $local_fs' and some other values and combinations but with no success.

Last edited by Punkta; 10-19-2015 at 07:00 PM.
 
Old 10-19-2015, 09:28 PM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,748

Rep: Reputation: 5927Reputation: 5927Reputation: 5927Reputation: 5927Reputation: 5927Reputation: 5927Reputation: 5927Reputation: 5927Reputation: 5927Reputation: 5927Reputation: 5927
Ok, guess I did not understand the https://wiki.debian.org/LSBInitScripts/ wiki but since update-rc.d does place your script in rc0.d and as k01... then $all is not the problem. I did try your script on a debian 7 and it ran and then finally tried it on a version 8 vm. The first time it didn't run but the second time it did. Not sure what I did to get it to work.
 
Old 10-20-2015, 12:41 AM   #5
Punkta
LQ Newbie
 
Registered: Oct 2015
Posts: 6

Original Poster
Rep: Reputation: Disabled
It is strange... Did you try my second script? The first one works fine for me, too.
IMO, the problem is more deeper. Maybe I need to add something to a line 'Should-stop'? I tried 'Should-stop: $all' - no difference. Or maybe sendsigs kills my script too quickly?
 
Old 10-31-2015, 07:04 AM   #6
Punkta
LQ Newbie
 
Registered: Oct 2015
Posts: 6

Original Poster
Rep: Reputation: Disabled
My script does delete all old files and dirs from the Trash. But any symlinks it doesn't. There is a solution:
Code:
#! /bin/sh
### BEGIN INIT INFO
# Provides:          empty-trash
# Required-Start:    
# Required-Stop:
# Default-Start:     5
# Default-Stop:
# Short-Description: Empty Trash
### END INIT INFO

DAYS=10
find /home/user/.local/share/Trash ! -type d -mtime +$DAYS -delete
find /home/user/.local/share/Trash/files/* -depth -type d -exec rmdir --ignore-fail-on-non-empty {} +
exit
The only difference is in the "type" option of the first "find" command.
The old variant:
Code:
-type f
That means "find files only"
The new variant:
Code:
! -type d
That means "find all except directories"

But I still can't make my script work at runlevel 0. Has somebody any ideas?

Last edited by Punkta; 11-01-2015 at 02:47 AM.
 
Old 11-24-2015, 09:09 AM   #7
Punkta
LQ Newbie
 
Registered: Oct 2015
Posts: 6

Original Poster
Rep: Reputation: Disabled
Well, I just fixed this. There is my new script below:
Code:
#!/bin/sh

if [ 0=$(runlevel | cut -d ' ' -f2) ]; then
  DAYS=10
  find /home/user/.local/share/Trash ! -type d -mtime +$DAYS -delete
  find /home/user/.local/share/Trash/files -depth -type d -exec rmdir --ignore-fail-on-non-empty {} +
fi
exit 0
The runlevel checking is from here.

I opened the file '/etc/lightdm/lightdm.conf' (as root) and uncommented the line 'session-cleanup-script=' and added here the path to my script. I saved the file and that's all.

It is not exactly a LSB script and it does not run directly from rc0.d but it runs at runlevel 0 only and works as expected.

Last edited by Punkta; 11-25-2015 at 03:02 PM.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Added rc0.d script does not run y-man Linux - General 2 09-17-2013 01:20 PM
[SOLVED] help with simple startup script - missing LSB fields tux-junkie Debian 3 07-14-2011 08:41 AM
[SOLVED] Linking init script to specific rc0.d, rc1.d etc directories vinaytp Linux - Newbie 4 08-20-2010 03:01 AM
Building LSB compatible application with LSB SDK - lsbappchk fails gkiagia Programming 0 01-12-2007 05:00 AM
Why won't my FC3 rc0 and rc6 levels not call kill script when entering those levels? dvkwiatk Linux - General 2 11-11-2006 08:09 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian

All times are GMT -5. The time now is 03:04 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration