Closed tuxmaster5000 closed 3 years ago
When using /usr/share/rock/bin/rock.sh And when using "systemctl start rock" no process will running.
Please try to apply the same fix on rock.sh as in https://github.com/obiba/rock/commit/01cf528a750bdfd6ea9744041dfda6fac361fcd8 and let me know if it works now.
I build an fix for it, because the init.d start up is dead on current RHEL systems. RHEL6 is EOL an RHEL7 and newer use systemd instant. As far my service file is ready, I will append it.
Here is the final systemd script needed for modern RHEL aka CentOS systems:
[Unit] Description=Opal Rock service
[Service] WorkingDirectory=/var/lib/rock EnvironmentFile=/etc/default/rock User=rock LimitNOFILE=16384 ExecStart=/usr/bin/java $JAVA_ARGS -cp "${ROCK_HOME}/conf:${ROCK_DIST}/lib/*" -DROCK_HOME=$ROCK_HOME -DROCK_DIST=$ROCK_DIST -DROCK_LOG=$ROCK_LOG org.springframework.boot.loader.JarLauncher $ROCK_ARGS
[Install] WantedBy=network-online.target
I guess that rock.sh works with the fix I provided, right?
Oh one type here: is mus be: ExecStart=/usr/bin/java $JAVA_ARGS -cp "${ROCK_HOME}/conf:${ROCK_DIST}/lib/*" -DROCK_HOME=${ROCK_HOME} -DROCK_DIST=${ROCK_DIST} -DROCK_LOG=${ROCK_LOG} org.springframework.boot.loader.JarLauncher $ROCK_ARGS
Yes your commit will fix it.
Thanks for the systemd script, it works on ubuntu as well. Need to figure out how to migrate from init.d script to the systemd one in the package installation process.
For RHEL, simple remove the exchange the script and call systemctl daemon-reload in the %post section And then use the systemd macros in the rpm spec file. See here as an example: https://src.fedoraproject.org/rpms/httpd/blob/f34/f/httpd.spec
Call required to make systemd switch from an init.d script to the systemd one: systemctl daemon-reload
Could you try in CentOS if this RPM package works? Both for the case of an upgrade and a clean install. https://github.com/obiba/rock/releases/tag/1.1.0-beta That would be very helpful, thanks.
Yes I will try it on Monday and give you the feedback.
Thanks. Just tried on debian environment and it works.
FYI I have just rebuilt the 1.1.0-beta packages, to enable service start on system boot.
An clean install will work, but an update will fails. After the update of the package the status will fails with:
systemctl status rock
Failed to get properties: Access denied
Also the old init.d files are not removed. I think the pre script of the package must call "chkconfig --del rock" before the new files are installed,
Thanks for the test, this is very helpful! I have added the chkconfig trick. I am not sure for the systemctl issue. Some people reported some systemd issues (but this was a long time ago). Anyway I have made a new pre-release https://github.com/obiba/rock/releases/tag/1.1.0-beta2 if you could give it a try...
Now the old init symlinks are removed this is fine (comes from chkconfig) But the systemctl status rock call fails with the same error :( This can fixed with an "systemctl daemon-reload" call. But then I seen, that the service was not restarted with the package update. Only after an additional "systemctl restart rock" the current version of it will run. And then the new one will run, but the logs are going into /var/lib/rock/logs :( instant of /var/log/rocks
Please try this one https://github.com/obiba/rock/releases/tag/1.1.0-beta3 in which preinstall script ensures the service is stopped.
Regarding the logs, /var/lib/rock/logs is supposed to be a symlink to /var/log/rock
Now:
the same systemd problem:
systemctl status rock
Failed to get properties: Access denied
systemctl daemon-reload
systemctl status rock
...
Jun 07 12:46:54 localhost.localdomain systemd[1]: Started LSB: R server administrator.
systemctl restart rock
systemctl status rock
Jun 07 12:49:00 localhost.localdomain systemd[1]: Started OBiBa Rock service.
/var/lib/rock/logs are not an symlink to /var/log/rocks:
LANG=C ll /var/lib/rock/
total 0
drwxr-x---. 3 rock adm 20 Jun 7 12:46 R
lrwxrwxrwx. 1 rock adm 9 Jun 7 12:46 conf -> /etc/rock
drwxr-xr-x. 2 rock nobody 23 Jun 7 12:49 logs
drwxr-xr-x. 3 rock nobody 14 Jun 7 12:49 work
Obviously the postinstall script is not executed because this is the one that does the missing systemctl
calls and the logs symlink.
Where can I find the spec file for the rpm build? Then I can take an look into it.
Some scriptlet doc: https://docs.fedoraproject.org/en-US/packaging-guidelines/Scriptlets/
The RPM package is built using the RPM maven plugin: https://github.com/obiba/rock/blob/systemd/pom.xml#L69-L176 https://www.mojohaus.org/rpm-maven-plugin/adv-params.html#Scripts
Oh, then I can't help, because I only build rpm packages direct from spec file, which is the official way. And it looks like mave have its own way. :( I think this will be the reason why some scripts fails. Does maven create an temporary spec file or an srpm file? If yes, please attach it, so that I can "debug" it.
I cannot found srpm file but I have the spec file (renamed with .txt for github upload).
This will helps.
The first problem is in line 119. It will not work, because in the old package /var/lib/rock/logs is an directory, So first the old files must be moved, then the directory must be removed. After that the symlink can be created.
The case switch of line 164 are not needed, because in both valid scenarios the same function is called.
On line 58 the if is also unneeded I think. An simple "systemctl stop rock" is enough, because the call is forward to the init.d subsystem in the old case. In line 73, an "systemctl daemon-reload" are needed, to tell systemd to clean up before the sysetmd service file will be placed.
Thanks, here is the new spec: rock.spec.txt
and the corresponding RPM: https://github.com/obiba/rock/releases/tag/1.1.0-beta4
Now after the update the server is stopped, when it was running before, but the systemd system is now happy. But the restart after the update will not work.
The mkdir /var/log/rock is not necessary, because the directory comes the the package:
less rock-1.1.0-beta4_1.noarch.rpm
Name : rock
Version : 1.1.0
Release : beta4_1
Architecture: noarch
Install Date: (not installed)
Group : Applications/Engineering
Size : 30785586
License : GPLv3
Signature : (none)
Source RPM : rock-1.1.0-beta4_1.src.rpm
Build Date : Di 08 Jun 2021 15:02:44 CEST
Build Host : travis-job-762f3bee-7e14-44c9-b1c0-5246a0f4936a
Relocations : /usr/share
Packager : OBiBa
Summary : rock
Description :
R server controller with REST API
-rw-r--r-- 1 root root 716 Jun 8 15:02 /etc/default/rock
drw-r----- 2 rock adm 0 Jun 8 15:02 /etc/rock
-rw-r----- 1 rock adm 498 Jun 8 15:01 /etc/rock/Rprofile.R
-rw-r----- 1 rock adm 498 Jun 8 15:01 /etc/rock/Rserv.conf
-rw-r----- 1 rock adm 1220 Jun 8 15:01 /etc/rock/application.yml
-rw-r----- 1 rock adm 1320 Jun 8 15:01 /etc/rock/logback.xml
-rw-r----- 1 rock adm 990 Jun 8 15:01 /etc/rock/system.info.R
-rw-r--r-- 1 root root 425 Jun 8 15:01 /lib/systemd/system/rock.service
drwxr----- 2 rock adm 0 Jun 8 15:02 /tmp/rock
drwxr-xr-x 2 root root 0 Jun 8 15:02 /usr/share/rock-1.1.0-beta4/bin
-rwxr-xr-x 1 root root 2013 Jun 8 15:01 /usr/share/rock-1.1.0-beta4/bin/rock.sh
-rwxr-xr-x 1 root root 58 Jun 8 15:01 /usr/share/rock-1.1.0-beta4/bin/update.sh
drwxr-xr-x 2 root root 0 Jun 8 15:02 /usr/share/rock-1.1.0-beta4/lib
-rwxr-xr-x 1 root root 30777848 Jun 8 15:02 /usr/share/rock-1.1.0-beta4/lib/rock-1.1.0-beta4.jar
drwxr----- 2 rock adm 0 Jun 8 15:02 /var/lib/rock
drwxr----- 2 rock adm 0 Jun 8 15:02 /var/log/rock
When I look in the less output I seen the next big problem. /tmp/rock is very bad idea, because /tmp is an tmps on modern systems. So when the application stores big data here then /var/tmp/ must be used. And the second tmp problem is, that an tmpfiles.d config file is needed in both cases. (/var/tmp, /tmp) See https://www.freedesktop.org/software/systemd/man/tmpfiles.d.html
The symlink for the log will fails, because the mv call fails when the source directory is empty. So the mv/ln section must be something like this:
if [ ! -L "$LOG_DIR_OLD" ]; then
if [ -n "$(ls -A $LOG_DIR_OLD)" ]; then
mv $LOG_DIR_OLD/* $LOG_DIR
fi
rm -rf $LOG_DIR_OLD
ln -s $LOG_DIR $LOG_DIR_OLD
fi
Line 107 to 109 must be declared in the file section of the spec file. Doing this in the post section is an very bad idea, because it is complete agains the rpm design.
I can create an clean spec file, but I have no idea if you can add this to build process, because it will use many macros which are only functional when building the rpm package on an system using mock. (the clean way to build rpm packages, from spec files and srpm packages.)
There are some legacy code I am afraid... /tmp/rock
was for the daemon based, not relevant with systemd, it has been cleaned.
Now the RPM packaging takes care of the base folders layout, owner and rights.
Last pre-release: https://github.com/obiba/rock/releases/tag/1.1.0-beta6
Specs: rock.spec.txt
Tested again. But the same error as on https://github.com/obiba/rock/issues/2#issuecomment-857418404 I will try to build an spec file and send it to you.
Now I have an working solution, but I don't know how you can build this in your build environment, because my was only tested using mock. (The RedHat/Fedora way to build rpm packages) So I have attached the srpm file. The both "trans" sections of the spec file can be removed in an later one, because the are only needed for the migration.
Because github will not allow big files, I only have attached the relevant part of it. X.zip
Thanks, I will try that. One question: all those keywords %{_sharedstatedir}
, %{name}
etc. should be written as-is in the scriptlets?
yes, because this are macros, which make the life simpler :)
I have added your scriptlets, not sure of the result given the build tool that is used. https://github.com/obiba/rock/releases/tag/1.1.0-beta1
No, the result will be different. I think your build environment will not use the the same macros as it is used default by RedHat/Fedora one. %{_sharedstatedir} will be /usr/com in your environment. And the %systemd_post, %systemd_postun_with_restart macros are not resolved. :(
Is there a page that describes those macros?
Only partial: https://docs.fedoraproject.org/en-US/packaging-guidelines/Scriptlets/#Systemd https://docs.fedoraproject.org/en-US/packaging-guidelines/RPMMacros/ For the systemd macros I have added the source file for it. macros.systemd.txt
I have developped the macros. Please give it a try: https://github.com/obiba/rock/releases/tag/1.1.0-beta
Hi some macros are not the same as needed. %systemd_post: in my package it is resolved to:
if [ $1 -eq 1 ] ; then
# Initial installation
systemctl preset rock.service >/dev/null 2>&1 || :
fi
in yours:
systemctl --no-reload preset rock.service
%preun: my:
if [ $1 -eq 0 ] ; then
# Package removal, not upgrade
systemctl --no-reload disable rock.service > /dev/null 2>&1 || :
systemctl stop rock.service > /dev/null 2>&1 || :
fi
yours:
systemctl preset rock.service
systemctl start rock.service
%postun: my:
systemctl daemon-reload >/dev/null 2>&1 || :
if [ $1 -ge 1 ] ; then
# Package upgrade, not uninstall
systemctl try-restart rock.service >/dev/null 2>&1 || :
fi
yours:
systemctl try-restart rock.service
Sorry about that, this is really painful, it is like coding in the dark. Please try this new build: https://github.com/obiba/rock/releases/tag/1.1.0-beta
No problem, I know,it is every time an real problem, when you build software using not the system own work flow. Now the script part of package looks like mine. :)
Does it work? when:
I will check it on Monday.
The fresh install will fails. because useradd must be called with an lower -c instant of -C for the command. Please change it, then I can try it again.
Ok. please try again: https://github.com/obiba/rock/releases/tag/1.1.0-beta
Now the user create will work. Here the next errors:
Please try again: https://github.com/obiba/rock/releases/tag/1.1.0-beta
Hm, now the workong part is missing and the fixed are not included.
Here the current spec file, of my working version. Test for update an clean install. rock.spec.gz
I have installed a centos7 box and was able to test install and upgrade. I consider 1.0.3 RPM package broken. Installing and upgrading systemd-compliant new packages will work as expected (minor issue: centos7 is really old and does not have systemd 236+, so process stderr and stdout redirect to file is not supported).
Under CentOS7 rock fails to start with: cat /var/log/rock/stdout.log Error: Could not find or load main class org.obiba.rock.Application