Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I want my server to notify me (via growl) that the (re)booting finished. I have the php file that sends out the growl ready but I do not know what file I should add the line in.

What file I need to add my code so it is run only after booting of SuSE finished?

share|improve this question
add comment

4 Answers 4

up vote 3 down vote accepted

Newer syntax for Suse Linux Enterprise 11 SP2 (and openSUSE ?)

The best way would be to create a shell script that will call your PHP script. This shell script should have in its header the following comment:

#!/bin/sh
### BEGIN INIT INFO
# Provides:          nothing
# Required-Start:    $all
# Default-Start:     3 5
# Default-Stop:      4
# Short-Description: single_line_description
# Description:       multiline_description
### END INIT INFO

You can find a typical template (with loads of explanatory comments) in /etc/init.d/skeleton. This template includes the necessary code to hook your PHP script. You will see a start case where you would have to call your PHP script.
I have discarded a number of optional parameter in the header as it does not appear that you would need them.

Important
It is important to use the skeleton at least the case statement (see init scripts actions), and to implement the start case at least. In the start case, that is where to call your script.

You can find here a small script example that will be called at the end of a boot: see my Gist. I put an invalid run level for the Default-Stop, but somehow the script is still called during shutdown. Anyway, the code in the "stop" case is executed, not the one in the "start" case while shutting down.

Once you have written your script, copy it to /etc/init.d let's assume that your init script is called boot-notification, then you would do (as root):

chown root:root boot-notification
chmod 0750 boot-notification
mv boot-notification /etc/init.d/

Then you need to "register" the script in the init system. You will use the insserv command (again as root) or you can use YaST:

insserv boot-notification

Then you can further check that the script is one of the last to be run by looking into each init level. If you chose only runlevel 3, then you could do this:

ls -l /etc/init.d/rc3.d/S*

This will return a list of links to init scripts. The link to your script should be at the end (or near it) of the list.

Note: If you want to play around with the more dynamic way of writing init scripts, I would advise reading these 2 pages:

share|improve this answer
    
I did not follow your steps 100% I only used your new headers for the script and now I can see the description in yast. My problem is that the script is triggers before the reboot and after. I do not want it happen before. –  Radek Jul 19 '12 at 23:10
    
YaST has probably added the script to the reboot and shutdown init. If you use the skeleton (check the openSuse link, it contains a simpler one, look in the 'Action' section). You have to be sure that when start is invoke, you call your PHP script. When stop is invoke, you don't call it. Or you can use @Petr-Uzel solution too, then you simply call your PHP script, no need to apply the skeleton structure. –  Huygens Jul 20 '12 at 9:34
    
Would you know how to check if calling the script is part of shutdown init? –  Radek Jul 23 '12 at 0:21
1  
@Radek when shutting down or rebooting, the runlevel change to (respectively) 0 or 6. If you have the script in /etc/init.d/rcn.d/K* with n equal 0 or 6, then it is called during the shutdown. I have added a gist (see link in my answer) with a simple script you could re-use to call your PHP script. –  Huygens Jul 23 '12 at 7:15
    
After checking, the runlevel for shutting down and reboot are correct, however, the scripts are not place there. But in their respective start runlevel. So if you put the runlevel 3 to start the script, then in runlevel 3 you will see the shutdown script, the difference is that for startup, the link to the script is S<nn><filename> whereas for the shuttdown it is K<nn><filename> –  Huygens Jul 23 '12 at 7:32
show 2 more comments

(open)SUSE uses /etc/init.d/after.local for this purpose. Just add the commands you need to be executed into that file. Note that this works fine with SystemV init, but with systemd this would need AFAIK need to be solved differently.

share|improve this answer
2  
This is executing scripts just after the initial machine boot, not the end of the init boot process... AFAIK –  Huygens Jul 17 '12 at 8:38
    
Yeah, of course you are right, thanks! The correct file is /etc/init.d/after.local. Updating my answer. –  Petr Uzel Jul 17 '12 at 12:00
    
Cool file, something I have to remember! +1 –  Huygens Jul 17 '12 at 12:01
    
It seems to not be working in openSuse since 12.1: forums.opensuse.org/blogs/jdmcdaniel3/… but this blog post propose a work around. –  Huygens Jul 20 '12 at 9:39
add comment

To add a new init script is quite straight forward on Suse.

The best way would be to create a shell script that will call your PHP script. This shell script should have in its header the following comment:

#!/bin/sh
#chkconfig: 35 99 00
#description: Notify of boot completion

You can find a typical template (with loads of explanatory comments) in /etc/init.d/skeleton.compat (that one supports the chkconfig syntax, you have also 7etc/init.d/skeleton which supports newer LSB standard, but it is a bit more complicate to explain you how to set it up, though it is more powerful). This template includes the necessary code to hook your PHP script. You will see a start case where you would have to call your PHP script.

The important number I gave you are on the chkconfig line.

  • 35: means that this script will be called in either init 3 (console mode, usual for server) or init 5 (graphical mode, more common for desktop)
  • 99: is the priority in either init 3 or 5. It means that it will be called last. Note that some other boot scripts could be called with a priority 99.
  • 00: is the priority for shutdown/reboot. You could also have a notification as soon as the system is going down.

Once you have written your script, copy it to /etc/init.d let's assume that your init script is called boot-notification, then you would do (as root):

# chown root:root boot-notification
# chmod 0750 boot-notification
# mv boot-notification /etc/init.d/

Then you need to "register" the script in the init system. You will use the chkconfig command (again as root):

# chkconfig --add boot-notification

Check that this was taken into account properly:

# chkconfig boot-notification
boot-notification on

If you see on, it is good!
Then you can further check that the script is one of the last to be run by looking into each init level. If you chose only runlevel 3, then you could do this:

$ ls -l /etc/init.d/rc3.d/S*

This will return a list of links to init scripts. The link to your script should be at the end (or near it) of the list.

Note: If you want to play around with the more dynamic way of writing init scripts, I would advise reading these 2 pages:

share|improve this answer
    
I created a script, copied into /etc/init.d and registered via yast for runlevel 3 & 5. Now it is triggered before reboot starts and after it finishes. Then I added the header you suggested but it still sends out message before booting. Any idea how to stop that? –  Radek Jul 19 '12 at 0:36
    
OK, YaST does not support legacy synax it seems. I' going to offer you another answer with latest syntax then. –  Huygens Jul 19 '12 at 13:31
add comment

For OpenSUSE 12.2 (Mantis), the script for "after local" should be /etc/init.d/after-local , and you may need to enable it via systemctl, like this...

To enable /etc/init.d/after-local,

systemctl enable after-local.service

To check status of /etc/init.d/after-local,

systemctl status after-local.service
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.