systemd 执行格式错误

systemd 执行格式错误

我有一个 java 文件,我正在尝试将其安装为服务。但我收到错误。以下是我的文件的内容和错误。我正在运行 Debian 8。

[Unit]
Description=App1Manager
After=syslog.target

[Service]
ExecStart=/usr/bin/jsvc -user root -cp /usr/share/java/commons-daemon.jar:/usr/local/myapp/bin/Manager.jar -pidfile /var/run/app1manager.pid

Type=forking

[Install]
WantedBy=multi-user.target

对于以下任一情况,我收到以下错误:

SYSTEMD_LOG_LEVEL=debug /lib/systemd/system/myapp1 
SYSTEMD_LOG_LEVEL=debug /etc/init.d/myapp1 

/etc/init.d/myapp1: line 1: [Unit]: command not found
/etc/init.d/myapp1: line 6: [Service]: command not found
/etc/init.d/myapp1: line 7: -user: command not found
/etc/init.d/myapp1: line 10: [Install]: command not found


Aug 12 12:04:39 debian systemd[3903]: Failed at step EXEC spawning /etc/init.d/myapp1: Exec format error
-- Subject: Process /etc/init.d/myapp1 could not be executed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- The process /etc/init.d/myapp1 could not be executed and failed.
--
-- The error number returned while executing this process is 8.
Aug 12 12:04:39 debian systemd[1]: myapp1.service: control process exited, code=exited status=203
Aug 12 12:04:39 debian systemd[1]: Failed to start (null).
-- Subject: Unit myapp1.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit myapp1.service has failed.
--
-- The result is failed.
Aug 12 12:04:39 debian systemd[1]: Unit myapp1.service entered failed state.

答案1

安装到systemd/system带有.service文件扩展名的;不需要设置可执行位。不要将 systemd 格式的服务文件安装到/etc/init.d/;这适用于旧版 SysVinit 风格的服务脚本。

要启动服务,请使用systemctl start myapp1.当您不确定服务是作为 systemd 还是 SysV 实现时,请使用service myapp1 start

要在启动时启用[给定适当的Install部分],请使用systemctl enable myapp1.

相关内容