Using ‘systemd’ to Manage HAPEE Services

Systemd is an initialization (‘init’) system used by certain Linux distributions to bootstrap the user space and subsequently manage all processes.

This section applies to Centos 7 and Debian 8 only. The other Linux distributions rely on init scripts

The table below summarizes the services that systemd manages directly and the ones that sysv manages. The service list may change based on the subscription level and installed packages:

Service Init system
hapee-1.6 sysv
hapee-1.6-lb systemd
hapee-1.6-log sysv
hapee-1.6-rhi sysv
hapee-1.6-route sysv
hapee-1.6-route6 sysv
hapee-1.6-snmp sysv
hapee-1.6-vrrp sysv
The commands listed here apply to both services managed by systemd or sysv.

Interaction between systemd and HAProxy

When a system uses systemd, the following process unfolds:

  • systemd starts a “wrapper” process, which is used to handle communication between systemd and HAProxy. This wrapper process name is hapee-lb-systemd-wrapper
  • hapee-lb-systemd-wrapper then parses the configuration file and starts up a new process called hapee-lb-master. Its role is to parse and load the configuration file and to create the required number of HAProxy processes.
  • Running HAProxy processes are called hapee-lb

The process basically gives us the following cgroup tree. A cgroup (abbreviated from control groups) is a Linux kernel feature that limits, accounts for, and isolates the resource usage (CPU, memory, disk I/O, network, etc.) of a collection of processes.

Main PID: PID from (hapee-lb-systemd-wrapper)
CGroup: /user/system.slice/hapee-1.6-lb.service
	├─PID /opt/hapee-1.6/sbin/hapee-lb-systemd-wrapper ...
	├─PIDa /opt/hapee-1.6/sbin/hapee-lb-master
	├─PIDb /opt/hapee-1.6/sbin/hapee-lb ...	
	└─PIDc /opt/hapee-1.6/sbin/hapee-lb ...

Systemd sends signals to hapee-lb-systemd-wrapper. This process propagates its environment to its descendants. When a reload occurs, hapee-lb-systemd-wrapper itself is not reloaded, but passes the information to hapee-lb-master to run the reload operation.

Enable a service

By default, the services installed with HAPEE are not enabled.

To enable a service, run: systemctl enable <service name>

– Output example when enabling a systemd based service:

# systemctl enable hapee-1.6-lb
Created symlink from /etc/systemd/system/multi-user.target.wants/hapee-1.6-lb.service to /usr/lib/systemd/system/hapee-1.6-lb.service.

– Output example when enabling a sysv based service:

# systemctl enable hapee-1.6-log
hapee-1.6-log.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig hapee-1.6-log on

Start a service

To start a service, run: systemctl start <service name>

  • Example to start hapee-1.6-lb: systemctl start hapee-1.6-lb
  • Example to start hapee-1.6-log: systemctl start hapee-1.6-log

Stop a service

To stop a service, run: systemctl stop <service name>

  • Example to stop hapee-1.6-lb: systemctl stop hapee-1.6-lb
  • Example to stop hapee-1.6-log: systemctl stop hapee-1.6-log

Restart a service

To restart a service, run: systemctl restart <service name>

  • Example to restart hapee-1.6-lb: systemctl restart hapee-1.6-lb
  • Example to restart hapee-1.6-log: systemctl restart hapee-1.6-log

Reload a service

To reload a service, run: systemctl reload <service name>

  • Example to reload hapee-1.6-lb: systemctl reload hapee-1.6-lb
  • Example to reload hapee-1.6-log: systemctl reload hapee-1.6-log
WARNING: systemd has a severe limitation concerning reload: the environment variables do not get reloaded during a service reload. You must perform a service restart.
This is because the environment variables are loaded by hapee-lb-systemd-wrapper at startup and they cannot be refreshed at reload. See Interaction between systemd and HAProxy.

Check the status of a service

To know the status of a service, run: systemctl status <service name>

Example status output for hapee-1.6-lb:

# systemctl status hapee-1.6-lb
	hapee-1.6-lb.service - HAPEE Load Balancer		
	Loaded: loaded (/usr/lib/systemd/system/hapee-1.6-lb.service; enabled; vendor preset: disabled)			
	Active: active (running) since Wed 2016-02-17 17:10:26 UTC; 1s ago

Main PID: 417 (hapee-lb-system)
	CGroup: /user/system.slice/hapee-1.6-lb.service
		├─417 /opt/hapee-1.6/sbin/hapee-lb-systemd-wrapper -f /etc/hapee-1.6/hapee-lb.cfg -p /run/hapee-1.6-lb.pid			
		├─418 /opt/hapee-1.6/sbin/hapee-lb-master
		└─419 /opt/hapee-1.6/sbin/hapee-lb -f /etc/hapee-1.6/hapee-lb.cfg -p /run/hapee-1.6-lb.pid -Ds

Feb 17 17:10:26 centos7 systemd[1]: Started HAPEE Load Balancer.
Feb 17 17:10:26 centos7 systemd[1]: Starting HAPEE Load Balancer...
Feb 17 17:10:26 centos7 hapee-lb-systemd-wrapper[417]: haproxy-systemd-wrapper: executing /opt/hapee-1.6/sbin/hapee-lb -f 
/etc/hapee-1.6/hapee-lb.cfg -p /run/hapee-1.6-lb.pid -Ds

Example status output for hapee-1.6-log: systemctl reload hapee-1.6-log

# systemctl status hapee-1.6-log
hapee-1.6-log.service - SYSV: HAPEE LOG : Log collector module (rsyslog)
Loaded: loaded (/etc/rc.d/init.d/hapee-1.6-log)
Active: active (running) since Wed 2016-02-17 17:01:44 UTC; 5s ago
Docs: man:systemd-sysv-generator(8)
Process: 380 ExecStop=/etc/rc.d/init.d/hapee-1.6-log stop (code=exited, status=0/SUCCESS)
Process: 401 ExecReload=/etc/rc.d/init.d/hapee-1.6-log reload (code=exited, status=0/SUCCESS)
Process: 387 ExecStart=/etc/rc.d/init.d/hapee-1.6-log start (code=exited, status=0/SUCCESS)
Main PID: 394 (rsyslogd)
CGroup: /user/system.slice/hapee-1.6-log.service
└─394 /sbin/rsyslogd -c7 -f /etc/hapee-1.6/hapee-log.cfg -i /var/run/hapee-1.6/hapee-log.pid
Feb 17 17:01:44 centos7 systemd[1]: Starting SYSV: HAPEE LOG : Log collector module (rsyslog)...
Feb 17 17:01:44 centos7 hapee-1.6-log[387]: Starting rsyslogd (rsyslog)
Feb 17 17:01:44 centos7 hapee-1.6-log[387]: [  OK  ]
Feb 17 17:01:44 centos7 systemd[1]: Started SYSV: HAPEE LOG : Log collector module (rsyslog).
Feb 17 17:01:48 centos7 hapee-1.6-log[401]: Reloading rsyslogd (rsyslog): [  OK  ]
Feb 17 17:01:48 centos7 systemd[1]: Reloaded SYSV: HAPEE LOG : Log collector module (rsyslog).