Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jetty-users] Stopping embedded Jetty (not webapps) gracefully in systemd service

Hello,

in CentOS 7 Linux I have followed the guide

https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/System_Administrators_Guide/sect-Managing_Services_with_systemd-Unit_Files.html

and have created a custom service unit for systemd 
in the file /etc/systemd/system/words.service

[Unit]
Description=Words WebSocket Server
After=network-online.target

[Service]
Type=simple
User=nobody
Group=nobody
PrivateTmp=false
ExecStart=/usr/bin/java -classpath '/usr/share/java/words/*' de.afarber.websockets.MyHandler 123.123.123.123:8080
ExecStop=/bin/kill -TERM ${MAINPID}

[Install]
WantedBy=multi-user.target

Starting the service works then and WebSocket
connections are accepted at port 8080.

But when I try to stop the service with

# systemctl stop words

It reports a failed status:

# systemctl status -l words
● words.service - Words WebSocket Server
   Loaded: loaded (/etc/systemd/system/words.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Sun 2016-06-19 12:23:03 CEST; 3h 11min ago
  Process: 9139 ExecStop=/bin/kill -TERM ${MAINPID} (code=exited, status=0/SUCCESS)
  Process: 7340 ExecStart=/usr/bin/java -classpath /usr/share/java/words/* de.afarber.websockets.MyHandler 123.123.123.123:8080 (code=exited, status=143)
 Main PID: 7340 (code=exited, status=143)

Jun 19 12:20:39 www java[7340]: 2016-06-19 12:20:39.061:INFO:oejs.Server:main: Started @145ms
Jun 19 12:22:17 www java[7340]: 2016-06-19 12:22:17.210:INFO:daw.MyListener:qtp666641942-16: onWebSocketConnect: /217.246.219.11:53817
Jun 19 12:22:21 www java[7340]: 2016-06-19 12:22:21.770:INFO:daw.MyListener:qtp666641942-17: onWebSocketText: 
Jun 19 12:23:03 www systemd[1]: Stopping Words WebSocket Server...
Jun 19 12:23:03 www systemd[1]: words.service: main process exited, code=exited, status=143/n/a
Jun 19 12:23:03 www systemd[1]: Stopped Words WebSocket Server.
Jun 19 12:23:03 www systemd[1]: Unit words.service entered failed state.
Jun 19 12:23:03 www systemd[1]: words.service failed.
Jun 19 15:22:11 www systemd[1]: Stopped Words WebSocket Server.

unfortunately talks only about "old style" init services.

The modern Linux distributions use systemd (or upstart),
has anybody tried creating a similar service for systemd?

Here is the source code of my embedding Jetty program:
https://github.com/afarber/jetty-newbie/tree/master/WebsocketHandler

Thank you
Alex

Back to the top