如何将 init.d 脚本从 Ubuntu/Debian Linux 转换为 Solaris?

发布于 2024-07-08 11:59:56 字数 278 浏览 6 评论 0原文

我有几个 init.d 脚本,用于启动一些守护进程。 我在互联网上找到的大多数脚本都使用启动-停止-守护进程。 我的理解是“start-stop-daemon”是特定于 Linux 或 BSD 发行版的命令,在 Solaris 上不可用。

将 init.d 脚本从 Linux 转换为 Solaris 的最佳方法是什么? 是否有一个相当于我可以粗略使用的 start-stop-daemon 的命令?

由于我不是 Solaris 用户,所以我愿意预先承认我什至不知道我的问题本质上是否无效。

I have several init.d scripts that I'm using to start some daemons. Most of these scripts I've found on the internet and they all use start-stop-daemon. My understanding is that "start-stop-daemon" is a command that is specific to Linux or BSD distros and is not available on Solaris.

What is the best way to translate my init.d scripts from Linux to Solaris? Is there a command equivalent to start-stop-daemon that I can use, roughly?

Since I'm not much of a Solaris user, I'm willing to admit upfront that I don't even know if my question is inherently invalid or not.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

栖竹 2024-07-15 11:59:56

start-stop-daemon 是 Linux 的东西,在 Solaris 上用得不多。 我想如果您想重用初始化脚本,您可以移植该命令。

否则,这取决于您使用的 Solaris 版本。 从 Solaris 10 和 OpenSolaris 开始,它们使用新的启动脚本框架“Solaris 服务管理工具”,您可以使用命令 svcssvccfgsvcadm< /代码>。

请参阅 http://www.oracle.com/technetwork/server-storage /solaris/overview/servicemgmthowto-jsp-135655.html 了解更多信息。

对于较旧的 Solaris 版本,大多数 init 脚本都是用纯 shell 编写的,没有任何帮助命令(例如 start-stop-daemon)。

start-stop-daemon is a Linux thing, and not used that much on Solaris. I guess you can port the command though, if you want to reuse your init scripts.

Otherwise it depends on what version of Solaris you are using. Starting with Solaris 10 and also OpenSolaris they use a new startup script framework "Solaris Service Management Facility", which you configure with the commands svcs, svccfg and svcadm.

See http://www.oracle.com/technetwork/server-storage/solaris/overview/servicemgmthowto-jsp-135655.html for more information.

For older Solaris releases most init scripts are written in pure shell without any helper commands like start-stop-daemon.

北笙凉宸 2024-07-15 11:59:56

在 Solaris 10 或更高版本上,建议使用 SMF,但在早期版本中,您需要在 /etc/init.d 中创建一个 init 脚本,并从 rcX.d 目录链接到它。 下面是用于启动 rsync 守护进程的 init 脚本的简单示例:

#!/sbin/sh

startcmd () {
    /usr/local/bin/rsync --daemon  # REPLACE WITH YOUR COMMANDS
}

stopcmd () {
    pkill -f "/usr/local/bin/rsync --daemon"  # REPLACE WITH YOUR COMMANDS
}

case "$1" in
'start')
        startcmd
        ;;
'stop')
        stopcmd
        ;;
'restart')
        stopcmd
        sleep 1
        startcmd
        ;;
*)
        echo "Usage: $0 { start | stop | restart }"
        exit 1
        ;;
esac

从每个 rcX.d 目录创建到该脚本的链接(遵循“S”/“K”约定)。

ln rsync /etc/rc3.d/S91rsync
for i in `ls -1d /etc/rc*.d | grep -v 3`; do ln rsync $i/K02rsync; done

请参阅每个 rcX.d 目录中的自述文件并检查 init.d 的手册页。 这是手册页的一些内容:

rc?.d 目录中的文件名采用以下形式
[SK]nn,其中S表示开始这项工作,K表示
杀掉这个作业,nn是杀掉的相对序列号或者
开始工作。

进入状态(init S、0、2、3等)时,rc[S0-6]脚本
执行 /etc/rc[S0-6].d 中以 K 为前缀的脚本
后面是那些带有 S 前缀的脚本。当执行每个
/etc/rc[S0-6] 目录之一 /sbin/rc[S0-6] 中的脚本
脚本传递一个参数。 它传递了参数“stop”
对于以 K 为前缀的脚本以及以参数“start”开头的脚本
以 S 为前缀。应用相同的序列没有坏处
多个脚本的编号。

On Solaris 10 or later using SMF is recommended, but on an earlier release you'd create an init script in /etc/init.d and link to it from the rcX.d directories. Here's a bare-bones example of an init script for launching an rsync daemon:

#!/sbin/sh

startcmd () {
    /usr/local/bin/rsync --daemon  # REPLACE WITH YOUR COMMANDS
}

stopcmd () {
    pkill -f "/usr/local/bin/rsync --daemon"  # REPLACE WITH YOUR COMMANDS
}

case "$1" in
'start')
        startcmd
        ;;
'stop')
        stopcmd
        ;;
'restart')
        stopcmd
        sleep 1
        startcmd
        ;;
*)
        echo "Usage: $0 { start | stop | restart }"
        exit 1
        ;;
esac

Create a link to the script from each rcX.d directory (following the "S"/"K" convention).

ln rsync /etc/rc3.d/S91rsync
for i in `ls -1d /etc/rc*.d | grep -v 3`; do ln rsync $i/K02rsync; done

See the README in each rcX.d directory and check the man page for init.d. Here's a bit of the man page:

File names in rc?.d directories are of the form
[SK]nn, where S means start this job, K means
kill this job, and nn is the relative sequence number for killing or
starting the job.

When entering a state (init S,0,2,3,etc.) the rc[S0-6] script
executes those scripts in /etc/rc[S0-6].d that are prefixed with K
followed by those scripts prefixed with S. When executing each
script in one of the /etc/rc[S0-6] directories, the /sbin/rc[S0-6]
script passes a single argu- ment. It passes the argument 'stop'
for scripts prefixed with K and the argument 'start' for scripts
prefixed with S. There is no harm in applying the same sequence
number to multiple scripts.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文