Temos um trabalho do Upstart em /etc/init/private-api.conf
, contendo:
# 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
O próximo comando que eu preciso disparar é:
sudo initctl reload-configuration
Depois disso, devo executar o serviço usando o seguinte comando:
service private-api start/stop/restart/status
Recebo o seguinte erro quando faço :
initctl: Unable to connect to Upstart: Failed to connect to socket /com/ubuntu/upstart: Connection refused
Descobri que no Ubuntu 16.04 o Upstart não é usado e agora mudei para o Systemd , e que o arquivo Systemd precisa estar no local - /etc/systemd/system
, com a extensão do arquivo .service
. Após o qual executar o serviço systemd após 2 comandos precisam ser disparados:
sudo systemctl daemon-reload
sudo systemctl start xyz.service
Estou me referindo aos seguintes links:
- link
- link
Aqui está o que consegui até agora usando as referências acima:
[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
Eu recarreguei meu serviço Systemd:
sudo systemctl daemon-reload
Mas quando eu verifico o status do serviço, recebo erros absolutos de caminho:
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.
Alguém pode me ajudar a converter meu atual script .conf de upstart?
Saída de 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
Saída do 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