新贵到Systemd

时间:2017-03-24 11:21:03

标签: 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:无法连接到socket / com / ubuntu / upstart:拒绝连接

我发现在Ubuntu 16.04新手不能工作并且现在已经转移到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.


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

1 个答案:

答案 0 :(得分:1)

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

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

希望这有效。