Ubuntu: Remove CGroup from systemctl status output



Question:

I have PHP7.0-FPM running with 125 start servers, and I like to check its status after restarting it. With systemctl status, this of course produces over 130 lines of output, making it difficult to read quickly.

root@web2:/etc/php/7.0/fpm/pool.d# systemctl --no-pager --full status php7.0-fpm  ● php7.0-fpm.service - The PHP 7.0 FastCGI Process Manager     Loaded: loaded (/lib/systemd/system/php7.0-fpm.service; enabled; vendor preset: enabled)     Active: active (running) since Thu 2016-10-27 13:38:29 CDT; 13min ago    Process: 5961 ExecStartPre=/usr/lib/php/php7.0-fpm-checkconf (code=exited, status=0/SUCCESS)   Main PID: 5971 (php-fpm7.0)     Status: "Processes active: 0, idle: 125, Requests: 12, slow: 0, Traffic: 0req/sec"      Tasks: 126     Memory: 294.2M        CPU: 728ms     CGroup: /system.slice/php7.0-fpm.service             â"œâ"€5971 php-fpm: master process (/etc/php/7.0/fpm/php-fpm.conf)             â"œâ"€5974 php-fpm: pool www             â"œâ"€5975 php-fpm: pool www             â"œâ"€5976 php-fpm: pool www             â"œâ"€5977 php-fpm: pool www             â"œâ"€5978 php-fpm: pool www             â"œâ"€5979 php-fpm: pool www             â"œâ"€5980 php-fpm: pool www             â"œâ"€5981 php-fpm: pool www             â"œâ"€5982 php-fpm: pool www             â"œâ"€5983 php-fpm: pool www             â"œâ"€5984 php-fpm: pool www             â"œâ"€5985 php-fpm: pool www             â"œâ"€5986 php-fpm: pool www             â"œâ"€5987 php-fpm: pool www             â"œâ"€5988 php-fpm: pool www             â"œâ"€5989 php-fpm: pool www             â"œâ"€5990 php-fpm: pool www             â"œâ"€5991 php-fpm: pool www             â"œâ"€5992 php-fpm: pool www             â"œâ"€5993 php-fpm: pool www             â"œâ"€5994 php-fpm: pool www             â"œâ"€5995 php-fpm: pool www             â"œâ"€5996 php-fpm: pool www             â"œâ"€5997 php-fpm: pool www             â"œâ"€5998 php-fpm: pool www             â"œâ"€5999 php-fpm: pool www             â"œâ"€6000 php-fpm: pool www             â"œâ"€6001 php-fpm: pool www             â"œâ"€6002 php-fpm: pool www             â"œâ"€6003 php-fpm: pool www             â"œâ"€6004 php-fpm: pool www             â"œâ"€6005 php-fpm: pool www             â"œâ"€6006 php-fpm: pool www             â"œâ"€6007 php-fpm: pool www             â"œâ"€6008 php-fpm: pool www             â"œâ"€6009 php-fpm: pool www             â"œâ"€6010 php-fpm: pool www             â"œâ"€6011 php-fpm: pool www             â"œâ"€6012 php-fpm: pool www             â"œâ"€6013 php-fpm: pool www             â"œâ"€6014 php-fpm: pool www             â"œâ"€6015 php-fpm: pool www             â"œâ"€6016 php-fpm: pool www             â"œâ"€6017 php-fpm: pool www             â"œâ"€6018 php-fpm: pool www             â"œâ"€6019 php-fpm: pool www             â"œâ"€6020 php-fpm: pool www             â"œâ"€6021 php-fpm: pool www             â"œâ"€6022 php-fpm: pool www             â"œâ"€6023 php-fpm: pool www             â"œâ"€6024 php-fpm: pool www             â"œâ"€6025 php-fpm: pool www             â"œâ"€6026 php-fpm: pool www             â"œâ"€6027 php-fpm: pool www             â"œâ"€6028 php-fpm: pool www             â"œâ"€6029 php-fpm: pool www             â"œâ"€6030 php-fpm: pool www             â"œâ"€6031 php-fpm: pool www             â"œâ"€6032 php-fpm: pool www             â"œâ"€6033 php-fpm: pool www             â"œâ"€6034 php-fpm: pool www             â"œâ"€6035 php-fpm: pool www             â"œâ"€6036 php-fpm: pool www             â"œâ"€6037 php-fpm: pool www             â"œâ"€6038 php-fpm: pool www             â"œâ"€6039 php-fpm: pool www             â"œâ"€6040 php-fpm: pool www             â"œâ"€6041 php-fpm: pool www             â"œâ"€6042 php-fpm: pool www             â"œâ"€6043 php-fpm: pool www             â"œâ"€6044 php-fpm: pool www             â"œâ"€6045 php-fpm: pool www             â"œâ"€6046 php-fpm: pool www             â"œâ"€6047 php-fpm: pool www             â"œâ"€6048 php-fpm: pool www             â"œâ"€6049 php-fpm: pool www             â"œâ"€6050 php-fpm: pool www             â"œâ"€6051 php-fpm: pool www             â"œâ"€6052 php-fpm: pool www             â"œâ"€6053 php-fpm: pool www             â"œâ"€6054 php-fpm: pool www             â"œâ"€6055 php-fpm: pool www             â"œâ"€6056 php-fpm: pool www             â"œâ"€6057 php-fpm: pool www             â"œâ"€6058 php-fpm: pool www             â"œâ"€6059 php-fpm: pool www             â"œâ"€6060 php-fpm: pool www             â"œâ"€6061 php-fpm: pool www             â"œâ"€6062 php-fpm: pool www             â"œâ"€6063 php-fpm: pool www             â"œâ"€6064 php-fpm: pool www             â"œâ"€6065 php-fpm: pool www             â"œâ"€6066 php-fpm: pool www             â"œâ"€6067 php-fpm: pool www             â"œâ"€6068 php-fpm: pool www             â"œâ"€6069 php-fpm: pool www             â"œâ"€6070 php-fpm: pool www             â"œâ"€6071 php-fpm: pool www             â"œâ"€6072 php-fpm: pool www             â"œâ"€6073 php-fpm: pool www             â"œâ"€6074 php-fpm: pool www             â"œâ"€6075 php-fpm: pool www             â"œâ"€6076 php-fpm: pool www             â"œâ"€6077 php-fpm: pool www             â"œâ"€6078 php-fpm: pool www             â"œâ"€6079 php-fpm: pool www             â"œâ"€6080 php-fpm: pool www             â"œâ"€6081 php-fpm: pool www             â"œâ"€6082 php-fpm: pool www             â"œâ"€6083 php-fpm: pool www             â"œâ"€6084 php-fpm: pool www             â"œâ"€6085 php-fpm: pool www             â"œâ"€6086 php-fpm: pool www             â"œâ"€6087 php-fpm: pool www             â"œâ"€6088 php-fpm: pool www             â"œâ"€6089 php-fpm: pool www             â"œâ"€6090 php-fpm: pool www             â"œâ"€6091 php-fpm: pool www             â"œâ"€6092 php-fpm: pool www             â"œâ"€6093 php-fpm: pool www             â"œâ"€6094 php-fpm: pool www             â"œâ"€6095 php-fpm: pool www             â"œâ"€6096 php-fpm: pool www             â"œâ"€6097 php-fpm: pool www             â""â"€6098 php-fpm: pool www    Oct 27 13:38:29 web2 systemd[1]: Starting The PHP 7.0 FastCGI Process Manager...  Oct 27 13:38:29 web2 systemd[1]: Started The PHP 7.0 FastCGI Process Manager.  

I really don't need all the CGroup info that it outputs. I just want the quick status and the few log lines at the bottom. I can filter the output like this:

root@web2:/etc/php/7.0/fpm/pool.d# systemctl --no-pager status php7.0-fpm | grep -v "php-fpm: pool www"  ● php7.0-fpm.service - The PHP 7.0 FastCGI Process Manager     Loaded: loaded (/lib/systemd/system/php7.0-fpm.service; enabled; vendor preset: enabled)     Active: active (running) since Thu 2016-10-27 13:38:29 CDT; 19min ago    Process: 5961 ExecStartPre=/usr/lib/php/php7.0-fpm-checkconf (code=exited, status=0/SUCCESS)   Main PID: 5971 (php-fpm7.0)     Status: "Processes active: 0, idle: 125, Requests: 16, slow: 0, Traffic: 0req/sec"      Tasks: 126     Memory: 295.5M        CPU: 737ms     CGroup: /system.slice/php7.0-fpm.service             â"œâ"€5971 php-fpm: master process (/etc/php/7.0/fpm/php-fpm.conf)                          Oct 27 13:38:29 web2 systemd[1]: Starting The PHP 7.0 FastCGI Process Manager...  Oct 27 13:38:29 web2 systemd[1]: Started The PHP 7.0 FastCGI Process Manager.  

But then I lose the colored formatting in bash that is also really useful for a quick status check.

Is there any way in systemctl or similar command to get this status info without the CGroup?


Solution:1

I don't think it will be possible to get the color if you process the output in any way. systemctl detects when its output isn't a tty and doesn't produce colored output. This is often the default behavior since that's usually what you want.

As a workaround, here's a little script that parses out the CGroup info, and adds the color back on:

perl -MTerm::ANSIColor -ne 'next if /^CGroup/ || /â"œâ"€/;       s/(?>: )active/color("bold green").$&.color("reset")/e; print'  

Pass your systemctl output through that and the word active will be green:

systemctl --no-pager status php7.0-fpm |      perl -MTerm::ANSIColor -ne 'next if /^CGroup/ || /â"œâ"€/;       s/(?>: )active/color("bold green").$&.color("reset")/e; print'  

If you edit your question and add different output (I don't have the service installed so I don't know what else should be colored), I can extend this to other possible outputs.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »