3

We have a .conf file named private-api.conf in the location /etc/init , So my file location is - /etc/init/private-api.conf

The contents of my file is as following -

# 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

The next Command I need to fire is -

sudo initctl reload-configuration

After which I am supposed to run the Service, using the following command -

service private-api start/stop/restart/status

I get the following error when I do -
initctl: Unable to connect to Upstart: Failed to connect to socket /com/ubuntu/upstart: Connection refused

I found that in Ubuntu 16.04 upstarts don't work and have moved to Systemd now,
And that the Systemd file needs to be in the location - /etc/systemd/system, with the file extension .service
After which to run the Systemd following 2 commands need to be fired -
1. sudo systemctl daemon-reload
2. sudo systemctl start xyz.service

I am referring the following links -
1. https://wiki.ubuntu.com/SystemdForUpstartUsers
2. https://www.digitalocean.com/community/tutorials/understanding-systemd-units-and-unit-files

Here's what I've achieved so far using the above refs -

[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

I reloaded my Systemd service -
sudo systemctl daemon-reload

But when I check service status, I get absolute path errors -

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.


Can someone help me convert my current upstart .conf script?

Dev1ce
  • 5,390
  • 17
  • 90
  • 150
  • I'm chipping-away at the same damn thing. I just found this which looks promising. At least, for me: https://www.digitalocean.com/community/questions/convert-run-at-startup-script-from-upstart-to-systemd-for-ubuntu-16 – James T Snell Mar 24 '17 at 19:51
  • FWIW, the manpages systemd.service and systemd.exec are really all what you need. The documentation is pretty extensive and complete. – Jonas Schäfer Apr 05 '17 at 08:47
  • hi, I've updated my question, can you help find the flaw in my Systemd service? My upstart script is also included in the question. Thanks :) – Dev1ce Apr 05 '17 at 09:01

1 Answers1

1

You have already set the WorkingDirectory, you can directly use the command from your script.

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

Hopefully this works.

DarkKnight
  • 597
  • 3
  • 15