Introduction
This document describes how to create service files for init.d or Systemd for the EFM (Edge Fog Processing Module) Asset Manager.
Prerequisites
Requirements
Cisco recommends that you have knowledge of Linux.
Components Used
This document is not restricted to specific software and hardware versions.
The information in this document was created from the devices in a specific lab environment. All of the devices used in this document started with a cleared (default) configuration. If your network is live, ensure that you understand the potential impact of any command.
Configure
The EFM installation package does not contain service files for init.d or Systemd out of the box.
Here you can find a simple example to create a service file for the Asset Manager component of EFM.
For init.d
[root@cen7 ~]# cat /etc/init.d/assetmanager
#!/bin/bash
# parstream init script.
ASSETMANAGER_HOME="/opt/cisco/kinetic/asset_manager/"
ASSETMANAGER_USER="EFM"
case "$1" in
'start')
echo "Starting EFM Asset Manager daemon as user $ASSETMANAGER_USER"
sleep 2
su -c "cd $ASSETMANAGER_HOME;$ASSETMANAGER_HOME/bin/start.sh" $ASSETMANAGER_USER
;;
'stop')
echo "Stopping EFM Asset Manager daemons for user $ASSETMANAGER_USER"
su -c "cd $ASSETMANAGER_HOME;$ASSETMANAGER_HOME/bin/stop.sh" $ASSETMANAGER_USER
;;
*)
# usage
echo "usage: $0 start|stop"
exit 1
;;
esac
Ensure that you adjust the environment variables to match your environment: ASSETMANAGER_HOME and ASSETMANAGER_USER.
After the file is created, ensure that it is marked as executable.
For Systemd
[root@cen7 ~]# cat /etc/systemd/system/efm-assetmanager.service
[Unit]
Description=EFM Asset Manager
After=network.target
[Service]
Type=forking
User=EFM
WorkingDirectory=/opt/cisco/kinetic/asset_manager/
ExecStart=/opt/cisco/kinetic/asset_manager/bin/start.sh
ExecStop=/opt/cisco/kinetic/asset_manager/bin/stop.sh
[Install]
WantedBy=multi-user.target
Ensure that you adjust the configuration variables to match your environment: User=.
After the service file is created, ensure that you update the daemon files in systemd:
[root@cen7 ~]# systemctl daemon-reload
Verify
To verify if the scripts/service file work as expected, you can try to start and stop the service:
For init.d
[root@cen7 ~]# /etc/init.d/assetmanager start
Starting EFM Asset Manager daemon as user EFM
[root@cen7 ~]# nohup: redirecting stderr to stdout
[root@cen7 ~]# /etc/init.d/assetmanager stop
Stopping EFM Asset Manager daemons for user EFM
For Systemd
[root@cen7 ~]# systemctl start efm-assetmanager
[root@cen7 ~]#
[root@cen7 ~]# systemctl status efm-assetmanager
● efm-assetmanager.service - EFM Asset Manager
Loaded: loaded (/etc/systemd/system/efm-assetmanager.service; disabled; vendor preset: disabled)
Active: active (running) since Tue 2018-04-24 02:54:16 CEST; 5s ago
Process: 45098 ExecStop=/opt/cisco/kinetic/asset_manager/bin/stop.sh (code=exited, status=0/SUCCESS)
Process: 45235 ExecStart=/opt/cisco/kinetic/asset_manager/bin/start.sh (code=exited, status=0/SUCCESS)
Main PID: 45238 (java)
CGroup: /system.slice/efm-assetmanager.service
└─45238 java -classpath /opt/cisco/kinetic/asset_manager/lib/efm-servicelayer-1.5.0.12-fat.jar com.cisco.efm.application.ApplicationStarter
Apr 24 02:54:16 cen7 systemd[1]: Starting EFM Asset Manager...
Apr 24 02:54:16 cen7 systemd[1]: Started EFM Asset Manager.
[root@cen7 ~]#
[root@cen7 ~]# systemctl stop efm-assetmanager
As you can see, the EFM Asset Manager processes get started under the user you defined in the service files and everything gets cleaned up after it is requested to stop the services.
Troubleshoot
In case you experience issues to start, check these:
- Configurable parameters in the init.d or Systemd service file (user, paths)
- For SystemD: The output of systemctl status efm-assetmanager
- The output of journalctl --unit=efm-assetmanager