LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   init script ubuntu (https://www.linuxquestions.org/questions/linux-software-2/init-script-ubuntu-749225/)

Ipolit 08-21-2009 03:08 AM

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

catkin 08-21-2009 05:30 AM

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)?

Ipolit 08-24-2009 06:39 AM

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

catkin 08-24-2009 02:51 PM

Quote:

Originally Posted by Ipolit (Post 3655331)
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)?

Ipolit 08-25-2009 12:43 AM

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.

catkin 08-25-2009 05:41 AM

Quote:

Originally Posted by Ipolit (Post 3652040)
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.

catkin 08-25-2009 06:07 AM

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.

catkin 08-25-2009 06:11 AM

Quote:

Originally Posted by Ipolit (Post 3652040)
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.

Ipolit 08-25-2009 08:54 AM

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.


All times are GMT -5. The time now is 01:58 PM.