-
Notifications
You must be signed in to change notification settings - Fork 441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix use of app_name and exec vars in systemv start-rpm-template #537
Conversation
It looks like a bug was introduced in commit 22a691, where if `executableScriptName in Linux` and `packageName in Linux` are not equal, then an incorrect script is generated. The `exec` template variable should only be used to build the run command. Everything else should be the `app_name`.
@@ -34,8 +34,6 @@ | |||
# $JAVA_OPTS used in $RUN_CMD wrapper | |||
export JAVA_OPTS | |||
|
|||
prog="${{exec}}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why remove this and insert ${{app_name}}
by hand?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought it helped the readability of the file. Seeing as it’s already templated, it seems easier to see where the app_name
variable flows to, rather than having the indirection of prog
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm. I think it doesn't matter. The main point for creating a new variable is to be able to rename the replacement placeholder in one place. However we shouldn't do this (as any client could rely on this). So readability wins :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean change the var name app_name
in the future? As you say, that would be pretty disastrous for backwards compatibility :)
On which system did you test this? |
I haven’t; I figured I was safe as it’s just a renaming. |
optimist :D |
On that note, there are some simple sbt tests projects, none of which were able to catch this issue with On the one hand, these templates don’t need to change that often and code review is not replaceable, yet some means for doing dry runs on scripts would be great. It definitely seems hard though… and I’d admit that previously I’ve resorted to manual testing when developing sbt plugins. |
The problem is testing system loaders is that you need a real virtual machine to
the service and check. Still on the list, but needs a lot of effort :( |
I'll give this a shot on centos. @kardapoltsev could you take a look aswell? |
I've already took. Looks reasonable but I'm not sure. |
Hm. I get -bash: /var/log/test-project-simple/daemon.log: Permission denied However this shouldn't be due to this PR. I cannot even run the command as root?! |
Even root couldn't run non-executable file :) |
true story, bro :( |
Huh, didn’t see that one coming. So what happened? |
Hm. Nope, everythings seems fine @kardapoltsev (regarding executable permissions) > ls -Al /usr/share/test-project-simple/bin/
total 12
-rwxr-xr-x 1 root root 9187 Mar 30 13:34 test-project-simple Running with sudo runuser test-project-simple /usr/share/test-project-simple/bin/test-project-simple >> /var/log/test-project-simple/daemon.log 2>&1
-bash: /var/log/test-project-simple/daemon.log: Permission denied I added ls -Al /var/log/test-project-simple/
total 0
-rw-r--r-- 1 test-project-simple test-project-simple 0 Mar 30 13:50 daemon.log |
Oh, is it just that we have incorrectly used |
yeah.... I'm pretty sure this is the case 😭 |
I guess not many are using the systemv + rpm combo? |
looks like. Shouldn't hold us back from fixing this :) |
Maybe now is the time to address the ‘FIXME’ # FIXME figure out how to use daemon correctly
nohup runuser $DAEMON_USER ${RUN_CMD} >> /var/log/${{app_name}}/daemon.log 2>&1 &
# The way to go, but doesn't work properly
# If the app creates the pid file this gets messy
# daemon --user $DAEMON_USER --pidfile $PIDFILE $RUN_CMD & I’m not sure I follow the issue that you were trying to avoid (from d6f88be) A few lines down the script is creating a PID file. If this is used with Play, which creates its own PID file, won’t this result in the PID file being written twice? Now that I think about it, I’m guessing that if the script / daemon function writes the PID file before Play’s server fully initializes then Play will detect a PID file and abort? Maybe we can copy and adapt the daemon function from an appropriate distro? |
I think that was the problem (either this or in another flavour). I cannot quiet recall, why two PID files didn't work either. If play want's to have his own PID, so be it.
I'm not sure if this is the way to go. I remember there was an idea to configure the
|
Here’s the daemon function from # A function to start a program.
daemon() {
# Test syntax.
local gotbase= force= nicelevel corelimit
local pid base= user= nice= bg= pid_file=
local cgroup=
nicelevel=0
while [ "$1" != "${1##[-+]}" ]; do
case $1 in
'') echo $"$0: Usage: daemon [+/-nicelevel] {program}"
return 1;;
--check)
base=$2
gotbase="yes"
shift 2
;;
--check=?*)
base=${1#--check=}
gotbase="yes"
shift
;;
--user)
user=$2
shift 2
;;
--user=?*)
user=${1#--user=}
shift
;;
--pidfile)
pid_file=$2
shift 2
;;
--pidfile=?*)
pid_file=${1#--pidfile=}
shift
;;
--force)
force="force"
shift
;;
[-+][0-9]*)
nice="nice -n $1"
shift
;;
*) echo $"$0: Usage: daemon [+/-nicelevel] {program}"
return 1;;
esac
done
# Save basename.
[ -z "$gotbase" ] && base=${1##*/}
# See if it's already running. Look *only* at the pid file.
__pids_var_run "$base" "$pid_file"
[ -n "$pid" -a -z "$force" ] && return
# make sure it doesn't core dump anywhere unless requested
corelimit="ulimit -S -c ${DAEMON_COREFILE_LIMIT:-0}"
# if they set NICELEVEL in /etc/sysconfig/foo, honor it
[ -n "${NICELEVEL:-}" ] && nice="nice -n $NICELEVEL"
# if they set CGROUP_DAEMON in /etc/sysconfig/foo, honor it
if [ -n "${CGROUP_DAEMON}" ]; then
if [ ! -x /bin/cgexec ]; then
echo -n "Cgroups not installed"; warning
echo
else
cgroup="/bin/cgexec";
for i in $CGROUP_DAEMON; do
cgroup="$cgroup -g $i";
done
fi
fi
# Echo daemon
[ "${BOOTUP:-}" = "verbose" -a -z "${LSB:-}" ] && echo -n " $base"
# And start it up.
if [ -z "$user" ]; then
$cgroup $nice /bin/bash -c "$corelimit >/dev/null 2>&1 ; $*"
else
$cgroup $nice runuser -s /bin/bash $user -c "$corelimit >/dev/null 2>&1 ; $*"
fi
[ "$?" -eq 0 ] && success $"$base startup" || failure $"$base startup"
}
So, Play definitely does the right thing by creating a pid file on startup and deleting it on vm shutdown. It just needs a little help ( And so it seems that for programs that don’t manage their own pid file, there should be an option to turn on pid tracking in the init script. |
I should have perused the old issues… I now see that there have been plenty of discussions on this in the past! |
Yeah :( sorry for not pointing out. I'm currently a bit busy. IF you can fix this, it would really awesome. If not, no problem, then we merge this pr and fix it in another. |
fix use of app_name and exec vars in systemv start-rpm-template
So I'm merging this and try to fix this in another pr |
@muuki88, sorry, I should have replied. I have a fixed script that works nicely with a Play sample. I was going to work on the case where the process doesn’t manage its own pid file, so the script has to capture it instead. Also, I’ve got a testing environment set up with Vagrant + Ansible provisioning, and was going to finish this by using Ansible to orchestrate package installation testing, etc. I’ll submit this as a PR too. |
See #541 |
Awesome! No problem :) |
It looks like a bug was introduced in commit 22a691a, where if
executableScriptName in Linux
andpackageName in Linux
are not equal, then an incorrect script is generated.The
exec
template variable should only be used to build the run command. Everything else should be theapp_name
.