Options

Linux question of the day

123457

Comments

  • Options
    W StewartW Stewart Member Posts: 794 ■■■■□□□□□□
    Forgot to mention. crash is due to a memory leak so I'm not too sure that increasing swap space is a solution. I believe cache memory also frees itself when an application needs it. In this particular situation, the server is a dedicated server and we're mostly hands off when it comes to personal data, so what can we do so that we don't have to run across the street and reboot the box every time it runs out of memory? I'll give you a hint, the solution is already built into the kernel.
  • Options
    W StewartW Stewart Member Posts: 794 ■■■■□□□□□□
    Okay another hint. Lets say I just wanted the system to reboot itself when it ran out of memory rather than hanging so that I wouldn't have to run across the street to reboot it myself. What's the best way to accomplish this?
  • Options
    onesaintonesaint Member Posts: 801
    Forgot to reply! You're talking about the OOM killer I suspect. Had to look this one up and found a great article on this from Oracle here.
    Work in progress: picking up Postgres, elastisearch, redis, Cloudera, & AWS.
    Next up: eventually the RHCE and to start blogging again.

    Control Protocol; my blog of exam notes and IT randomness
  • Options
    TrashmanTrashman Member Posts: 140
    I agree with Marco71 on why it is a bad idea and what can go wrong. I would take a different route to perform the delete and just do
    rm -rf TrashCan/*
    

    If you fat finger the name TrashCan, it would simply come back with a "No such file or directory" error.

    Don't delete my TrashCan icon_cry.gif
    Bachelor of Science in Information Systems
    2015 COLOR=#008000]X[/COLOR | 2016 COLOR=#ff8c00]In progress[/COLOR | 2017 | 2018
  • Options
    W StewartW Stewart Member Posts: 794 ■■■■□□□□□□
    onesaint wrote: »
    Forgot to reply! You're talking about the OOM killer I suspect. Had to look this one up and found a great article on this from Oracle here.

    That's it. I did have to look it up as well but I figured there had to be a sysctl setting to alter the way the system behaved when it ran out of memory but I was already aware of being able to set the reboot time on a kernel panic. I went on a week long vacation but I still check the shift reports and it doesn't look like anybody has ad to manually reboot the box yet.
  • Options
    MentholMooseMentholMoose Member Posts: 1,525 ■■■■■■■■□□
    You're logged in as root and cannot delete or modify a file even though you seem to have the proper permissions. Why is this happening?
    [root@linux ~]# ls -lZ asdf.txt
    -rw-r--r--. root root unconfined_u:object_r:admin_home_t:s0 asdf.txt
    [root@linux ~]# getfacl asdf.txt
    # file: asdf.txt
    # owner: root
    # group: root
    user::rw-
    group::r--
    other::r--
    
    [root@linux ~]# rm -fv asdf.txt
    rm: cannot remove `asdf.txt': Operation not permitted
    [root@linux ~]# echo asdf > asdf.txt
    bash: asdf.txt: Permission denied
    
    MentholMoose
    MCSA 2003, LFCS, LFCE (expired), VCP6-DCV
  • Options
    ExpectExpect Member Posts: 252 ■■■■□□□□□□
    chattr -/+ i ?
  • Options
    W StewartW Stewart Member Posts: 794 ■■■■□□□□□□
    ^ gonna have to go with Expect. Here's a more basic version of the same question. You're logged in as a normal user. You can read and modify a file but you can't delete it. Why is that?
  • Options
    ExpectExpect Member Posts: 252 ■■■■□□□□□□
  • Options
    W StewartW Stewart Member Posts: 794 ■■■■□□□□□□
  • Options
    onesaintonesaint Member Posts: 801
    all of the special mode stuff should show up in the mode attributes when running ls. I'm thinking this directory perms or an SELinux type error.
    Work in progress: picking up Postgres, elastisearch, redis, Cloudera, & AWS.
    Next up: eventually the RHCE and to start blogging again.

    Control Protocol; my blog of exam notes and IT randomness
  • Options
    W StewartW Stewart Member Posts: 794 ■■■■□□□□□□
    Which question is that an answer to?


    Edit: you would need to run lsattr to see if the +i flag was set with the chattr command.
  • Options
    MentholMooseMentholMoose Member Posts: 1,525 ■■■■■■■■□□
    Expect wrote: »
    chattr -/+ i ?
    Yes, that was fast.
    MentholMoose
    MCSA 2003, LFCS, LFCE (expired), VCP6-DCV
  • Options
    UnixGuyUnixGuy Mod Posts: 4,565 Mod
    Interesting, so how often do you see chattr used in production? How useful is it? Have you seen in production? what was it used for?
    Certs: GSTRT, GPEN, GCFA, CISM, CRISC, RHCE

    Learn GRC! GRC Mastery : https://grcmastery.com 

  • Options
    ExpectExpect Member Posts: 252 ■■■■□□□□□□
    UnixGuy wrote: »
    Interesting, so how often do you see chattr used in production? How useful is it? Have you seen in production? what was it used for?
    Everytime I write an upgrader script to a customer, I always keep old configuration files for a revert option, which means I move them to another directory and just chattr the files so accidental deletion won't happen. that's how I use chattr.
  • Options
    MentholMooseMentholMoose Member Posts: 1,525 ■■■■■■■■□□
    What command will let you view the current iptables rules? (generally distribution-agnostic)
    What is the default command-line "helper" application to create iptables rules on recent Fedora versions (and likely RHEL 7)? On recent Ubuntu versions? BONUS: Write an example command for both to open port 443/tcp.
    MentholMoose
    MCSA 2003, LFCS, LFCE (expired), VCP6-DCV
  • Options
    W StewartW Stewart Member Posts: 794 ■■■■□□□□□□
    UnixGuy wrote: »
    Interesting, so how often do you see chattr used in production? How useful is it? Have you seen in production? what was it used for?

    I've only seen it used at my previous place of employment to make sure customers didn't start arbitrarily messing with files. People seemed to treat it like more of a hacky work around and not the proper way of doing things though so it was only used so often. It's helpful when your offices dhcp server keeps overwriting your resolv.conf
  • Options
    W StewartW Stewart Member Posts: 794 ■■■■□□□□□□
    What command will let you view the current iptables rules? (generally distribution-agnostic)
    What is the default command-line "helper" application to create iptables rules on recent Fedora versions (and likely RHEL 7)? On recent Ubuntu versions? BONUS: Write an example command for both to open port 443/tcp.

    1. iptables-save
    2. system-config-firewall{,-tui} for redhat. I don't really use ubuntu so I'm not sure what the interface is called and I'd rather not **** and look it up.
    3.iptables -A INPUT -m state --state NEW,ESTABLISHED -p tcp --dport 443 -j ACCEPT
    It should be the same for both but redhat may add an additional RH-Firewall-INPUT-1 chain or something like that.



    Edit: Here's a question. Who can tell me what I did with system-config-firewall{,-tui}?
  • Options
    ExpectExpect Member Posts: 252 ■■■■□□□□□□
    it's a terminal user interface for managing iptables, basically a simple "gui" from the CLI, if that was your question(?)
  • Options
    MentholMooseMentholMoose Member Posts: 1,525 ■■■■■■■■□□
    W Stewart wrote: »
    1. iptables-save
    Yes, that's exactly what I had in mind. I'd also accept "iptables --list" since the question was kind of vague. :D

    2. I'm looking for the new CLI tool in recent Fedora versions which RHEL 7 will (likely) also use. system-config-firewall-tui does not work anymore (by default).

    BONUS. I'm looking for the command using the tools from 2.
    MentholMoose
    MCSA 2003, LFCS, LFCE (expired), VCP6-DCV
  • Options
    The TechnomancerThe Technomancer Member Posts: 96 ■■□□□□□□□□
    W Stewart wrote: »
    That's it. I did have to look it up as well but I figured there had to be a sysctl setting to alter the way the system behaved when it ran out of memory but I was already aware of being able to set the reboot time on a kernel panic. I went on a week long vacation but I still check the shift reports and it doesn't look like anybody has ad to manually reboot the box yet.

    A more elegant way of managing this, especially when the memory leak is a non-resolvable issue without a new software release, is to monitor the RAM usage by the application in question (either with a cronjob or an external monitoring source like Nagios) and throw a SIGHUP at the process if it crosses that threshold. Zero downtime, no 5 minute+ long reboot, etc.

    Example script for that to be run as a cronjob checking every minute...which assumes that the process mentioned here is the only one that would be causing the system to go OOM, and for example purposes, is the lone java app on a server:
    #!/bin/bash
    
    # This variable is the amount of free memory that you want to trigger the HUP at
    threshold=50000
    
    # This variable is the name of your process(es) you want to HUP
    process="java"
    
    # this variable is the free memory on the system as determined by vmstat
    memfree=$(vmstat -s | grep "free memory" | awk {'print $1'}) 
    
    # Logic loop
    
    if [[ $memfree -lte $threshold ]]; then
      sudo pkill -HUP $process  #leave off sudo if running out of root's crontab
    fi
    

    Run that every minute out of your system user's (or roots, leave off sudo) crontab. Add a notification to the if loop if you want to track how often this occurs.
    Any sufficiently advanced technology is indistinguishable from magic.
  • Options
    onesaintonesaint Member Posts: 801
    W Stewart wrote: »
    Which question is that an answer to?


    Edit: you would need to run lsattr to see if the +i flag was set with the chattr command.

    i was referring to the sticky bit, but, my answer was off. Good call to you and expect on the chattr +i.
    Work in progress: picking up Postgres, elastisearch, redis, Cloudera, & AWS.
    Next up: eventually the RHCE and to start blogging again.

    Control Protocol; my blog of exam notes and IT randomness
  • Options
    W StewartW Stewart Member Posts: 794 ■■■■□□□□□□
    Expect wrote: »
    it's a terminal user interface for managing iptables, basically a simple "gui" from the CLI, if that was your question(?)



    Sorry probably not clear enough. Explain what this does and why.
    ls /usr/bin/system-config-firewall{,-tui}
    
  • Options
    W StewartW Stewart Member Posts: 794 ■■■■□□□□□□
    A more elegant way of managing this, especially when the memory leak is a non-resolvable issue without a new software release, is to monitor the RAM usage by the application in question (either with a cronjob or an external monitoring source like Nagios) and throw a SIGHUP at the process if it crosses that threshold. Zero downtime, no 5 minute+ long reboot, etc.

    Example script for that to be run as a cronjob checking every minute...which assumes that the process mentioned here is the only one that would be causing the system to go OOM, and for example purposes, is the lone java app on a server:
    #!/bin/bash
    
    # This variable is the amount of free memory that you want to trigger the HUP at
    threshold=50000
    
    # This variable is the name of your process(es) you want to HUP
    process="java"
    
    # this variable is the free memory on the system as determined by vmstat
    memfree=$(vmstat -s | grep "free memory" | awk {'print $1'}) 
    
    # Logic loop
    
    if [[ $memfree -lte $threshold ]]; then
      sudo pkill -HUP $process  #leave off sudo if running out of root's crontab
    fi
    

    Run that every minute out of your system user's (or roots, leave off sudo) crontab. Add a notification to the if loop if you want to track how often this occurs.


    I was considering scripting something but it was a dedicated server and some of my coworkers would say that just changing the sysctl settings would be overstepping my boundaries but I figured it may as well have been a setting that we included by default before handing the server over to the customers. I would also hope that the reboots would eventually prompt the customer to do something about the memory leaks as well but our hands are really tied as far as what we can and can't touch on a customer's server.
  • Options
    The TechnomancerThe Technomancer Member Posts: 96 ■■□□□□□□□□
    Yeah, if it's customer colocated kit, you don't do anything they aren't filing a ticket and paying a remote hands and eyes fee for, and you're only doing what they tell you to prevent liability.
    Any sufficiently advanced technology is indistinguishable from magic.
  • Options
    W StewartW Stewart Member Posts: 794 ■■■■□□□□□□
    ^ You seem to know your stuff based on your other post so I'm sure you've got to have an answer for this one.

    ls /usr/bin/system-config-firewall{,-tui}

    What output do I get and why?
  • Options
    The TechnomancerThe Technomancer Member Posts: 96 ■■□□□□□□□□
    You'll get the same output as if you ran:

    ls /usr/bin/system-config-firewall /usr/bin/system-config-firewall-tui

    Curly braces indicate a shell glob, and when a comma is used, it represents multiple terms to be iterated over. Since the glob started with a comma, that meant the first term was blank, and -tui is tacked onto the end (as that was the location of the glob) of the term during the second iteration.
    Any sufficiently advanced technology is indistinguishable from magic.
  • Options
    W StewartW Stewart Member Posts: 794 ■■■■□□□□□□
    Finally somebody got it. The technical term is brace expansion. A very useful feature of bash that I like to use often at work.

    https://www.gnu.org/software/bash/manual/html_node/Brace-Expansion.html
  • Options
    The TechnomancerThe Technomancer Member Posts: 96 ■■□□□□□□□□
    Here's one:

    What is the ctime of a file, and how do you change it with one command?
    Any sufficiently advanced technology is indistinguishable from magic.
  • Options
    W StewartW Stewart Member Posts: 794 ■■■■□□□□□□
    I'm pretty sure the touch command will change it but I'm not to sure exactly what it is. I believe it was the last time the file was changed but I may have that confused with mtime.
Sign In or Register to comment.