Monday, 4 December 2017

And there's more - running WebSphere Liberty Profile via Linux scripts

Following on from this earlier post: -


here's a similar script to start a WebSphere Liberty Profile (WLP) runtime via systemd : -

Create the systemd script - as root

vi /etc/systemd/system/mfp.service

[Unit]
Description=IBM WebSphere Liberty Profile
After=network.target

[Service]
Type=forking
User=wasadmin
ExecStart=/opt/ibm/WebSphere/Liberty/bin/server start
ExecStop=/opt/ibm/WebSphere/Liberty/bin/server stop
PrivateTmp=true
LimitNOFILE=infinity

[Install]
WantedBy=multi-user.target


Reload systemd - as root

sudo systemctl daemon-reload

Start the service - as root

systemctl start mfp

Check the service status - as root

systemctl status mfp

● mfp.service - IBM WebSphere Liberty Profile
   Loaded: loaded (/etc/systemd/system/mfp.service; disabled; vendor preset: disabled)
   Active: active (running) since Mon 2017-12-04 21:29:54 GMT; 4s ago
  Process: 5730 ExecStart=/opt/ibm/WebSphere/Liberty/bin/server start (code=exited, status=0/SUCCESS)
 Main PID: 5753 (java)
   CGroup: /system.slice/mfp.service
           └─5753 /opt/ibm/Java/jre/bin/java -javaagent:/opt/ibm/WebSphere/Liberty/bin/tools/ws-javaagent.jar -Djava.awt.headless=true -jar /opt/ibm/WebSphere/Liberty/bin/tools/ws-server.jar defaultS...

Dec 04 21:29:47 mfp.uk.ibm.com systemd[1]: Starting IBM WebSphere Liberty Profile...
Dec 04 21:29:47 mfp.uk.ibm.com server[5730]: Starting server defaultServer.
Dec 04 21:29:54 mfp.uk.ibm.com server[5730]: Server defaultServer started with process ID 5753.
Dec 04 21:29:54 mfp.uk.ibm.com systemd[1]: Started IBM WebSphere Liberty Profile.


Stop the service - as root

systemctl stop mfp

And there we have it …

One additional thing - I needed to ensure that the JAVA_HOME variable was set in order that WLP could start up.

I did this using the server.env file: -

vi /opt/ibm/WebSphere/Liberty/usr/servers/defaultServer/server.env 

and appended: -

JAVA_HOME=/opt/ibm/Java/jre

Otherwise, I ended up with exceptions such as: -

Job for mfp.service failed because the control process exited with error code. See "systemctl status mfp.service" and "journalctl -xe" for details.

and: -

Dec 04 21:32:50 mfp.uk.ibm.com server[6066]: /opt/ibm/WebSphere/Liberty/bin/server: line 833: java: command not found

I suspect that this is because the root user is spawning new shells which aren't picking up the .bashrc for the wasadmin user.

No comments: