Fix #3203 usage server broken in 4.11/4.12#3207
Conversation
'$$'; thus, the _pid variable received '$$', causing an exception.
|
@blueorangutan package |
|
@GabrielBrascher a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress. |
|
@blueorangutan package |
|
@GabrielBrascher a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress. |
|
Would you think to put pid file to the /run folder? like /run/cloudstack-usage.service.pid |
|
I would say that /run or /var/run would be better as well. But why does the usage server actually needs it's PID? |
|
I would also ask (sorry if silly question) - why any difference to 4.11.2 at all (did the code around systemd changed) ? - i.e. I observe no pid with 4.11.2, as far as I can see. But definitively (if PID required) would put it to default location as /var/run/* Happy to test, just want to avoid doing it 2 times... ? |
|
I agree with @wido @konstantinjfk that it would be better to save pid file as "/var/run/cloudstack-usage.service.pid" I have applied @GabrielBrascher 's patch in cloudstack 4.11.2, changed pid file to "/var/run/cloudstack-usage.service.pid" and tested it. all seems fine. so this pull request is good for me, except the pid file location. thanks @GabrielBrascher for your work. |
exception in case of null or blank pid (NumberUtils.toInt returns zero if the conversion fails).
|
code looks good to me. |
|
Thanks for the feedback @wido @andrijapanic @konstantinjfk @ustcweizhou! |
|
@wido, as far as I know, the implementation used the pid to have a unique id regarding the cloudstack-usage.service (in case of multiple cloudstack-usage nodes running). To change this approach some refactoring is needed. Regarding the codebase (prior to this PR), the exception was happening at line 274 from UsageManagerImpl.java. If the _pid is not a valid pid for the service (for instance zero) the runInContextInternal execution flow is ignored. |
|
@andrijapanic the _pid is there at 4.11.2. However, I am not sure if the service was alrady migrate to systemd at 4.11.2 or it was migrated in the 4.11 branch after 4.11.2 was released. |
|
@GabrielBrascher thx a lot for the fixes ! I'll wait for commit and kick packaging once more. |
|
Fixed! Thanks for the help @andrijapanicsb! |
3510470 to
4c948e0
Compare
4d7ad0f to
d9d3da9
Compare
|
@GabrielBrascher could you squash the commits to one commit ? |
d9d3da9 to
a42bc9f
Compare
|
@ustcweizhou sure, I will Squash when merging (with the Squash and merge). |
|
@blueorangutan package |
|
@GabrielBrascher a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress. |
|
Packaging result: ✔centos6 ✔centos7 ✔debian. JID-2624 |
|
@blueorangutan test |
|
@GabrielBrascher a Trillian-Jenkins test job (centos7 mgmt + kvm-centos7) has been kicked to run smoke tests |
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| JAVA_OPTS="-Dpid=$$ -Xms256m -Xmx2048m" |
There was a problem hiding this comment.
@GabrielBrascher What's the issue, this should work?
There was a problem hiding this comment.
Nevermind, re-read the description. Alright keep this change, I'll advise you a simpler fix.
There was a problem hiding this comment.
Btw, this without quotes would work
| [Service] | ||
| Type=simple | ||
| EnvironmentFile=/etc/default/cloudstack-usage | ||
| ExecStart=/usr/bin/java $JAVA_OPTS -cp $CLASSPATH $JAVA_CLASS |
There was a problem hiding this comment.
Put this and this would fix the pid issue:
Environment=JAVA_PID=$$
ExecStart=/usr/bin/java $JAVA_DEBUG -Dpid=$JAVA_PID $JAVA_OPTS -cp $CLASSPATH $JAVA_CLASS
There was a problem hiding this comment.
Comment: this would need to be fixed for 4.11 as well, let me send a quick fix instead.
yadvr
left a comment
There was a problem hiding this comment.
Too complicated, I'll submit a simpler change.
|
Please review/test - #3210 |
|
Trillian test result (tid-3416)
|
|
I did not review this one (test it), but already had env for #3210 and confirm it works fine - usage jobs does kick in as it should. |
|
Closing this in favor of #3210 |
Fixes issue #3203.
Due to the migration to systemd, the configuration
-Dpid=$$does not return the pid value but the string '$$'; thus, the _pid variable received '$$', causing a silenced exception.This PR adds the file
/etc/cloudstack/usage/cloudstack-usage.service.pidthat has the process pid. The file is configured after the ExecStart, by running thesystemctl showcommand configured as:ExecStartPost=/bin/sh -c "systemctl show -p MainPID cloudstack-usage.service 2>/dev/null | cut -d= -f2 > /etc/cloudstack/usage/cloudstack-usage.service.pid"Description
Types of changes
Screenshots (if appropriate):
How Has This Been Tested?
CloudStack usage service run as expected after updating with the changes from this PR.