ubuntu-16.04 - Upstart 到 Systemd

标签 ubuntu-16.04 systemd upstart

我们在 /etc/init 位置有一个名为 private-api.conf.conf 文件, 所以我的文件位置是 - /etc/init/private-api.conf

我的文件内容如下-

# start when server starts
start on runlevel [23456]
# Stop when server shuts down/reboots
stop on shutdown

#Respawn the process if it crashes
#If it respawns more than 10 times in 5 seconds stop
respawn
respawn limit 10 5

#expect fork

script
    cd /home/ubuntu/private-api && exec java -jar -Dspring.profiles.active=stage private-api-SNAPSHOT.jar > private-api.log 2>&1
end script

我需要执行的下一个命令是 -

sudo initctl reload-configuration

之后我应该运行该服务,使用以下命令 -

service private-api start/stop/restart/status

当我这样做时出现以下错误 -
initctl:无法连接到 Upstart:无法连接到套接字/com/ubuntu/upstart:连接被拒绝

我发现在 Ubuntu 16.04 中 upstarts 不起作用,现在已经转移到 Systemd,
并且 Systemd 文件需要位于位置 - /etc/systemd/system,文件扩展名为 .service
之后运行 Systemd 需要触发以下 2 个命令 -
1. sudo systemctl daemon-reload
2. sudo systemctl start xyz.service

我指的是以下链接 -
1. https://wiki.ubuntu.com/SystemdForUpstartUsers
2. https://www.digitalocean.com/community/tutorials/understanding-systemd-units-and-unit-files

到目前为止,这是我使用上述引用文献所取得的成就 -

[Unit]
Description=Upstart for Private API
After=network.target network-online.target
Wants=network-online.target

[Service]
User=root
WorkingDirectory=/home/ubuntu/private-api
ExecStart=/usr/bin/java -classpath home/ubuntu/private-api/private-api-0.0.1-SNAPSHOT.jar -Dspring.profiles.active=stage > home/ubuntu/private-api/private-api.log 2>&1
SuccessExitStatus=143
Restart=on-failure
RestartSec=120s

[Install]
WantedBy=multi-user.target

我重新加载了我的 Systemd 服务 -
sudo systemctl daemon-reload

但是当我检查服务状态时,出现绝对路径错误 -

sudo systemctl status private-api.service

    Apr 05 08:48:56 ip-10-10-1-153 systemd[1]: [/etc/systemd/system/private-api.service:9] Executable path is not absolute, ignoring: ExecStart=/usr/bin/java -classpath /home/ubuntu/private/astro-private-0.0.1-SNAPSHOT.jar -Dspring.profiles.active=dev > private.log 2>&1
Apr 05 08:48:56 ip-10-10-1-153 systemd[1]: private-api.service: Service lacks both ExecStart= and ExecStop= setting. Refusing.
Apr 05 08:49:07 ip-10-10-1-153 systemd[1]: [/etc/systemd/system/private-api.service:9] Executable path is not absolute, ignoring: ExecStart=/usr/bin/java -classpath /home/ubuntu/private/astro-private-0.0.1-SNAPSHOT.jar -Dspring.profiles.active=dev > private.log 2>&1
Apr 05 08:49:07 ip-10-10-1-153 systemd[1]: private-api.service: Service lacks both ExecStart= and ExecStop= setting. Refusing.
Apr 05 08:51:40 ip-10-10-1-153 systemd[1]: [/etc/systemd/system/private-api.service:9] Executable path is not absolute, ignoring: ExecStart=/usr/bin/java -classpath /home/ubuntu/private/astro-private-0.0.1-SNAPSHOT.jar -Dspring.profiles.active=dev > /home/ubuntu/private/private.log 2>&1
Apr 05 08:51:40 ip-10-10-1-153 systemd[1]: private-api.service: Service lacks both ExecStart= and ExecStop= setting. Refusing.
Apr 05 09:17:41 ip-10-10-1-153 systemd[1]: [/etc/systemd/system/private-api.service:9] Executable path is not absolute, ignoring: ExecStart=/usr/bin/java -classpath /home/ubuntu/private/astro-private-0.0.1-SNAPSHOT.jar -Dspring.profiles.active=dev > /home/ubuntu/private/private.log 2>&1
Apr 05 09:17:41 ip-10-10-1-153 systemd[1]: private-api.service: Service lacks both ExecStart= and ExecStop= setting. Refusing.
Apr 05 09:17:59 ip-10-10-1-153 systemd[1]: [/etc/systemd/system/private-api.service:9] Executable path is not absolute, ignoring: ExecStart=/usr/bin/java -classpath /home/ubuntu/private/astro-private-0.0.1-SNAPSHOT.jar -Dspring.profiles.active=dev > /home/ubuntu/private/private.log 2>&1
Apr 05 09:17:59 ip-10-10-1-153 systemd[1]: private-api.service: Service lacks both ExecStart= and ExecStop= setting. Refusing.


有人可以帮我转换我当前的 upstart .conf 脚本吗?

最佳答案

您已经设置了工作目录,您可以直接使用脚本中的命令。

ExecStart=/usr/bin/java -jar -Dspring.profiles.active=stage > private-api.log 2>&1

希望这能奏效。

关于ubuntu-16.04 - Upstart 到 Systemd,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42998212/

相关文章:

cassandra - 如何在没有 Cassandra 数据库的情况下安装 Datastax DevCenter

java - Eclipse 在 Ubuntu 中挂起

linux - nginx安装出现问题,不知道如何解决

ruby - 无法在 upstart 调用的 ruby​​ 脚本中导入 readline

python - 使用 python : execute service or systemd or init. d 脚本进行进程管理

environment-variables - 如何在Upstart脚本的启动前设置环境变量?

python - 如何使用 Python 在 Ubuntu 中创建自己的命令

c# - .NET Core SQLite 'database is locked' 仅在 Linux 上

linux - 如何使 sysfs 更改在 centos 7 (systemd) 中持久化

systemd - systemctl status 为 systemctl status(不是底层服务)中的错误返回什么返回码?