lsc
lsc copied to clipboard
Make a systemd script
I don't think this issue was proposed previously, so I post it here. It was first proposed by [email protected] in the mailing list (2018-02-13 13:50 GMT+01:00)
[Unit]
Description=LSC sync broker
After=network.target
[Service]
PrivateTmp=true
PIDFile=/run/lsc.pid
Type=oneshot
#Environment=JAVA_HOME=/usr/jvm/lib/latest
User=lsc
Group=lsc
ExecStart=/opt/lsc/bin/lsc -a all -f /opt/lsc/etc
[Install]
WantedBy=multi-user.target
Need to be tested.
Check that we can read logs with journalctl
PIDFile is not required with Type=oneshot. We run lsc from systemd with a few more hardening options (I believe ExecStart and ReadWritePaths are specific to our setup, they should be made generic).
[root@ldap-test-01 lsc]# systemctl cat lsc-main
# /etc/systemd/system/lsc-main.service
#
# Ansible managed
#
[Unit]
Description=Run LSC jobs | main
[Service]
Type=oneshot
ExecStart=/etc/lsc/run-main
User=lsc
Group=lsc
PrivateTmp=true
PrivateDevices=true
ProtectSystem=strict
ProtectKernelTunables=yes
ProtectControlGroups=yes
ReadWritePaths=/var/log/lsc
UMask=0007
[Install]
WantedBy=multi-user.target
taking a look.
I have proposed a systemd example in https://github.com/lsc-project/lsc/pull/230
- it runs
lsc -f /etc/lsc -s all - stdout logs are displayed in
journalctl -xeu lsc.service
Certainly not perfect because the admin still needs to adapt the synchronization options (-s, -c, -a)
Solution to test: use the standard way to override a systemd service : https://askubuntu.com/questions/659267/how-do-i-override-or-configure-systemd-services
I have added a new commit (6b9afd78) for:
- adding debian package recipes
- adding RHEL package recipes
- fixing some minor things
- renaming the systemd service names and corresponding default files, which I didn't find meaningful:
lsc-oneshot -> lsc-sync lsc -> lsc-async /etc/default/lsc-examplesynctask -> /etc/default/lsc-sync /etc/default/lsc-examplesynctask -> /etc/default/lsc-async
with these new rules, it is easier to understand which task is intended to be launched with which default file.
I have tested the new packages:
- debian 12: build ok, install ok, running ok
- rockylinux 9: build ok, install ok, running impossible because systemd not available on my container. But everything seems well-deployed.
@xavierba : I have some new remarks:
- could you give a look and tell me if it is ok for you?
BuildRequires: systemdmakes it impossible to build the package on debian systems. (which worked before...) Too bad... but if you have an alternative, feel free!- I didn't get this from your PR:
%systemd_postun_with_restart lsc.service, because I am not sure if it is a good idea to restart the service when doing an upgrade, whatever the use case. (but I confess I am not sure of the meaning of systemd_postun_with_restart in this situation) - when everything will be ok, could you resolve conflicts in https://github.com/lsc-project/lsc/pull/246 ?
As pointed out by @xavierba , we should take advantage of this issue to drop the support of init.d. I am favourable for doing so, because systemd is now the default component:
- since centos 7
- since debian 8
Anyway, we no longer support lsc packages for OS older that these.
If everyone is ok with that, I am going to remove init.d in #260
If everyone is ok with that, I am going to remove init.d in https://github.com/lsc-project/lsc/pull/260
Ok for me
systemd scripts seems ready in #260 I am going to merge.
What I have done since last review:
- removed /etc/init.d/lsc support
- removed useless sed on /etc/default/lsc-* files (since these variables are now defined in corresponding systemd unit files)
- fix pid filename directly in systemd unit file
- removed
%systemd_preun [email protected]since systemd doesn't know which instance to stop (even with a joker) - removed /etc/default/lsc (since not used any more)
- clean and simplify /etc/default/lsc-sync and /etc/default/lsc-async
- write the documentation (see https://github.com/lsc-project/documentation/blob/main/source/run.rst#using-systemd-service)
- test build + install + run + remove on debian12: OK
- test build + install +run + remove on rocky9: OK (warnings during preinstall, but not due to systemd)
- split long lines