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

http://unix.stackexchange.com/questions/43230/how-to-run-my-script-after-suse-finished-booting-up

 

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:

  •  

     

    -----------------------------------------------------------------------

 

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:

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值