Starting WSO2 APIM as a Linux service using the Systemd (system daemon)
--
This article shows how we can start WSO2 APIM as a Linux service in a Linux VM using the Systemd (system daemon). Starting WSO2 APIM this way eliminates the need of starting the server manually by running the wso2server.sh script present under <APIM_HOME>/bin folder, every time there is a machine reboot/restart where the APIM is running. Once we start APIM as a Linux service, it automatically starts whenever machine reboot happens. We have used WSO2 APIM 3.2.0 for this article.
Steps:
1. Create a system unit file under /etc/systemd/system.
/etc/systemd/system/<wso2api-profile>.service
E.G: Create file as /etc/systemd/system/wso2apim.service
2. Use the below template to configure the startup process.
[Unit]
Description=WSO2 API Manager: <profile >
After=network.target
[Service]
Environment=JAVA_HOME=<JAVA_HOME_PATH>
ExecStart=/bin/sh <server_script_path > <optimize_params> start
ExecStop=/bin/sh <server_script_path> stop
ExecReload=/bin/sh <server_script_path> restart
PIDFile=<pid_file_path>
User=<user >
Group=<user_group>
Type=forking
Restart=on-failure
RestartSec=5
StartLimitInterval=60s
StartLimitBurst=3
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
E.G: We have created the above configuration as below in the wso2apim.service file:
[Unit]
Description=WSO2 API Manager3.2.0: All-In-One
After=network.target
[Service]
Environment=JAVA_HOME=/root/jres/java-11
ExecStart=/bin/sh /<APIM_HOME>/bin/wso2server.sh start
ExecStop=/bin/sh /<APIM_HOME>/bin/wso2server.sh stop
ExecReload=/bin/sh /<APIM_HOME>/bin/wso2server.sh restart
PIDFile=/<APIM_HOME>/wso2carbon.pid
User=root
Group=root
Type=forking
Restart=on-failure
RestartSec=5
StartLimitInterval=60s
StartLimitBurst=3
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
3. Reload the systems using the below command.
systemctl daemon-reload
4. Start the WSO2 APIM using the below command.
systemctl start <wso2api-profile>.service
E.G: systemctl start wso2apim.service
5. Execute the below command to check the status of wso2apim.service. You may see a PID file related issue on running this command which isn’t of much concern and can be ignored. Ensure that “WSO2 APIM started” message comes in the output.
systemctl status <wso2api-profile>.service
E.G: systemctl status wso2apim.service
6. Execute the below command to enable the wso2apim.service during machine reboot. This will start the WSO2 APIM automatically whenever there is a machine reboot.
systemctl enable <wso2api-profile>.service
E.G: systemctl enable wso2apim.service
7. You can go to the path /<APIM_HOME>/repository/logs and run the below command to trace the WSO2 APIM server logs to check if the server is starting successfully.
tail -100f wso2carbon.log