来吧兄弟,一起玩一起讨论!
您需要 登录 才可以下载或查看,没有账号?注册
×
本帖最后由 yumin9822 于 2014-5-16 10:51 编辑
http://forum.synology.com/enu/viewtopic.php?f=40&t=51025 上面网址里面有详细的分析DSM系统启动的分析,我贴出给大家分享以下。作者是在DSM4.0 安装了optware环境后的分析。本人觉得对于以后大家添加自己的开机运行脚本的位置大有裨益!蓝色字体部分为作者分析的DSM启动和关闭过程脚本的执行顺序,按顺序执行!即开机运行顺序为
/usr/syno/etc/rc.d/ ---> /etc/rc.optware ---> /opt/etc/rc.optware --->/opt/etc/init.d/ ---> /usr/local/etc/rc.d/
关机运行顺序为
/usr/local/etc/rc.d/scriptname.sh stop ---> /usr/syno/etc/rc.d/S[00->99]scriptname.sh stop
如果按照作者的方法,修改为以下脚本后,开机关机顺序变成下面的On startup post-edit, scripts run in this order:
1. /usr/syno/etc/rc.d/S[00->99]scriptname.sh start
These are all of the Synology Scripts.
2. /etc/rc.optware start (executed by rc.local)
This script mounts your /opt with your /volume1/@optware
3. /usr/local/etc/rc.d/optware.sh start (executed by unknown syno script)
This now rechecks your mounts on startup, and executes /opt/etc/rc.optware start.
4. /opt/etc/rc.optware start (executed by /usr/local/etc/rc.d/optware.sh)
This executes a /opt/etc/init.d/S[00->99]scriptname.sh start
5. /opt/etc/init.d/S[00->99]scriptname.sh start (executed by /opt/etc/rc.optware)
This is where optware packages will install their startup scripts. This is the correct place.
On shutdown, scripts run in this order:
1. /usr/local/etc/rc.d/optware.sh stop (executed by unknown syno script)
This script does some logging on umount, then executes /opt/etc/rc.optware stop.
2. /opt/etc/rc.optware stop (executed by /usr/local/etc/rc.d/optware.sh)
This executes a /opt/etc/init.d/K[00->99]scriptname.sh stop
3. /opt/etc/init.d/K[00->99]scriptname.sh stop (executed by /opt/etc/rc.optware)
This is where optware packages will install their shutdown scripts.
4. /usr/syno/etc/rc.d/S[00->99]scriptname.sh stop
These are all of the Synology Scripts. 作者推荐自己制作的开机运行脚本放在/usr/local/etc/rc.d/目录下面。
本人白裙DS213J DSM5.0 4482系统安装好optware环境后,测试通过!(optware环境安装有兴趣,可以查看我的帖子http://www.gebi1.com/thread-83866-1-1.html)
以下为原文,供你参考!
---------------------------------------------------
So after installing ipkg and a couple packages (pound, named) I noticed that my DSM 4.0 NAS wouldn't shut down gracefully.
After much work I have it figured out. This info is for DSM 4.0, but probably works for the previous release.
On startup, scripts run in this order:
1. /usr/syno/etc/rc.d/S[00->99]scriptname.sh start
These are all of the Synology Scripts. Unless you have some compelling reason, do not put any init scripts in here. That defeats the purpose of the whole optware concept. They have theirs and you have yours.
2. /etc/rc.optware start (executed by rc.local)
This script mounts your /opt with your /volume1/@optware
Then by default it calls /opt/etc/rc.optware start
3. /opt/etc/rc.optware start (executed by /etc/rc.optware)
This executes a /opt/etc/init.d/S[00->99]scriptname.sh start
4. /opt/etc/init.d/S[00->99]scriptname.sh start (executed by /opt/etc/rc.optware)
This is where optware packages will install their startup scripts. This is the correct place.
5. /usr/local/etc/rc.d/scriptname.sh start (executed by unknown syno script)
This is an important startup directory. You are allowed to put scripts in here.
On shutdown, scripts run in this order:
1. /usr/local/etc/rc.d/scriptname.sh stop (executed by unknown syno script)
This is an important shutdown directory. You are allowed to put scripts in here.
2. /usr/syno/etc/rc.d/S[00->99]scriptname.sh stop
These are all of the Synology Scripts. Unless you have some compelling reason, do not put any init scripts in here. That defeats the purpose of the whole optware concept. They have theirs and you have yours.
But what about the other startup scripts? None of them run by default. This is why you're having problems. What makes it worse is if your services don't shutdown, DSM unmounts the disk out from under them with a -f flag, causing the blinking light of doom. Also any additional processes residing in or symlinked to /opt/ that you have running including bash! will prevent DSM from shutting down. I thought it would be a smart idea to change root's default shell to /opt/bin/bash. It made it impossible to shutdown while I was logged in. Also, it made it impossible to login to root when /opt wasn't mounted. Do not set any default shells to anything residing in /opt!
Ok so how do we fix this best? There are several ways to make it work, but this one is I think the closest to the developers' intentions and also improves your logging to /var/log/messages for troubleshooting later.
Replace or add the below scripts.
1. /etc/rc.optware
Please note what your REAL_OPT_DIR value is
Backup the old stuff
copy this below script into /etc/rc.optware using vi or whatever you have installed.
make sure you replace the REAL_OPT_DIR line with whatever you got from grep.
2. /opt/etc/rc.optware
Backup the old stuff
copy this below script into /opt/etc/rc.optware using vi or whatever you have installed.
Code: #!/bin/sh
# Optware setup
# Alternatives Optware Startup und Shutdown Script #/usr/local/etc/rc.d/optware.sh
#
logger -s -p daemon.error "$0 $1 executing."
case $1 in
start)
for i in /opt/etc/init.d/S??* ;do
#
# Ignore dangling symlinks (if any).
[ ! -f "$i" ] && continue
logger -s -p daemon.error "Beginning $1 of $i."
case "$i" in
*.sh)
# Source shell script for speed.
(
trap - INT QUIT TSTP
set start
. $i
)
;;
*\~)
# Tilde is a backup, ignore
logger -s -p daemon.error "Ignoring $i. It's a backup."
;;
*)
# No sh extension, so fork subprocess.
$i start
;;
esac
logger -s -p daemon.error "$1 of $i complete."
done
;;
#
stop)
#
for i in /opt/etc/init.d/K??* ;do
#
# Ignore dangling symlinks (if any).
[ ! -f "$i" ] && continue
logger -s -p daemon.error "Beginning $1 of $i."
case "$i" in
*.sh)
# Source shell script for speed.
(
trap - INT QUIT TSTP
set stop
. $i
)
;;
*\~)
# Tilde is a backup, ignore
logger -s -p daemon.error "Ignoring $i. It's a backup."
;;
*)
# No sh extension, so fork subprocess.
$i stop ;;
esac
logger -s -p daemon.error "$1 of $i complete."
done
;;
#
*)
echo "Usage: $0 [start|stop]"
;;
esac
logger -s -p daemon.error "$0 $1 complete."
#
# End
3. /usr/local/etc/rc.d/optware.sh
copy this below script into /usr/local/etc/rc.d/optware.sh using vi or whatever you have installed.
make sure you replace the REAL_OPT_DIR line with whatever you got from grep in step 1.
4. Set the permissions on everything correctly
You should be done! Init scripts running in /opt/etc/init.d/ will run correctly.
your directory should look like this for reference:
(I have 2 services, named and pound running)
nas> ls -la /opt/etc/init.d
drwxr-xr-x 2 root root 4096 May 4 14:25 .
drwxr-xr-x 5 root root 4096 May 1 18:33 ..
lrwxrwxrwx 1 root root 8 Apr 30 18:16 K90pound -> S10pound
lrwxrwxrwx 1 root root 8 Apr 30 18:17 K91named -> S09named
-rwxr-xr-x 1 root root 1181 May 1 17:22 S09named
-rwxr-xr-x 1 root root 1143 May 1 10:18 S09named~
-rwxr-xr-x 1 root root 1117 May 1 10:32 S10pound
-rwxr-xr-x 1 root root 1074 May 1 10:30 S10pound~
The key here is that the S scripts run 0-99 to start, while the K scripts run 0-99 to kill.
note that my K scripts are just symlinked to my S scripts. Most optware will do that automatically, but for reference the command looks like 'ln -s S09named K91named'
If for whatever reason you have problems, double check the instructions, and 'tail -f /var/log/messages' Worst case, replace your backups.
Enjoy.
Last edited by khaki54 on Wed Jun 06, 2012 4:16 pm, edited 1 time in total.
|