LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-21-2009, 03:08 AM   #1
Ipolit
Member
 
Registered: Nov 2003
Location: Bulgaria
Distribution: Vector Linux, Morphix
Posts: 309

Rep: Reputation: 31
init script ubuntu


Hello all,
I have a network with approximately 100 PCs running Ubuntu 8.04. All the PCs use autodir package because I need every user to be able to sit on any computer. Because we frequently add new users, we generate passwords, users and shadow files separately and on every boot those files are updated with rsync.
Unfortunatelly on some PCs this doesn't happen. On some of them it happens when the PC starts to shutdown, which is not a problem at all, but in case of new user the PC has to be restarted in order to receive those files.
The rc script has been generated with
Code:
update-rc.d syncronisation defaults
and it has created in all /etc/rcX.d files 20syncronisation

the script contains the following
Code:
rsync --delete --delete-after -v -r -z 172.23.31.16::muskogee /opt/remote
/opt/remote/init.sh //this replaces old passwords, shadows and users
How to make it to be executed on boot, not on shutdwon

And the other interesting thing is that if I put the script in rc.local it is not executed.

Thank you
 
Old 08-21-2009, 05:30 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,577
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
The scripts pointed to by /etc/rc[S0-6].d/S* symlinks are run on entering the associated run level. During boot, run level S is entered first, followed by whatever is set as your default run level. The default run level on ubuntu is 2 unless you have changed it.

What is the output from
Code:
/bin/ls -l /etc/rc[S0-6].d/*syncronisation*
What evidence do you have that your script is not being run during boot (as opposed to not doing what you intend it to do during boot)?
 
Old 08-24-2009, 06:39 AM   #3
Ipolit
Member
 
Registered: Nov 2003
Location: Bulgaria
Distribution: Vector Linux, Morphix
Posts: 309

Original Poster
Rep: Reputation: 31
Code:
/bin/ls -l /etc/rc[S0-6].d/*syncronisation*
lrwxrwxrwx 1 root root 24 2009-08-21 10:40 /etc/rc0.d/K20syncronisation -> ../init.d/syncronisation
lrwxrwxrwx 1 root root 24 2009-08-21 10:40 /etc/rc1.d/K20syncronisation -> ../init.d/syncronisation
lrwxrwxrwx 1 root root 24 2009-08-21 10:40 /etc/rc2.d/S20syncronisation -> ../init.d/syncronisation
lrwxrwxrwx 1 root root 24 2009-08-21 10:40 /etc/rc3.d/S20syncronisation -> ../init.d/syncronisation
lrwxrwxrwx 1 root root 24 2009-08-21 10:40 /etc/rc4.d/S20syncronisation -> ../init.d/syncronisation
lrwxrwxrwx 1 root root 24 2009-08-21 10:40 /etc/rc5.d/S20syncronisation -> ../init.d/syncronisation
lrwxrwxrwx 1 root root 24 2009-08-21 10:40 /etc/rc6.d/K20syncronisation -> ../init.d/syncronisation
As expected. But it works only in 6 level
 
Old 08-24-2009, 02:51 PM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,577
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by Ipolit View Post
As expected. But it works only in 6 level
Links look fine. What evidence do you have that your script is not being run during boot (as opposed to not doing what you intend it to do during boot)?
 
Old 08-25-2009, 12:43 AM   #5
Ipolit
Member
 
Registered: Nov 2003
Location: Bulgaria
Distribution: Vector Linux, Morphix
Posts: 309

Original Poster
Rep: Reputation: 31
First of all if the scripts are executed it could be seen in the boot process, since rsync copies 50 MB of files and the process is visible. The second is when new user is added, he cannot login before run the scripts manually or reboot and scripts are executed in the shutdown level 6. But this is not on all computes. The interesting thing is that there is no difference in computers because the installation is done using dd and disks are clones of one. I don't know really what is going on.
 
Old 08-25-2009, 05:41 AM   #6
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,577
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by Ipolit View Post
How to make it to be executed on boot, not on shutdwon
To runn at boot, you need only the /etc/rc2.d/S20syncronisation symlink; you can remove all the others. That presumes that your default run level is the original default, 2. You can test this by running
Code:
sed -n -e "/^id:[0-9]*:initdefault:/{s/^id://;s/:.*//;p}" /etc/inittab
On an as-installed system this gives an error message
Code:
sed: can't read /etc/inittab: No such file or directory
In which case the default run level is 2. See the /etc/event.d/rc-default script.
 
Old 08-25-2009, 06:07 AM   #7
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,577
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
You can get a bit more information by re-writing your script in conformance with boot script conventions (not tested).
Code:
#! /bin/sh

DESC='local initialisation'
NAME='local_initialisation'
SCRIPTNAME="/etc/init.d/$NAME"

# Define LSB log_* functions.
. /lib/lsb/init-functions

# Debug
log_action_msg "$SCRIPTNAME running with args $*"

case "$1" in
  start)
	log_action_begin_msg "Starting $DESC"
	rsync --delete --delete-after -v -r -z 172.23.31.16::muskogee /opt/remote
        /opt/remote/init.sh # this replaces old passwords, shadows and users
        log_action_end_msg "Finished $DESC"
	;;
  stop)
	;;
  restart|force-reload)
	;;
  *)
	echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
	exit 3
	;;
esac
This will also ensure that the script only does anything during boot; during shutdown it is called with $1 set to stop so does nothing.

It assumes your script is /etc/init.d/local_initialisation; adjust as appropriate.

BTW, // is not a bash script comment. In your original script "//this replaces old passwords, shadows and users" would have been passed to init.sh as arguments where they presumably (!) had no effect. The bash comment character is # as shown in the above example.

That will give you some messages on the console during boot so you can see if the script is being run. Once you have that information we can focus on either why it is not being run or why it is being run but is not doing what you want it to do.

Last edited by catkin; 08-25-2009 at 06:13 AM. Reason: Typos
 
Old 08-25-2009, 06:11 AM   #8
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,577
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by Ipolit View Post
And the other interesting thing is that if I put the script in rc.local it is not executed.
That is interesting. We can have good confidence that rc.local is run so strange that the script is not run. Let's see what the suggested modified script tells us about whether it is being run or not.
 
Old 08-25-2009, 08:54 AM   #9
Ipolit
Member
 
Registered: Nov 2003
Location: Bulgaria
Distribution: Vector Linux, Morphix
Posts: 309

Original Poster
Rep: Reputation: 31
Actually the script was placed in /opt directory and there was a link to it from /etc/rc2.d/S98syncronisation
In this manner it works on some computers.
Afterwards I put it in /etc/init.d and executed

update-rc.d syncronisation defaults

Two slashes do not reside in the script, I put them here in the post.
 
  


Reply


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Init.d Script pliqui Debian 11 06-16-2009 08:58 AM
script init.d anna611 Linux - Newbie 9 11-28-2007 12:22 PM
need help with init script batymahn Linux - Server 1 08-23-2007 11:12 AM
How to add something in init script Ypkis Linux - Newbie 5 10-12-2003 06:35 AM
could use some help with my init.d script.... BrianK Linux - General 3 10-31-2002 07:21 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration