2

We have an Upstart job in /etc/init/private-api.conf, containing:

# 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 Upstart isn't used 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 service following 2 commands need to be fired:

sudo systemctl daemon-reload
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?

Output of systemctl show private-api.service-

Type=oneshot
Restart=on-failure
NotifyAccess=none
RestartUSec=2min
TimeoutStartUSec=infinity
TimeoutStopUSec=1min 30s
RuntimeMaxUSec=infinity
WatchdogUSec=0
WatchdogTimestampMonotonic=0
FailureAction=none
PermissionsStartOnly=no
RootDirectoryStartOnly=no
RemainAfterExit=no
GuessMainPID=yes
MainPID=0
ControlPID=0
FileDescriptorStoreMax=0
NFileDescriptorStore=0
StatusErrno=0
Result=success
ExecMainStartTimestampMonotonic=0
ExecMainExitTimestampMonotonic=0
ExecMainPID=0
ExecMainCode=0
ExecMainStatus=0
Slice=system.slice
MemoryCurrent=18446744073709551615
CPUUsageNSec=18446744073709551615
TasksCurrent=18446744073709551615
Delegate=no
CPUAccounting=no
CPUShares=18446744073709551615
StartupCPUShares=18446744073709551615
CPUQuotaPerSecUSec=infinity
BlockIOAccounting=no
BlockIOWeight=18446744073709551615
StartupBlockIOWeight=18446744073709551615
MemoryAccounting=no
MemoryLimit=18446744073709551615
DevicePolicy=auto
TasksAccounting=no
TasksMax=18446744073709551615
UMask=0022
LimitCPU=18446744073709551615
LimitCPUSoft=18446744073709551615
LimitFSIZE=18446744073709551615
LimitFSIZESoft=18446744073709551615
LimitDATA=18446744073709551615
LimitDATASoft=18446744073709551615
LimitSTACK=18446744073709551615
LimitSTACKSoft=8388608
LimitCORE=18446744073709551615
LimitCORESoft=0
LimitRSS=18446744073709551615
LimitRSSSoft=18446744073709551615
LimitNOFILE=4096
LimitNOFILESoft=1024
LimitAS=18446744073709551615
LimitASSoft=18446744073709551615
LimitNPROC=31855
LimitNPROCSoft=31855
LimitMEMLOCK=65536
LimitMEMLOCKSoft=65536
LimitLOCKS=18446744073709551615
LimitLOCKSSoft=18446744073709551615
LimitSIGPENDING=31855
LimitSIGPENDINGSoft=31855
LimitMSGQUEUE=819200
LimitMSGQUEUESoft=819200
LimitNICE=0
LimitNICESoft=0
LimitRTPRIO=0
LimitRTPRIOSoft=0
LimitRTTIME=18446744073709551615
LimitRTTIMESoft=18446744073709551615
WorkingDirectory=/home/ubuntu/private-api
OOMScoreAdjust=0
Nice=0
IOScheduling=0
CPUSchedulingPolicy=0
CPUSchedulingPriority=0
TimerSlackNSec=50000
CPUSchedulingResetOnFork=no
NonBlocking=no
StandardInput=null
StandardOutput=journal
StandardError=inherit
TTYReset=no
TTYVHangup=no
TTYVTDisallocate=no
SyslogPriority=30
SyslogLevelPrefix=yes
SyslogLevel=6
SyslogFacility=3
SecureBits=0
CapabilityBoundingSet=18446744073709551615
AmbientCapabilities=0
User=root
MountFlags=0
PrivateTmp=no
PrivateNetwork=no
PrivateDevices=no
ProtectHome=no
ProtectSystem=no
SameProcessGroup=no
UtmpMode=init
IgnoreSIGPIPE=yes
NoNewPrivileges=no
SystemCallErrorNumber=0
RuntimeDirectoryMode=0755
KillMode=control-group
KillSignal=15
SendSIGKILL=yes
SendSIGHUP=no
Id=private-api.service
Names=private-api.service
Requires=sysinit.target
Wants=network-online.target
Conflicts=shutdown.target
Before=shutdown.target
After=network.target basic.target systemd-journald.socket sysinit.target network-online.target
RequiresMountsFor=/home/ubuntu/private-api
Description=Upstart for AMS private-CMS
LoadState=error
ActiveState=inactive
SubState=dead
FragmentPath=/etc/systemd/system/private-api.service
UnitFileState=disabled
UnitFilePreset=enabled
StateChangeTimestampMonotonic=0
InactiveExitTimestampMonotonic=0
ActiveEnterTimestampMonotonic=0
ActiveExitTimestampMonotonic=0
InactiveEnterTimestampMonotonic=0
CanStart=no
CanStop=no
CanReload=no
CanIsolate=no
StopWhenUnneeded=no
RefuseManualStart=no
RefuseManualStop=no
AllowIsolate=no
DefaultDependencies=yes
OnFailureJobMode=replace
IgnoreOnIsolate=no
NeedDaemonReload=no
JobTimeoutUSec=infinity
JobTimeoutAction=none
ConditionResult=no
AssertResult=no
ConditionTimestampMonotonic=0
AssertTimestampMonotonic=0
LoadError=org.freedesktop.DBus.Error.InvalidArgs "Invalid argument"
Transient=no
StartLimitInterval=10000000
StartLimitBurst=5
StartLimitAction=none

Output of cat private-api.service -

[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
  • Is that the entire output of systemctl status private-api.service? – muru Apr 5 '17 at 9:16
  • hi , just updated the entire error, also I am doubtful about where to specify my Java Spring boot's active .properties. Issue probably in ExecStart section. – Ani Apr 5 '17 at 9:22
  • Did you edit the service file after originally creating it? If so, did you run systemctl daemon-reload again after editing? I tried the service file in the question, and I don't get the "Executable path is not absolute" error. – muru Apr 5 '17 at 9:24
  • I fired -> sudo systemctl daemon-reload after editing my .service – Ani Apr 5 '17 at 9:26
  • Add the output of systemctl show private-api.service and systemctl cat private-api.service as well. – muru Apr 5 '17 at 9:28
2

First, the file you've posted does have "absolute path" error reported, as checked on Ubuntu 16.04 with systemd 229. You can check the syntax of the file yourself with:

systemd-analyze verify /etc/systemd/system/private-api.service

Second, there's no need to include User=root in the file. System units are run by root as default.

Third, attempting to redirect the output of the service this way may not work and is not recommended. systemd has StandardOutput= and StandardInput= directives to control where this output goes. By default, it does something useful which it send the data to the systemd journal. if you want to review the logs you for just your service, you can use:

journalctl -u private-api
0

Several things I noticed:

  1. I think the ExecStart parameter might be wrong. Have you tried it in a console: Copy the command and see if it works "on its own"?

Is java really installed under /usr/bin/java? ls -l /usr/bin/java

  1. I think there's a slash missing at the path of the jar-file:

ExecStart=/usr/bin/java -classpath home/ubuntu/private-api/private-api-0.0.1-SNAPSHOT.jar

should be

ExecStart=/usr/bin/java -classpath /home/ubuntu/private-api/private-api-0.0.1-SNAPSHOT.jar

Same with the path to the log-file.

  1. You need a ExecStop script that tells systemd how to shutdown your service gracefully.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.