logback skipping log files on AWS EC2 - amazon-web-services

I'm using logback for logging from an app deployed in Tomcat, with a fairly simple setup (see code fragments). We use a RollingFileAppender, with TimeBasedRollingPolicy, set for daily rollover. When running locally, everything appears to be fine. When running in AWS in an EC2 instance, I'm seeing that some log files are missing.
I wrote a really simple app that does nothing but log once per second with a counter, and then a logback config that rolls every minute. For this particular test, we're seeing every third log file is missing.
So, for example, we'll get:
-rw-r--r-- 1 tomcat tomcat 891 May 13 18:46 logtest_tomcat.2014-05-13_1845.0.log.gz
-rw-r--r-- 1 tomcat tomcat 499 May 13 18:47 logtest_tomcat.2014-05-13_1846.0.log.gz
-rw-r--r-- 1 tomcat tomcat 541 May 13 18:49 logtest_tomcat.2014-05-13_1848.0.log.gz
-rw-r--r-- 1 tomcat tomcat 519 May 13 18:50 logtest_tomcat.2014-05-13_1849.0.log.gz
-rw-r--r-- 1 tomcat tomcat 532 May 13 18:52 logtest_tomcat.2014-05-13_1851.0.log.gz
-rw-r--r-- 1 tomcat tomcat 510 May 13 18:53 logtest_tomcat.2014-05-13_1852.0.log.gz
-rw-r--r-- 1 tomcat tomcat 536 May 13 18:55 logtest_tomcat.2014-05-13_1854.0.log.gz
-rw-r--r-- 1 tomcat tomcat 1226 May 13 18:56 logtest_tomcat.2014-05-13_1855.0.log.gz
-rw-r--r-- 1 tomcat tomcat 531 May 13 18:58 logtest_tomcat.2014-05-13_1857.0.log.gz
-rw-r--r-- 1 tomcat tomcat 496 May 13 18:59 logtest_tomcat.2014-05-13_1858.0.log.gz
-rw-r--r-- 1 tomcat tomcat 1244 May 13 19:01 logtest_tomcat.2014-05-13_1900.0.log.gz
-rw-r--r-- 1 tomcat tomcat 496 May 13 19:02 logtest_tomcat.2014-05-13_1901.0.log.gz
-rw-r--r-- 1 tomcat tomcat 514 May 13 19:04 logtest_tomcat.2014-05-13_1903.0.log.gz
-rw-r--r-- 1 tomcat tomcat 500 May 13 19:05 logtest_tomcat.2014-05-13_1904.0.log.gz
-rw-r--r-- 1 tomcat tomcat 522 May 13 19:07 logtest_tomcat.2014-05-13_1906.0.log.gz
The file format is yyyy-mm-dd_HHmm - so you can see that 1847, 1850, 1853, 1856, 1859, 1902, 1905 are all missing.
I've checked the contents - the sequential numbering on the log statements jumps by 60 for the missing logs - so it's not that multiple minutes are being collapsed into a single rolled over log.
We also thought it might be due to our Splunk forwarder - we ran the test both with and without the Splunk forwarder running, and got the same results - every third log file is missing.
Here's the logback appender for this test:
<appender name="daily" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${bc.logs.home}/logtest_tomcat.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- Rollover every minute for this test -->
<fileNamePattern>${bc.logs.home}/logtest_tomcat.%d{yyyy-MM-dd_HHmm}.%i.log.gz</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<!-- or whenever the file size reaches 250MB -->
<maxFileSize>250MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<maxHistory>60</maxHistory>
</rollingPolicy>
<append>true</append>
<encoder>
<pattern>%d{"yyyy-MM-dd HH:mm:ss,SSS z", UTC} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
And here's my little driver class (the 'BCLog' is a simple wrapper around slf4j logging, instantiated by
Logger log = LoggerFactory.getLogger(clazz);
)
package com.sirsidynix.logtest.biz.svc.impl;
import com.sirsidynix.bccommon.util.BCLog;
import com.sirsidynix.bccommon.util.BCLogFactory;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
public class JustLogIt implements InitializingBean, DisposableBean
{
private static final BCLog LOG = BCLogFactory.getLog(JustLogIt.class);
private Thread thread;
#Override
public void afterPropertiesSet() throws Exception
{
LOG.info("Firing up JustLogIt thread");
thread = new Thread(){
#Override
public void run()
{
long iteration = 0;
while (true)
{
try
{
Thread.sleep(1000);
iteration++;
LOG.info("Logging Iteration " + iteration);
}
catch (InterruptedException e)
{
LOG.info("LogIt thread sleep interrupted!!!");
}
}
}
};
thread.start();
}
#Override
public void destroy() throws Exception
{
LOG.info("Shutting down JustLogIt thread");
thread.interrupt();
}
}
Any ideas?
Thanks!

Related

Connecting to LND Node through a local-running Django Rest API

I am trying to connect to my LND node running on AWS (I know it is not the best case scenario for an LND node but this time I had no other way of doing it) from my local running Django Rest Api. The issue is that it cannot find the admin.macaroon file even though the file is in the mentioned directory. Below I am giving some more detailed information:
view.py
class GetInfo(APIView):
def get(self, request):
REST_HOST = "https://ec2-18-195-111-81.eu-central-1.compute.amazonaws.com"
MACAROON_PATH = "/home/ubuntu/.lnd/data/chain/bitcoin/mainnet/admin.macaroon"
# url = "https://ec2-18-195-111-81.eu-central-1.compute.amazonaws.com/v1/getinfo"
TLS_PATH = "/home/ubuntu/.lnd/tls.cert"
url = f"https//{REST_HOST}/v1/getinfo"
macaroon = codecs.encode(open(MACAROON_PATH, "rb").read(), "hex")
headers = {"Grpc-Metadata-macaroon": macaroon}
r = requests.get(url, headers=headers, verify=TLS_PATH)
return Response(json.loads(r.text))
The node is running with no problem on AWS. This is what I get when I run lncli getinfo:
$ lncli getinfo:
{
"version": "0.15.5-beta commit=v0.15.5-beta",
"commit_hash": "c0a09209782b1c62c3393fcea0844exxxxxxxxxx",
"identity_pubkey": "mykey",
"alias": "020d4da213770890e1c1",
"color": "#3399ff",
"num_pending_channels": 0,
"num_active_channels": 0,
"num_inactive_channels": 0,
"uris": [
....
and the permissions are as below:
$ ls -l
total 138404
-rwxrwxr-x 1 ubuntu ubuntu 293 Feb 6 09:38 admin.macaroon
drwxrwxr-x 2 ubuntu ubuntu 4096 Feb 5 14:48 bin
drwxr-xr-x 6 ubuntu ubuntu 4096 Jan 27 20:17 bitcoin-22.0
drwxrwxr-x 4 ubuntu ubuntu 4096 Feb 1 16:39 go
-rw-rw-r-- 1 ubuntu ubuntu 141702072 Mar 15 2022 go1.18.linux-amd64.tar.gz
drwxrwxr-x 72 ubuntu ubuntu 4096 Feb 1 16:36 lnd
-rw-rw-r-- 1 ubuntu ubuntu 0 Jan 27 20:13 screenlog.0
The error I get is [Errno 2] No such file or directory:'/home/ubuntu/.lnd/data/chain/bitcoin/mainnet/admin.macaroon'
I guess the problem should be how I need to access the node from my API, but I have no idea how to access an EC2 instance from an external api.
Thank you in advance

Nginx 403 Forbidden on serving large images

I have setup a Django application, in which user can upload his image and it is served by Nginx and Gunicorn.
I have a problem with uploading large image files which does not get appropriate permissions to be served by Nginx
location /medias/images/ {
root /var/www/html;
}
When uploading files, the larger ones only get read permissions for the user, not for group/other:
-rw------- 1 user1 user1 4.9M Mar 15 14:35 File1.jpg
-rw------- 1 user1 user1 3.7M Mar 15 14:31 File2.jpg
-rw-r--r-- 1 user1 user1 110K Mar 15 14:44 File3.pdf
-rw-r--r-- 1 user1 user1 34K Mar 15 09:17 File4.docx
-rw-r--r-- 1 user1 user1 136K Mar 15 14:45 File5.jpg
-rw-r--r-- 1 user1 user1 92K Mar 15 14:22 File6.doc
-rw------- 1 user1 user1 4.4M Mar 15 14:25 File7.jpg
However the smaller images get their permissions fine and are served properly.
The point is that both uploading small and semi-large (3mb) image files are done by a same process.
Any ideas?
Set the FILE_UPLOAD_MAX_MEMORY_SIZE parameter in your Django settings, in Bytes.
For example FILE_UPLOAD_MAX_MEMORY_SIZE = 20971520 equals 20MB.

Clojure - add file to the classpath

How do I add resources (preferably programmatically) to the classpath of my program ?
I am using compojure.route.resources like the following :
A route for serving resources on the classpath. Accepts the following
keys: :root - the root prefix path of the resources, defaults
to 'public' :mime-types - an optional map of file extensions to mime
types
(defroutes routes
(resources "/js" {:root "js"})
(resources "/css" {:root "css"}))
Now I would like to add files to be served, but I don't know where to generate them.
Note : in case it matters, I am using boot and the example is taken from this template.
In regular boot based project, you can have a resources folder at the root:
-rw-r--r--# 1 niko staff 173 Dec 18 10:19 boot.properties
-rw-r--r--# 1 niko staff 2796 Dec 30 09:55 build.boot
drwxr-xr-x# 17 niko staff 578 Dec 30 10:49 resources
drwxr-xr-x# 4 niko staff 136 Nov 16 09:52 src
drwxr-xr-x# 17 niko staff 578 Jan 14 11:50 target
In that folder you can create the css and the js folder and include your files there:
drwxr-xr-x# 5 niko staff 170 Dec 14 15:33 resources/css/
drwxr-xr-x# 4 niko staff 136 Nov 30 18:01 resources/js/

Django 1.8, mod_wsgi, apache 2.4 setup on CentOS 7 Not Working

I'm having a hell of a time with a server error that sounds like it has an obvious solution, but isn't working out that way:
[:error] [pid 10979] (13)Permission denied: [remote xxx.xx.xxx.xxx:20] mod_wsgi (pid=10979, process='testsite', application='xxx.xxx.xx.xx|/testsite'): Call to fopen() failed for '/home/jnett/testsite/testsite/wsgi.py'.
For obvious reasons, I took out the actual server addresses. I've set up so many django sites in RedHat, earlier CentOS distributions, OSX, and even Ubuntu, and took lots of notes in all cases. Still, I cannot seem to get this configuration right.
So here it is:
1.
My apache configuration is
VirtualHost *:80>
ServerName xxx.xxx.xx.xx
ServerAlias *.xxx.xxx.xx.xx
WSGIDaemonProcess testsite python-path=/home/jnett/testsite:/home/jnett/airview_env/lib/python2.7/site-packages
WSGIScriptAlias /testsite /home/jnett/testsite/testsite/wsgi.py process-group=testsite
Alias /static /home/jnett/testsite/static
<Directory /home/jnett/testsite/testsite>
Require all granted
</Directory>
<Location /home/jnett/testsite/static>
Options -Indexes
</Location>
/VirtualHost>
(I intentionally wrote "< VirtualHost >" as "VirtualHost >" for formatting issues here. )
2.
My wsgi.py file is located where it should be according to the above apache configuration and contains:
import os, sys
sys.path.append( '/home/jnett/airview_env/lib/python2.7/site-packages' )
sys.path.append( '' )
from django.core.wsgi import get_wsgi_application
os.environ["DJANGO_SETTINGS_MODULE"] = "testsite.settings"
application = get_wsgi_application()
3.
My user directory has permissions 755.
4.
My project directory testsite has 777 permissions (just as a sanity check here, which is driving my insanity on this problem) on the parent directory and recursively for everything inside.
Further, apache also has ownership.
~ ]$ls -all
drwxrwxrwx. 4 jnett apache 50 Jan 4 22:23 testsite
~ ]$cd testsite/
~/testsite ]$ls -all
total 8
drwxrwxrwx. 4 jnett apache 50 Jan 4 22:23 .
drwxr-xr-x. 9 jnett jnett 4096 Jan 4 23:56 ..
-rwxrwxrwx. 1 jnett apache 251 Dec 30 16:52 manage.py
drwxrwxrwx. 2 jnett apache 6 Jan 4 22:23 static
drwxrwxrwx. 2 jnett apache 70 Jan 4 23:56 testsite
~/testsite ]$cd testsite/
~/testsite/testsite ]$ls -all
total 12
drwxrwxrwx. 2 jnett apache 70 Jan 4 23:56 .
drwxrwxrwx. 4 jnett apache 50 Jan 4 22:23 ..
-rwxrwxrwx. 1 jnett apache 0 Dec 30 16:52 __init__.py
-rwxrwxrwx. 1 jnett apache 2644 Dec 30 16:52 settings.py
-rwxrwxrwx. 1 jnett apache 758 Dec 30 16:52 urls.py
-rwxrwxrwx. 1 jnett apache 554 Jan 4 22:48 wsgi.py
5.
The django version is 1.8 and apache version is 2.4.
6.
selinux is set to permissive, because I know that can sometimes cause issues.
I've tried every possible little tweak to the above settings and to the permissions of everything it's pointing to, but I still cannot get any result other than the above "permission denied" error. Yes, I've googled around as much as I could on this error; No, none of the things I found produced a solution. Yes, I've also scoured the django and mod_wsgi documentation, so please don't just post a link and nothing else unless you noticed a specific obvious discrepancy.
I've staring at this for quite some time, so I'm hoping a fresh set of eyes can catch something I haven't thought of yet.
It really was an selinux problem--I misunderstood how to set it to permissive. Changing the value in /etc/selinux/config to permissive does NOT actually put selinux in a permissive state until the server is rebooted.

Application.cfc extending cfc in subdirectory without access to CF admin or webroot subdirectories

I'm on a shared linux server and I only have access to http://domain.com/~username/ which maps to ~/public_html.
I would like to use the Taffy framework for ColdFusion in this context. As far as I can tell, to use the framework you must have an Application.cfc that extends the Taffy framework component taffy.core.api.
https://github.com/atuttle/Taffy
https://github.com/atuttle/Taffy/wiki/Installing-Taffy
https://github.com/atuttle/Taffy/wiki/So-you-want-to:-Create-a-dead-simple-CRUD-API
The only directories I have access to are not sub-directories of the web root and therefore (as I understand it) not subsets of the ColdFusion path.
In my particular case I neither have access to CFADMIN nor are the server admins going to install a component I need to extend in a system-wide context where it is already on the path and accessible via global dot notation.
The instructions say you should unzip the taffy folder into your web root, and if you can't do that, you should make it a subfolder of your api. The former is not a possibility for me and when I do the latter I get "Could not find the ColdFusion Component or Interface taffy.core.api."
More Detail:
My api is at http://domain.com/~username/api/, so I unzipped /taffy to ~/public_html/api/. If I copy the Taffy example at taffy/examples/api to ~/public_html/api so that going to http://domain.com/~username/api/ should access the example, I get "Could not find the ColdFusion Component or Interface taffy.core.api" even if have taffy/core/api.cfc beneath that directory (~/public_html/api).
On this server I have successfully made cfc's that extend a cfc in another directory using <cfset THIS.mappings["/subdir"]= getDirectoryFromPath(getCurrentTemplatePath()) & "subdir/"> and <cfobject name="parentObj" component="subdir.parent">.
I have also successfully made an Application.cfc that extends a cfc in the same directory.
I just haven't successfully made an Application.cfc that can extend a cfc in another directory, even if it's a subdirectory.
I did try to use grep & related tools to strip every reference of "taffy.core" out of Taffy's source code so I could just dump all the taffy cfc's into my root directory along with Application.cfc so I could extend api.cfc, but I got different errors and didn't pursue that hacky solution any further.
<cfdump var=#expandPath('/mapping')# /> outputs /var/www/html/mapping.
uname#domain $>ls -la /var/www/html
drwxr-xr-x 3 root root 4096 Sep 16 00:34 .
drwxr-xr-x 7 root root 4096 May 28 2012 ..
lrwxrwxrwx 1 root root 19 Sep 16 00:34 cfide -> /var/www/html/CFIDE
drwxrwxr-x 10 apache root 4096 Sep 16 00:32 CFIDE
~/public_html/api/resources/successesCollection.cfc:
<cfcomponent extends="taffy.core.resource" taffy_uri="/successes">
<cffunction name="get" access="public" output="false">
<cfreturn representationOf('success').withStatus(200) />
</cffunction>
</cfcomponent>
~/public_html/api/Application.cfc:
<cfcomponent extends="taffy.core.api">
<!--- doesn't work
<cfset THIS.mappings["/taffy"]= getDirectoryFromPath(getCurrentTemplatePath()) & "taffy/">
<cfset THIS.mappings["/core"]= getDirectoryFromPath(getCurrentTemplatePath()) & "taffy/core/">
--->
<cfscript>
this.name = hash(getCurrentTemplatePath());
// do your onApplicationStart stuff here
function applicationStartEvent(){}
// do your onRequestStart stuff here
function requestStartEvent(){}
// this function is called after the request has been parsed and all request details are known
function onTaffyRequest(verb, cfc, requestArguments, mimeExt){
// this would be a good place for you to check API key validity and other non-resource-specific validation
return true;
}
// called when taffy is initializing or when a reload is requested
function configureTaffy(){
setDebugKey("debug");
setReloadKey("reload");
setReloadPassword("true");
// Usage of this function is entirely optional. You may omit it if you want to use the default representation class.
// Change this to a custom class to change the default for the entire API instead of overriding for every individual response.
setDefaultRepresentationClass("taffy.core.genericRepresentation");
}
</cfscript>
</cfcomponent>
Output of http://domain.com/~uname/api/index.cfm/successes/: Could not find the ColdFusion Component or Interface taffy.core.api.
Adding this to my Application.cfc doesn't fix the issue:
<cfcomponent extends="taffy.core.api">
<cfscript>
this.name = hash(getCurrentTemplatePath());
this.mappings = StructNew();
this.mappings['/taffy'] =
expandPath('./taffy');
In addition, adding the following to ~/public_html/api/Application.cfc doesn't fix the issue either:
<cfset this.mappings["/taffy"] =
expandPath(getDirectoryFromPath(getCurrentTemplatePath()) & "taffy")>
Check out the following sequence of commands and let me know if I've overlooked something. I'm still left with "Could not find the ColdFusion Component or Interface taffy.core.api" upon browsing to "http://domain/~uname/api".
[uname#domain ~]$ cd ~/public_html
[uname#domain ~/public_html]$ rm -rf api
[uname#domain ~/public_html/api]$ wget -O taffy.zip https://github.com/atuttle/Taffy/zipball/master
[uname#domain ~/public_html/api]$ unzip taffy.zip
[uname#domain ~/public_html/api]$ mv atuttle-Taffy-35df54e/ taffy
[uname#domain ~/public_html/api]$ mv taffy/examples/api .
[uname#domain ~/public_html/api]$ mv taffy api/
[uname#domain ~/public_html/api]$ tree -d ~/public_html/api/
~/public_html/api/
|-- resources
`-- taffy
|-- bonus
|-- core
|-- examples
| |-- ParentApplication
| | |-- config
| | |-- mixin
... etc
[uname#domain ~/public_html/api]$ ls -la ~/public_html/api/
total 8
drwxr-xr-x 4 uname ugroup 1024 Dec 9 11:00 .
drwxr-xr-x 10 uname web 1024 Dec 9 10:57 ..
-rw-r--r-- 1 uname ugroup 1188 Dec 9 11:00 Application.cfc
-rw-r--r-- 1 uname ugroup 172 Sep 20 13:04 .htaccess
-rw-r--r-- 1 uname ugroup 218 Sep 20 13:04 index.cfm
drwxr-xr-x 2 uname ugroup 1024 Sep 20 13:04 resources
drwxr-xr-x 8 uname ugroup 1024 Sep 20 13:04 taffy
[uname#domain ~/public_html/api]$ ls -la ~/public_html/api/taffy/
total 15
drwxr-xr-x 8 uname ugroup 1024 Sep 20 13:04 .
drwxr-xr-x 4 uname ugroup 1024 Dec 9 11:00 ..
drwxr-xr-x 2 uname ugroup 96 Sep 20 13:04 bonus
-rw-r--r-- 1 uname ugroup 4096 Sep 20 13:04 build.xml
drwxr-xr-x 2 uname ugroup 1024 Sep 20 13:04 core
drwxr-xr-x 15 uname ugroup 1024 Dec 9 10:57 examples
-rw-r--r-- 1 uname ugroup 99 Sep 20 13:04 .gitignore
drwxr-xr-x 2 uname ugroup 96 Sep 20 13:04 lib
-rw-r--r-- 1 uname ugroup 1356 Sep 20 13:04 LICENSE.TXT
-rw-r--r-- 1 uname ugroup 2490 Sep 20 13:04 ReadMe.md
drwxr-xr-x 3 uname ugroup 96 Sep 20 13:04 snippets
drwxr-xr-x 5 uname ugroup 1024 Sep 20 13:04 tests
[uname#domain ~/public_html/api]$ ls -la ~/public_html/api/taffy/core/
total 72
drwxr-xr-x 2 uname ugroup 1024 Sep 20 13:04 .
drwxr-xr-x 8 uname ugroup 1024 Sep 20 13:04 ..
-rw-r--r-- 1 uname ugroup 42382 Sep 20 13:04 api.cfc
-rw-r--r-- 1 uname ugroup 4574 Sep 20 13:04 baseRepresentation.cfc
-rw-r--r-- 1 uname ugroup 2572 Sep 20 13:04 dashboard.cfm
-rw-r--r-- 1 uname ugroup 1756 Sep 20 13:04 dashboard.css
-rw-r--r-- 1 uname ugroup 4538 Sep 20 13:04 docs.cfm
-rw-r--r-- 1 uname ugroup 3030 Sep 20 13:04 factory.cfc
-rw-r--r-- 1 uname ugroup 179 Sep 20 13:04 genericRepresentation.cfc
-rw-r--r-- 1 uname ugroup 3516 Sep 20 13:04 mocker.cfm
-rw-r--r-- 1 uname ugroup 389 Sep 20 13:04 nativeJsonRepresentation.cfc
-rw-r--r-- 1 uname ugroup 3765 Sep 20 13:04 resource.cfc
You do have a couple of options.
Mapping (per-application or otherwise)
As Taffy is a development framework, your sysadmin/host may be willing to install it in a central location for all developers to make use of. They could put the Taffy folder in the web root, or create a server-level mapping to wherever the folder may be.
Relative Path
It should be possible to run Taffy from a relative path. It sounds like this is the approach you're trying to take, but you may not have the files in the right locations.
In order to use relative paths, you need a directory structure that resembles:
~uname/api/
~uname/api/taffy/core/api.cfc <- Framework contents
~uname/api/taffy/core/factory.cfc
~uname/api/taffy/core/dashboard.cfm
~uname/api/taffy/core/...
~uname/api/taffy/...
~uname/api/Application.cfc <- your api code
~uname/api/index.cfm
~uname/api/resources <- where you put your resource CFC's
It sounds like you're missing the "taffy" folder and either put the CFC's directly in your api folder or put the "core" folder in your api folder.
The "taffy" folder is required. Think of the dot-notation path you're putting in your Application.cfc's extends attribute as a filesystem path. Since it's taffy.core.api then your filesystem needs to contain taffy/core/api.cfc.
Have you tried using a relative path proxy, as Ben Nadel explains here: http://www.bennadel.com/blog/2115-Extending-The-Application-cfc-ColdFusion-Framework-Component-With-A-Relative-Path-Proxy.htm
The idea is that your application.cfc would extend a local proxy (rootProxy.cfc) that resides in the same directory. That proxy then cfincludes the cfc you are interested in. Since cfinclude takes a relative path, you needn't worry about global dot notation or mappings.