I have created a service for getting the entity manager in a command
I don't understand why I can use the entity manager in regular Controller and not in my Command.
I have declared my service in "service.yml"
common.doctrine:
class: AppBundle\Services\GetDoctrineService
arguments: [ '#doctrine.orm.entity_manager' ]
public: true
I wrote it in "GetDoctrineService.php"
<?php
namespace AppBundle\Services;
use Doctrine\ORM\EntityManager;
class GetDoctrineService
{
protected $em;
public function __construct(\Doctrine\ORM\EntityManager $em)
{
$this->em = $em;
}
public function getRepository(string $repo) {
return $this->em->getRepository($repo);
}
}
In my command, I am importing it and calling it in the "Command way"
$em = $this->getApplication()->getKernel()->getContainer()->get('common.doctrine');
$foo = $em->getRepository(Entity::FOO)->findAll();
I changed the db host to "localhost" in "parameters.yml"
# This file is auto-generated during the composer install
parameters:
#database_host: db-name
database_host: localhost
When I installed postgres with a command, the file "pg_hba.conf" wasn't created (I am working with Ubuntu)
I have this error while i use my command :
Message: "An exception occured in driver: SQLSTATE[08006] [7] could not connect to server: Connection refused Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432?"
The problem was in the configuration files:
using 'localhost' was a mistake: we should have use the dn-name for the host
Related
I'm a newbie with database and Vapor. I'm trying to put a vapor project on a Postgres database on a VPS but I had this error:
2022-08-05 11:18:26.611154+0200 Run[16315:261688] Swift/ErrorType.swift:200: Fatal error: Error raised at top level: PostgresNIO.PSQLError(base: PostgresNIO.PSQLError.Base.connectionError(underlying: NIOPosix.NIOConnectionError(host: "82.125.176.210", port: 5432, dnsAError: nil, dnsAAAAError: nil, connectionErrors: [NIOPosix.SingleConnectionFailure(target: [IPv4]82.125.176.210/82.125.176.210:5432, error: connection reset (error set): Operation timed out (errno: 60))])))
Here my code:
import Fluent
import FluentPostgresDriver
import Vapor
import Leaf
public func configure(_ app: Application) throws {
app.middleware.use(FileMiddleware(publicDirectory: app.directory.publicDirectory))
app.middleware.use(app.sessions.middleware)
let databaseName: String
let databasePort: Int
databaseName = "vapor_database"
databasePort = 5432
app.databases.use(.postgres(
hostname: "82.125.176.210",
port: databasePort,
username: Environment.get("DATABASE_USERNAME") ?? "456787555",
password: Environment.get("DATABASE_PASSWORD") ?? "456787555",
database: Environment.get("DATABASE_NAME") ?? databaseName
), as: .psql)
app.migrations.add(CreateUser())
app.migrations.add(CreateAcronym())
app.migrations.add(CreateCategory())
app.migrations.add(CreateAcronymCategoryPivot())
app.migrations.add(CreateToken())
switch app.environment {
case .development, .testing:
app.migrations.add(CreateAdminUser())
default:
break
}
app.migrations.add(AddTwitterURLToUser())
app.migrations.add(MakeCategoriesUnique())
app.logger.logLevel = .debug
try app.autoMigrate().wait()
app.views.use(.leaf)
// register routes
try routes(app)
}
A timeout error usually means that there's no route to the database server because it's being blocked by a firewall. (As opposed to a connection refused error if there's nothing listening on that port). Make sure you set a rule in the firewall to allow the Vapor app to connect
need your help,
I need to connect to AWS Aurora Postgresql using liquibase, it's already configured for local machine, and works fine, but have issues with ssh configuration to it.
I'm using id 'org.hidetake.ssh' version '2.10.1', and id 'org.liquibase.gradle' version '2.0.4'
I'm able to run command directly on host machine, like getting date execute ('date') below, but have no idea why liquibase fails with
Unexpected error running Liquibase: liquibase.exception.DatabaseException: liquibase.exception.DatabaseException: Connection could not be created to jdbc:postgresql://xxxx.rds.amazonaws.com:5432/postgres with driver org.postgresql.Driver. The connection attempt failed.
here is my build.gradle setting:
ssh.settings {
knownHosts = allowAnyHosts
logging = 'stdout'
identity = file("${System.properties['user.home']}/myfolder/.ssh/id_rsa")}
remotes {
dev {
host = 'xxx.xxx.xxx.xxx'
port = 22
user = 'ec2-user'
identity = file("${System.properties['user.home']}/myfolder/.ssh/id_rsa")
}
}
ssh.run {
session(remotes.dev) {
forwardLocalPort port: 5432, hostPort: 5432
execute ('date')
liquibase {
activities {
main {
//changeLogFile changeLog
url 'jdbc:postgresql://xxxx.rds.amazonaws.com:5432/postgres'
username feedSqlUserDev
password feedSqlUserPasswordDev
logLevel 'debug'
}
}
}
}
}
Could you please help me with it, what am I doing wrong?
Also had to connect to SSH bastion host before running liquibase updates. My solution is based on https://github.com/int128/gradle-ssh-plugin/issues/246 answer by the plugin author.
Here is my setup:
ssh.settings {
knownHosts = allowAnyHosts
logging = 'stdout'
identity = file("${System.properties['user.home']}/.ssh/id_rsa")
}
remotes {
bastion {
host = '<hostname>'
user = '<username>'
}
}
liquibase {
activities {
main {
changeLogFile '...'
url 'jdbc:postgresql://localhost:5438/***'
username '***'
password '***'
driver 'org.postgresql.Driver'
}
}
}
task('sshTunnelStart') {
doFirst {
project.ext.ready = new CountDownLatch(1)
project.ext.done = new CountDownLatch(1)
Thread.start {
ssh.run {
session(remotes.bastion) {
forwardLocalPort port: 5438,
host: '<real db hostname>',
hostPort: 5432
project.ready.countDown()
project.done.await(5, TimeUnit.MINUTES) // liquibase update timeout
}
}
}
ready.await(10, TimeUnit.SECONDS) // start tunnel timeout
}
}
task('sshTunnelStop') {
doLast {
// teardown tunnel
project.done.countDown()
}
}
update.dependsOn(sshTunnelStart)
update.finalizedBy(sshTunnelStop)
Note that in liquibase config I use localhost:5438 as it is a local port forwarded to the remote. Later the same port is used in forwardLocalPort as a 'port' parameter. 'host' parameter is set to the remote database host, and 'hostPort' is accordingly the database port. The last part of the config adds dependencies between tasks to liquibase update and start/stop the tunnel.
I am writing a JBoss EAR application that needs to query the local JBoss server it is running on for status of deployments. I am running JBoss as standalone. I am able to query the JBoss server easily using the JBoss-CLI, but using the API with the 'ModelControllerClient', I am getting a "connection refused" error. My firewall is completely disabled, and I am pointing at localhost, so I am not sure what the problem could be.
Here is the code I am running:
public static void GetStatus() throws Exception{
ModelNode operation = new ModelNode();
operation.get( "address" ).add( "deployment", "*" );
operation.get( "operation" ).set( "read-attribute" );
ModelControllerClient client = ModelControllerClient.Factory.create(InetAddress.getByName("127.0.0.1"), 9990);
ModelNode result = client.execute( new OperationBuilder(operation).build() );
List<ModelNode> deployments = result.get( "result" ).asList();
String deploymentName;
// finally we can iterate and get the deployment names.
for ( ModelNode deployment : deployments ) {
deploymentName = deployment.get( "result" ).asString();
System.out.println( "deploymentName = " + deploymentName );
}
}
... and here is the error I receive when this method is called:
java.io.IOException: java.net.ConnectException: JBAS012144: Could not connect to remote://localhost:9990. The connection timed out
If I run the netstat -tuna command, I see that I am listening to 0:0:0:0:9990
Thanks!
Try with starting server on localhost instead of 0.0.0.0. Also refer sample example from http://middlewaremagic.com/jboss/?p=2676
I decided to play with lapis - https://github.com/leafo/lapis, but the application drops when I try to query the database (PostgreSQL) with the output:
2017/07/01 16:04:26 [error] 31284#0: *8 lua entry thread aborted: runtime error: attempt to yield across C-call boundary
stack traceback:
coroutine 0:
[C]: in function 'require'
/usr/local/share/lua/5.1/lapis/init.lua:15: in function 'serve'
content_by_lua(nginx.conf.compiled:22):2: in function , client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "localhost:8080"
The code that causes the error:
local db = require("lapis.db")
local res = db.query("SELECT * FROM users");
config.lua:
config({ "development", "production" }, {
postgres = {
host = "0.0.0.0",
port = "5432",
user = "wars_base",
password = "12345",
database = "wars_base"
}
})
The database is running, the table is created, in table 1 there is a record.
What could be the problem?
Decision: https://github.com/leafo/lapis/issues/556
You need to specify the right server IP in the host parameter.
The IP you have specified 0.0.0.0 is not a valid one, and normally it is used when you specify a listen address, with the meaning of "every address".
Usually you can use the '127.0.0.1' address during development.
I'm using Vagrant and I'm trying to provision a VM using puppet. In the Vagrant file I configured VM db as follow:
config.vm.define "db" do |db|
db.vm.hostname = "db"
db.vm.network "private_network", ip: "10.11.1.201", virtualbox__intnet: true
db.vm.provider "virtualbox" do |v|
v.memory = 1024
end
db.vm.network "forwarded_port", guest: 22, host: 2221, id: 'ssh', auto_correct: true
db.vm.network "forwarded_port", guest: 5432, host: 2222
db.ssh.forward_agent = true
config.vm.provision :shell do |shell|
shell.inline = "mkdir -p /etc/puppet/modules;
puppet module install puppetlabs-postgresql"
end
config.vm.provision :puppet do |puppet|
puppet.manifests_path = "puppet/manifests"
puppet.manifest_file = "site.pp"
puppet.module_path = "puppet/modules"
end
end
end
As you can see I set the download of the modules using a vagrant shell command before the puppet provisioner runs. In this way I have downloaded the puppetlabs-postgresql module from puppet labs. I do not want to manage my database by creating classes in my site.pp file located in /puppet/manifests/site.pp. I want to have a module call database in /puppet/modules/database. What I have done so far is create an init.pp file in /puppet/modules/database. Below is the content of my init.pp file :
class database {
class { 'postgresql::server':
ip_mask_allow_all_users => '0.0.0.0/0',
listen_addresses => '*',
ipv4acls => ['hostssl all johndoe 192.168.0.0/24 cert'],
postgres_password => 'TPSrep0rt!',
}
}
And then in my /puppet/manifests/site.pp file i have included the database class as below :
node 'db' {
include database
}
After the "vagrant up" command I get the error:
Error: Puppet::Parser::AST::Resource failed with error ArgumentError: Could not find declared class postgresql::server at /tmp/vagrant-puppet/modules-d1208595f982e4ac16b287f9bd398c89/database/manifests/init.pp:8 on node db.lan
==> db: Wrapped exception:
==> db: Could not find declared class postgresql::server
==> db: Error: Puppet::Parser::AST::Resource failed with error ArgumentError: Could not find declared class postgresql::server at /tmp/vagrant-puppet/modules-d1208595f982e4ac16b287f9bd398c89/database/manifests/init.pp:8 on node db.lan
What is the correct way to make use of the postgresql classes?
It is weird feeling to read your code, especially the class database part.
can you set hieradata template for puppet module postgresql
something likes:
postgresql::server:
ip_mask_allow_all_users: '0.0.0.0/0'
listen_addresses: '*'
ipv4acls:
- 'hostssl all johndoe 192.168.0.0/24 cert'
postgres_password: 'TPSrep0rt!'
in node define,
node 'db' {
include postgresql::server
}
manage the facters in pp file directly is not good practice.