如何在systemd下调试旧的initd脚本?

Gen*_*ent 5 linux opensuse init systemd systemctl

我有一个较旧的 initd 脚本来启动我的应用程序。它在旧版本的 SuSE 下运行良好,但在 Open SuSE 12.3 上失败。

奇怪的是

cd /etc/init.d ; ./script start
Run Code Online (Sandbox Code Playgroud)

工作正常。

/etc/init.d/script start
Run Code Online (Sandbox Code Playgroud)

显示重定向到 systemctl,但不启动我的应用程序(也不显示 initd 脚本的任何输出)。

我没有看到任何日志条目显示出了什么问题。我看到的唯一条目是在 /var/log/messages 中,说明应用程序已启动。

我该如何调试?

Mar*_*iae 1

该脚本之所以有这种行为,是因为 OpenSuse 12.3 用 systemd 取代了旧的 sysvinit,systemd 是一个控制整个启动过程的系统管理守护进程。

描述由 systemd 启动的服务的脚本格式与 sysvinit 的格式不同,因此您的脚本失败也就不足为奇了。一旦脚本正确设置,通过 systemctl 进行的操作就很简单:

sudo systemctl enable/disable your-service
Run Code Online (Sandbox Code Playgroud)

启用或禁用它,通常

sudo systemctl start/stop/status your-service
Run Code Online (Sandbox Code Playgroud)

启动它、停止它、查询它的状态。

典型的自定义服务脚本位于 /etc/systemd/system 文件夹中,以后缀 .service 结尾,格式如下:

 [Unit]
 Description=sdbarker.com Chiliproject
 Requires=mysqld.service nginx.service
 Wants=mysqld.service nginx.service

 [Service]
 User=www-data
 WorkingDirectory=/path/to/chiliproject/install
 ExecStart=/usr/bin/bundle 
 PIDFile=/path/to/chiliproject/install/tmp/pids/server.pid

 [Install]
 WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,大多数条目都是不言自明的。如果不了解有关您的脚本的更多信息,我无法提供进一步的帮助,但您会在此 Arch Linux Wiki 页面中找到编写正确的自定义服务脚本所需的信息。