Bonjour,

J'ai créé différents services avec Tomcat et maintenant je souhaiterais éviter d'utiliser Tomcat et en utilisant un démon.
Dans ce but, je met en place JSVC.

Le problème est que JSVC ne parvient pas à se connecter à la BDD via mysql-connector (mysql-connector-java-5.1.21-bin.jar pour être précis).

Dès que je souhaite toucher à la BDD j'ai l'erreur suivante qui apparait :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
 
 
[][-1][-1][getGlobalPropertyByCode][20130225.17:57:37] - [main] WARN org.hibernate.util.JDBCExceptionReporter  - SQL Error: 0, SQLState: 08001
[][-1][-1][getGlobalPropertyByCode][20130225.17:57:37] - [main] ERROR org.hibernate.util.JDBCExceptionReporter  - Could not create connection to database server. Attempted reconnect 3 times. Giving up.
[][-1][-1][getGlobalPropertyByCode][20130225.17:57:37] - [main] DEBUG org.hibernate.jdbc.ConnectionManager  - aggressively releasing JDBC connection
[][-1][-1][getGlobalPropertyByCode][20130225.17:57:37] - [main] DEBUG org.hibernate.ejb.AbstractEntityManagerImpl  - mark transaction for rollback
[][-1][-1][getGlobalPropertyByCode][20130225.17:57:38] - [main] ERROR com.toto.mobile.core.GlobalPropertyManager  - Exception : -->javax.persistence.PersistenceException: org.hibernate.exception.JDBCConnectionException: Cannot open connection      at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:614)         at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:76)         at com.toto.mobile.core.GlobalPropertyManager.getGlobalPropertyByCodes(GlobalPropertyManager.java:99)   at com.toto.mobile.core.UnsubscribeManager.<init>(UnsubscribeManager.java:90)   at com.toto.mobile.core.totoMobile.initialize(totoMobile.java:283)       at com.toto.mobile.core.totoMobile.<init>(totoMobile.java:131)        at com.toto.mobile.agent.daemon.DaemonAgent.init(DaemonAgent.java:89)      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     at java.lang.reflect.Method.invoke(Method.java:601)     at org.apache.commons.daemon.support.DaemonLoader.load(DaemonLoader.java:207) Caused by: org.hibernate.exception.JDBCConnectionException: Cannot open connection     at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:97)      at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)     at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:52)  at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:449)      at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167)    at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:161)   at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1573)       at org.hibernate.loader.Loader.doQuery(Loader.java:696)         at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)       at org.hibernate.loader.Loader.doList(Loader.java:2228)         at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2125)        at org.hibernate.loader.Loader.list(Loader.java:2120)   at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:401)   at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:361)         at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)        at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1148)   at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)     at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:67)         ... 10 more Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.         at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)     at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)         at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)      at java.lang.reflect.Constructor.newInstance(Constructor.java:525)  at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)  at com.mysql.jdbc.Util.getInstance(Util.java:386)       at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1013)    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)     at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)        at com.mysql.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:2297)        at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2218)  at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:797)        at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)      at java.lang.reflect.Constructor.newInstance(Constructor.java:525)      at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)      at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:389)   at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)        at java.sql.DriverManager.getConnection(DriverManager.java:579)         at java.sql.DriverManager.getConnection(DriverManager.java:190)     at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:133)      at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446)   ... 24 more Caused by: java.lang.NullPointerException   at com.mysql.jdbc.Buffer.<init>(Buffer.java:55)     at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1707)         at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1276)    at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2395)   at com.mysql.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:2236)   ... 38 more
Voici le fichier "persistence.xml" :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
 
 
<?xml version="1.0" encoding="UTF-8"?>
<!-- http://docs.jboss.org/hibernate/entitymanager/3.5/reference/en/html/configuration.html -->
<persistence version="2.0"
	xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
 
	<!-- prod -->
 
	<persistence-unit name="mobile" transaction-type="RESOURCE_LOCAL">
		<provider>org.hibernate.ejb.HibernatePersistence</provider>
		<properties>
			<property name="hibernate.archive.autodetection" value="class" />
			<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />			
			<property name="hibernate.connection.url"	value="jdbc:mysql://127.0.0.1:3306/mobile?useUnicode=true&amp;autoReconnect=true&amp;connectionCollation=utf8_general_ci&amp;characterEncoding=UTF-8&amp;profileSQL=false" />
			<property name="hibernate.show_sql" value="false" />
			<property name="hibernate.format_sql" value="false" />			
			<property name="hibernate.connection.username" value="root" />
			<property name="hibernate.connection.password" value="root" />
			<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />		
                <property key="hibernate.connection.provider_class">org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider</property>
                <property key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
                <property key="hibernate.show_sql">true</property>
                <property key="hibernate.hbm2ddl.auto">verify</property>
                <property key="hibernate.current_session_context_class">thread</property>
                <property key="hibernate.c3p0.acquire_increment">1</property>
                <property key="hibernate.c3p0.min_size">5</property>
                <property key="hibernate.c3p0.max_size">200</property>
                <property key="hibernate.c3p0.timeout">50000</property>
                <property key="hibernate.c3p0.max_statements">1000</property>
                <property key="hibernate.c3p0.idle_test_period">3000</property>
                <property key="hibernate.c3p0.testConnectionOnCheckout">false</property>
                <property key="hibernate.c3p0.acquireRetryAttempts">1</property>
		</properties>
	</persistence-unit>
 
	<persistence-unit name="mobile_stats" transaction-type="RESOURCE_LOCAL">
		<provider>org.hibernate.ejb.HibernatePersistence</provider>
		<properties>
			<property name="hibernate.archive.autodetection" value="class" />
			<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />			
			<property name="hibernate.connection.url"	value="jdbc:mysql://127.0.0.1:3306/mobile_stats?useUnicode=true&amp;autoReconnect=true&amp;connectionCollation=utf8_general_ci&amp;characterEncoding=UTF-8&amp;profileSQL=false" />
			<property name="hibernate.show_sql" value="false" />
			<property name="hibernate.format_sql" value="false" />			
			<property name="hibernate.connection.username" value="root" />
			<property name="hibernate.connection.password" value="root" />
			<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />		
			<property name="hibernate.hbm2ddl.auto" value="update"/>
                <property key="hibernate.connection.provider_class">org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider</property>
                <property key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
                <property key="hibernate.show_sql">true</property>
                <property key="hibernate.hbm2ddl.auto">verify</property>
                <property key="hibernate.current_session_context_class">thread</property>
                <property key="hibernate.c3p0.acquire_increment">1</property>
                <property key="hibernate.c3p0.min_size">5</property>
                <property key="hibernate.c3p0.max_size">20</property>
                <property key="hibernate.c3p0.timeout">5000</property>
                <property key="hibernate.c3p0.max_statements">100</property>
                <property key="hibernate.c3p0.idle_test_period">3000</property>
                <property key="hibernate.c3p0.testConnectionOnCheckout">true</property>
                <property key="hibernate.c3p0.acquireRetryAttempts">1</property>
		</properties>
	</persistence-unit>
 
</persistence>
En faisant en TCPDump je me suis aperçu que le "batch" semble contacter mysql sans que celui-ci ne lui réponde.

Je vois passer des packets contenant "mysql_native_password" et "Got.packets.out.of.order".

Au cas où, voici le script qui permet d'exécuter le "batch" :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
 
 
ID=$1
COMMAND=$2
CORPUS=$3
 
 
JSVC_OPTS=""
#JSVC_OPTS="-debug"
 
JAR=/opt/vrm/agent/mobile.agent.daemon-1.0-jar-with-dependencies.jar
JAVAHOME=/usr/lib/jvm/jdk1.7.0
JSVC_BIN='/usr/bin/jsvc'
 
# properties in /etc/vrm//agent
# jar in 	    /opt/vrm//agent
CLASSPATH="/usr/share/java/commons-daemon.jar:/etc/vrm/agent:/opt/vrm/agent/:$JAR"
 
# class 
CLASS="com.vaderetro.mobile.agent.daemon.Agent"
 
#  DaemonContext.getArguments()
AGENT_ARGS=" $ID $CORPUS"
 
# agent paths
AGENT_LOGS="/var/log/vrm/agents/$ID/"
LOG_FILE=${AGENT_LOGS}jsvc.log
 
PIDFILE=/var/run/agent-$ID.pid
 
LOG_OUT=/tmp/example.out
LOG_ERR=/tmp/example.err
 
 
NAME="mobile agent daemon $ID"
 
 
# JVM options
JAVA_OPTS="-Xmx128M -Dfile.encoding=fr_FR.UTF-8 -Dlog4j.configuration=file:/etc/vrm/agent/log4j.properties  -Djava.library.path=/opt/vrm/agent/"
 
function check_directories
{
  mkdir -p "/var/log/vrm/agents/"
  mkdir -p "/etc/vrm/agent/"
  mkdir -p "${AGENT_LOGS}"
}
 
 
function start
{	
	check_directories
	check_app_status
	if [[ "$?" -eq 1 ]]; then
		echo "(already running)"
		exit 1
	fi
	echo "Starting ${NAME}"
	local cmd="${JSVC_BIN} ${JSVC_OPTS} -pidfile ${PIDFILE} -home ${JAVAHOME} -outfile $LOG_FILE -errfile $LOG_FILE ${JAVA_OPTS} -cp ${CLASSPATH} ${CLASS} ${AGENT_ARGS}"
	echo "$cmd"
	`$cmd`
}
 
function stop
{
	check_directories
	check_app_status
	if [[ "$?" -ne 1 ]]; then
		echo "(not running)"
		exit 1
	fi
	echo "Stopping ${NAME}"
	local cmd="${JSVC_BIN} -stop ${JSVC_OPTS} -pidfile ${PIDFILE} -home ${JAVAHOME} -outfile $LOG_FILE -errfile $LOG_FILE  ${JAVA_OPTS} -cp ${CLASSPATH} ${CLASS} ${AGENT_ARGS}"
	echo "$cmd"
	`$cmd`	
}
 
 
function restart
{
	check_app_status
	if [[ "$?" -eq 1 ]]; then
		 stop
	      sleep 1
	fi
    start
}
 
 
function check_app_status
{
	local curpid=''
	local apprun=''
	if [[ -f "${PIDFILE}" ]]; then
		curpid=`cat "${PIDFILE}"`
		apprun=`echo $curpid | xargs -i ps {} | tail -n +2`
		if [[ -z "$apprun" ]]; then
			# not running, but pid file exists
			return 2
		else
			# running
			return 1
		fi
	else
		# not running
		return 0
	fi
}
 
case "$COMMAND" in
	start)
		start		
		;;
	stop)
		stop
		;;
	restart)
		restart
		;;
	status) 
		check_app_status
		case "$?" in
			0)
				echo "${NAME} is not running."
				;;
			1)
				echo "${NAME} is running."
				;;
			2)
				echo "${NAME} is not running, but pid file exists."
				;;
			*)
				exit 1
				;;
		esac
		;;
	*)
		echo "Usage: $0 AGENTID {start|stop|restart|status}"
		exit 1
		;;
esac
 
exit 0
Quelqu'un a-t-il déjà rencontré ce type de problème ?

je pensais que cela venait du security manager, mais en mettant un security qui autorise tout cela ne règle pas le problème...

Merci d'avance.

Cordialement.