How to use -javaagent in SupervisorD - supervisord

I'm trying to run Supervisord from Docker, but having trouble for running Java with -javaagent parameter. It gives below error
Error opening zip file or JAR manifest missing : /usr/apps/executor.jar
It works otherwise if I simply omit -javaagent.
I've tried with below option, but still same error
"-javaagent:/usr/apps/executor.jar"
-javaagent:"/usr/apps/executor.jar"
// Supervisor.conf
[supervisord]
nodaemon = true
user = root
loglevel = debug
[program:helloworld]
user = root
directory = /usr/apps
# this one will work
# command = /usr/bin/env java -jar /usr/apps/HelloWorld.jar
# this one will NOT work
command = /usr/bin/env java -javaagent:"/usr/apps/executor.jar" -jar /usr/apps/HelloWorld.jar
# this one will NOT work
#command = /usr/bin/env java "-javaagent:/usr/apps/executor.jar" -jar /usr/apps/HelloWorld.jar
# this one will NOT work
#command = /usr/bin/env java -javaagent:/usr/apps/executor.jar -jar /usr/apps/HelloWorld.jar
// DockerFile
FROM openjdk:11
USER root
COPY ./HelloWorld.jar /usr/apps/HelloWorld.jar
CMD ["/usr/bin/supervisord","-n"]
Appreciate any help to get this to work...

(From the comments.)
Error opening zip file or JAR manifest missing : /usr/apps/executor.jar
would imply that the file isn't in the container, so it can't be read. (This can be verified with e.g. docker build -t myimage . and docker run -it --rm myimage ls -la /usr/apps; if executor.jar isn't there, it's... not there.)
You'll need to make sure the file truly is in there with an ADD or COPY command.

Related

Supervisor VS Supervisord

I noticed that my servers have both supervisord.conf and supervisor.conf located at:
/etc/supervisord.conf
/etc/supervisor/supervisor.conf
The installed package is:
supervisor 3.2.0-2
OS version: Ubuntu 14.04/16.04
Running lsof|grep supervisor shows that none of the processes had neither of them open
Does anyone know the difference?
Which of the conf files is the one to take place?
When running supervisord or supervisorctl, the program will first check the current working directory ($CWD, or the directory from where you invoke the command) for a supervisord.conf file. When absent, it will look for /etc/supervisord.conf. The docs will tell you more about it: http://supervisord.org/configuration.html
You also can specify the exact location of the config file by using the -c flag: supervisord -c path/to/your/file.conf.
So, in answer to your question: /etc/supervisord.conf is the one. However, if you'd like to use the other config file, you would run supervisord -c /etc/supervisor/supervisor.conf.

supervisord exiting with ENOEXEC

I am trying to run a java process with supervisord and am getting:
couldn't exec /var/application/start_tester: ENOEXEC
The contents of start_tester is:
java -Duser.dir=/var/application/ -cp /var/application/application.jar:/var/application/toepoke.jar com.application.Application
When I run the script from the console the app runs as expected. Here is my supervisor config
[program:application_tester]
directory=/var/application
command=/var/application/start_tester ; the program (relative uses PATH, can take args)
log_stdout=true ; if true, log program stdout (default true)
log_stderr=true ; if true, log program stderr (def false)
logfile=/var/log/application_tester.log
When I run the script from the console this is the output:
[root#monitor application]# ./start_tester
20131009 203657: application starting up.
20131009 203657 (33): version 2.2.3
Your file needs to be executable. So either:
You should chmod +x it to set the executable bit.
Put a shebang at the start of the file. Not having this is what caused the ENOEXEC.
or
Modify your config file to something like command=sh /var/application/start_tester.
In most cases a shebang is usually missing.
- #!/usr/bin/env bash
- #!/bin/bash
- #!/bin/sh
- #!/bin/sh -
Once you add the shebang to your gunicorn_start file (in case of DJANGO),
restart the supervisor
sudo systemctl enable supervisor
sudo systemctl restart supervisor

Executing subprocess.Popen inside Python script in PyDev context is different than running in terminal

I'm executing this code:
p = subprocess.Popen(['/path/to/my/script.sh','--flag'] , stdin=subprocess.PIPE)
p.communicate(input='Y')
p.wait()
It works when executing it on the shell using "python scriptName.py",
BUT when executing using PyDev in Eclipse, it fails, the reason:
/path/to/my/script.sh: line 111: service: command not found
This bash script "script.sh" contains the following command which causes the error:
service mysqld restart
So "service" is not recognized when running the .sh script from the context of PyDev.
I guess it has to do with some ENV VAR configurations, couldn't find how to do it.
BTW - Using "shell=True" when calling subprocess.Popen didn't solve it.
service usually is located in /usr/sbin, and that this directory isn't on the PATH. As this usually contains administrative binaries and scripts which arn't designed to be run by everyone (only by admins/root), the sbin directories arn't always added to the PATH by default.
To check this, try to print PATH in your script (or add an env command).
To fix it, you could either
set the PATH in your python script using os.setenv
pass an env dict containing the correct PATH to Popen
set the PATH in your shellscript
use the full path in your shellscript
set the PATH in eclipse

Executable file to run java on CentOS 5

I'm trying to make a simple file so I can call it in SSH and it will start my minecraft server.
I tried making a batch file called start.bat with this code:
java -Xmx512M -Xmx512M -jar craftbukkit-1.2.5-R1.0.jar nogui
However, when I run it in SSH:
$ cd /Minecraft/server_1/
$ start.bat
The SSH returns that it is an invalid or unknown command. Is there any other way I can make a quick command/file to start my server? What file extensions would I use to get this working? It works if I paste that java command in SSH and run it, but I'd rather have a file.
The current working directory is not included in your PATH by default because it is a security risk on multiuser systems. (And a potential annoyance even on machines that are single user.) You would use ./start.bat to start the program.
Since you're using Windows naming conventions, I presume you also forgot to set the execution mode bit -- and you probably also forgot the shebang line at the top of the file.
Try this:
#!/bin/sh
java -Xmx512M -Xmx512M -jar craftbukkit-1.2.5-R1.0.jar nogui
Run chmod 500 on this file. (Strictly speaking, 555 could also work, if you didn't mind other people on the machine executing the file. But they don't need to, so don't let them.) See the chmod(1) manpage for more details on the modes -- 1 bits mean executable, 2 bits means writable, and 4 bits means readable -- thus, 5 is executable and readable.
Then, when you want to run the script, run it like this:
cd /Minecraft/server_1
./start.bat
Note the ./ -- that means the shell should start the search for the executable program in the current working directory. (It could be ./bin/start.bat if your current working directory had a bin subdirectory with a start.bat executable file.)
Is start.bat executable? Make sure you have #!/bin/sh as the first line of the file. Also the directory is probably not in in the path, so try this:
$ chmod 555 start.bat
$ ./start.bat

Run a perl script at startup in Ubuntu

I have a perl script that I need to run once at startup with an argument under my user account.
So when I boot the system up it needs to execute a command like this,
./path/to/script.pl start
Any ideas?
You could use a line in your crontab (crontab -e)
To run a command at startup:
edit /etc/crontab
Add the following line:
#reboot root perl ./path/to/script.pl start
^^^ Runs as root. Change "root" to "BlackCow" to run as BlackCow
Or, you could use upstart (add a .conf file to /etc/init/). Here's a copy and paste from my notes:
Use upstart to run a daemon at reboot/start
e.g. /etc/init/prestocab.conf:
#!upstart
description "node.js server"
author "BlackCow"
start on (local-filesystems and net-device-up IFACE=eth0)
stop on shutdown
script
export HOME="/root"
exec sudo -u root /usr/local/bin/node /home/prestocab/prestocab.com/www/socket.io/server.js 2>&1 >> /var/log/prestocab.log
end script
To use:
start prestocab
stop prestocab
restart prestocab
#
You might want to use some sort of process monitor to restart the daemon if it crashes
Depends on what init you are using, if your version of Ubuntu is using upstart
you have to configure the appropriate Upstart start scripts, if not
the rc scripts based on your runlevel. Check update-rc.d.
On Ubuntu, the simplest way is to add this line to your /etc/rc.local file (before the exit 0 line, substituting username with your own user name):
su -c "./path/to/script.pl start" username &