Wednesday, 30 July 2025

Ubuntu when will temp directory be cleared

 In Ubuntu, files within the /tmp directory are generally handled in two primary ways regarding their removal:

  • On System Reboot:
    The most common method of clearing /tmp is during a system reboot. By default, Ubuntu and other Debian-based distributions are configured to remove files from /tmp when the system starts up, particularly if their modification time exceeds a certain threshold defined by the TMPTIME variable in /etc/default/rcSA value of TMPTIME=0 will cause files to be removed regardless of age on boot, while other values specify a grace period (e.g., TMPTIME=7 for 7 days).
  • By systemd-tmpfiles-clean.timer:
    Modern Ubuntu systems often utilize systemd for managing temporary files. The systemd-tmpfiles-clean.timer service is typically configured to run daily and clean up temporary files based on rules defined in /usr/lib/tmpfiles.d/tmp.conf and potentially other configuration files in /etc/tmpfiles.d/These rules specify the age after which files in various temporary directories, including /tmp and /var/tmp, should be removed. For instance, files in /tmp might be cleaned after 10 days of inactivity, and those in /var/tmp after 30 days. 
Therefore, tmp directory files are removed either upon system reboot or periodically by the systemd-tmpfiles-clean.timer service, depending on their age and the system's configuration.

GO LANG GORILLA SESSION

 The gorilla/sessions package in Go handles session management, and when configured to use CookieStore, it sets a cookie in the browser to maintain session state. This process involves the following steps:


Gorilla session also creates session file in OS temp directory 

https://stackoverflow.com/questions/73263370/gorilla-session-not-setting-cookie

  • Initialization of CookieStore:
    You initialize a CookieStore by providing a secret key. This key is crucial for authenticating and encrypting session data stored in the cookie, ensuring its integrity and preventing tampering.
  • Session Retrieval/Creation:
    In your HTTP handler, you call store.Get(r, "session-name") to either retrieve an existing session associated with the incoming request or create a new one if no session with that name is found.
  • Data Storage:
    You can then store data within the session.Values map, which is a map[interface{}]interface{}This map holds the key-value pairs representing your session data.
  • Saving the Session:
    Crucially, you call session.Save(r, w) (or store.Save(r, w, session)) before writing any other content to the http.ResponseWriterThis method serializes the session data (including the session.Values), encrypts it using the secret key, and then sets the Set-Cookie HTTP header in the response.
  • Browser Action:
    When the browser receives the Set-Cookie header in the HTTP response, it stores the cookie containing the session ID and the encrypted session data.
  • Subsequent Requests:
    On subsequent requests to the same domain, the browser automatically includes this cookie in the Cookie HTTP header of the request, allowing gorilla/sessions on the server to retrieve and decrypt the session data, thus maintaining the user's state across requests.
Important Note: The MaxAge option, either set globally for the CookieStore or individually for a session's Options, determines how long the browser should retain the cookie. This MaxAge value is included in the Set-Cookie header sent to the browser.

Wednesday, 23 July 2025

GIT precommit hooks

 .git/hooks/precommit


write a bash script, will be executed after git commit 


Create a file named pre-commit (without any extension) in your .git/hooks/ directory within your Git repository. Ensure this file is executable (chmod +x .git/hooks/pre-commit).


precommit need to check pwd see where root folder is

code check bin using go 

https://github.com/Done-0/fuck-u-code


GIT does not upload this to remote, so it must be local 

#!/bin/bash

pwd

# Define the path to your Go executable

GO_EXECUTABLE=".git/hooks/fuck-u-code"


# Check if the Go executable exists

 if [ ! -f "$GO_EXECUTABLE" ]; then

     echo "Error: Executable '$GO_EXECUTABLE' not found in the same directory as the hook."

         exit 1

         fi



# Run the Go executable

"$GO_EXECUTABLE" analyze  rootsubfod1/cli


# Check the exit status of the Go executable

if [ $? -ne 0 ]; then

             echo "Check code failed. Aborting commit."

                 exit 1

fi


echo "Check code finished successfully. Please record the analysis, proceeding with commit."

exit 0


open ssl check cert purpose

 openssl x509 -in 57EMM020001.cer -noout -purpose 

Certificate purposes:
SSL client : No
SSL client CA : No
SSL server : No
SSL server CA : No
Netscape SSL server : No
Netscape SSL server CA : No
S/MIME signing : Yes
S/MIME signing CA : No
S/MIME encryption : No
S/MIME encryption CA : No
CRL signing : No
CRL signing CA : No
Any Purpose : Yes
Any Purpose CA : Yes
OCSP helper : Yes
OCSP helper CA : No
Time Stamp signing : No
Time Stamp signing CA : No
https://serverfault.com/questions/1035044/overriding-ssl-client-no-for-a-specific-nginx-vitual-server

Monday, 21 July 2025

Reverse proxy go lang vs jvm vs ha proxy

 HA Proxy has higher performance, but due its configuration based its hard for customized logic


GO has a realtively good performance, good at handling customized logic, one goruoutine handles one request, and go routine is not 1:1 thread to OS thread



JVM thread is OS thread worst of all

https://samsadsajid.medium.com/designing-a-reverse-proxy-why-golang-performs-better-than-java-spring-boot-an-in-depth-analysis-dc43de9861c7



https://serverfault.com/questions/618957/dynamic-haproxy-configuration#:~:text=If%20you%20authorize%20your%20stats,can%20send%20commands%20to%20it.&text=Mark%20the%20server%20DOWN%20for,centrally%20manage%20that%2C%20of%20course.


Generally go lang is good for customization, if you really have millions of request, u can do customizations with GO such as API  and proxy with HA proxy

Wednesday, 16 July 2025

redis data presistence

 https://redis.io/docs/latest/operate/oss_and_stack/management/persistence/


  • RDB (Redis Database): RDB persistence performs point-in-time snapshots of your dataset at specified intervals.
  • AOF (Append Only File): AOF persistence logs every write operation received by the server. These operations can then be replayed again at server startup, reconstructing the original dataset. Commands are logged using the same format as the Redis protocol itself.
  • No persistence: You can disable persistence completely. This is sometimes used when caching.
  • RDB + AOF: You can also combine both AOF and RDB in the same instance.

AOF needs more memory (30% free memory)
but can save on every write 
disk usage can also be big

https://stackoverflow.com/questions/25328317/does-redis-persist-data

.env file when are quotes required

 https://stackoverflow.com/questions/71538752/when-are-quotes-needed-in-env-file



Use the quotation marks when the string contains spaces or certain special character and certain syntaxes. These include:

  • space and other whitespace,

  • backslash (escapes a space and newline – \  gives space even in unquoted string),

  • quotation marks (but you can combine multiple quotation mark\ 'styles like'"this"),

  • pound sign (#) that marks start of comment (if it is not in quotes string or $(…)),

  • dollar sign (that is used to expand a variable – see below),

  • parentheses (( and )) – depending on context,

  • shell redirection chars (><2>| etc.),

  • asterisk (*) and question mark (?), since it is used in globs,

  • square brackets (because they list characters),

  • comma-separated text in {…} (because it provides multiple variants of text – {foo,bar}baz expands to foobaz barbaz),

  • maybe others,

  • and of course, the newline.