Unix: Simple Command Knowledge - unix

What does each token specify (in regards to docker) in the following command?
docker run --rm -it alpine chown nobody /

docker run --rm -it alpine chown nobody /
| | || | | |
| | | ------ ------------
| | | | |
Start running a container
| | | |
Delete the container when it's finished running
| | |
Interactive mode, attach to your terminal's stdin
| |
Tag. Runs container tagged `alpine`
|
Run `chown nobody /` inside container
Note that the command chown nobody / won't do anything because the changes are lost as soon as the container exits.

By running docker run --help you will see all the options and their meaning:
-i, --interactive Keep STDIN open even if not attached
--rm Automatically remove the container
when it exits
As for the chown nobody /, this command runs on container startup.
This command will change the owner of root dir (which is aliased by /) to user nobody. The user nobody is a special user available in linux distributions.

Related

mariadb server: I can't stop the server with `mysql.server stop`

OSX 10.13.6
I installed mariadb sever with homebrew a few years ago, and I use it infrequently. Today, I tried to start mariadb using the command:
$ mysql.server start
and I got a bunch of errors. So, I did:
$ brew update
then:
$ brew uprade mariadb
That completed fine, and now I can start mariadb with:
$ mysql.server start
and I can access all my old db's.
The problem I'm having is that I cannot stop mysql. Both these commands hang:
$ mysql.server stop
and(in another terminal window):
$ mysql.server status
According to the MariaDB docs for mysql.server, both those commands should work.
Currently, I'm killing the server like this:
$ killall mysqld mysqld_safe
then checking that the server was killed with this:
$ ps aux | grep mysqld
When I run the ps command when mysql is running, I get:
~$ ps aux | grep mysqld
7stud 3707 0.0 1.0 4808208 79948 s005 S 1:26PM 0:00.47
/usr/local/Cellar/mariadb/10.3.15/bin/mysqld
--basedir=/usr/local/Cellar/mariadb/10.3.15 --datadir=/usr/local/var/mysql --plugin-dir=/usr/local/Cellar/mariadb/10.3.15/lib/plugin --log-error=/usr/local/var/mysql/My-MacBook-Pro-2.local.err --pid-file=/usr/local/var/mysql/My-MacBook-Pro-2.local.pid
7stud 3643 0.0 0.0 4287792 1460 s005 S 1:26PM 0:00.02 /bin/sh
/usr/local/Cellar/mariadb/10.3.15/bin/mysqld_safe
--datadir=/usr/local/var/mysql --pid-file=/usr/local/var/mysql/My-MacBook-Pro-2.local.pid
7stud 4544 0.0 0.0 4267752 880 s000 S+ 1:41PM 0:00.00
grep mysqld
What is the proper way to shut down the mariadb server?
mysql> SHOW VARIABLES LIKE '%vers%';
+---------------------------------+------------------------------------------+
| Variable_name | Value |
+---------------------------------+------------------------------------------+
| innodb_version | 10.3.15 |
| protocol_version | 10 |
| slave_type_conversions | |
| system_versioning_alter_history | ERROR |
| system_versioning_asof | DEFAULT |
| thread_pool_oversubscribe | 3 |
| version | 10.3.15-MariaDB |
| version_comment | Homebrew |
| version_compile_machine | x86_64 |
| version_compile_os | osx10.13 |
| version_malloc_library | system |
| version_source_revision | 07aef9f7eb936de2b277f8ae209a1fd72510c011 |
| version_ssl_library | OpenSSL 1.0.2r 26 Feb 2019 |
| wsrep_patch_version | wsrep_25.24 |
+---------------------------------+------------------------------------------+
14 rows in set (0.01 sec)
I had the same issue, tried to use mysql.server stop and mysql.server status after running mysql.server start but they will just run indefinitely.
If you are using a Mac seems that mysql.server stop won't work... I installed mariadb with homebrew and found out that I can use brew services to start and stop it in this link:
https://dba.stackexchange.com/questions/214883/homebrew-mariadb-server-start-error-with-mysql-server-start
The commands are pretty simple and they work for me
brew services start mariadb
brew services stop mariadb
It may be a little late but I hope this helps you to figure out your problem.
See https://stackoverflow.com/a/59938033/4579271 for details.
To fix, run:
cp /usr/local/bin/mysql.server /usr/local/bin/mysql.server.backup
sed -i "" "s/user='mysql'/user=\`whoami\`/g" /usr/local/bin/mysql.server

Not able to start grakn, Storage is not able to start

I have installed grakn on unix and earlier it was working fine but now giving issues as it is not able to start.
I tried to run it using below command:
./grakn server start
Getting below error.
Starting Storage-FAILED!
Unable to start Storage
Please run 'grakn server status' or check the logs located under 'logs' directory.
There may be lot of things happening under the hood. Without looking into logs this is hard to tell what exactly happening. You can try killing all the processes and then remove associate pids from /tmp/ directory. Then retry starting grakn server.
$ for KILLPID in `ps ax | grep 'grakn' | awk '{print $1}'`; do kill -9 $KILLPID; done
$ ps -ef | grep defunct | grep -v grep | cut -b8-20 | xargs kill -9
$ rm -rf /tmp/grakn-*
Let me know if it helps.

Getting a bundle state via script from Karaf 3.0.5

I can check a bundle state from Karaf Console by doing:-
karaf#root>bundle:list | grep camel-test
246 | Active | 50 | 2.16.1 | camel-test
Is there a way I can do this programatically via some script running on the same machine as Karaf or via some REST End Point that Karaf exposes?
I am using Karaf 3.0.5 running under ServiceMix 6.0.1.
As discussed in Karaf User Forum I am able to achieve it using the karaf client:-
jabong#jabong1143:~/Downloads/apache-servicemix-6.1.0/bin$ ./client -l 0 -u karaf "bundle:list" | grep camel-test
246 | Active | 50 | 2.16.1 | camel-test

How to kill process inside container? Docker top command

I have simple example from official guide at docker website.
I run the following:
sudo docker run -d ubuntu:latest /bin/sh -c "while true; do echo hello world; sleep 1; done"
a66asdasdhqie123...
Then take some output from created container:
sudo docker logs a66
hello
hello
hello
...
Then I lookup the running processes of a container:
sudo docker top a66
UID PID PPID C STIME TTY TIME CMD
root 25055 15152 0 20:07 ? 00:00:00 /bin/sh -c while true; do echo hello world; sleep 1; done
root 25295 25055 0 20:10 ? 00:00:00 sleep 1
Next I try to kill the first process of container:
sudo docker exec a66 kill -9 25055
However after I make it nothing changes. Process still works and output "hello" every second. What do I wrong?
When I reproduce your situation I see different PIDs between docker top <container> and docker exec -it <container> ps -aux. When you do docker exec the command is executed inside the container => should use container's pid. Otherwise you could do the kill without docker straight from the host, in your case: sudo kill -9 25055.
check this:
ps | grep -i a66 | tr -s ' '|cut -f2 -d' '|
{
while read line;
do kill -9 $line;
done
}
to understand this start from executing commands from left till end of each pipe (|)
Simpler option:
kill $(pidof a66)
Took me a while to find the right answer, but you will have to manage this process from within the container. When you run docker top a66 from the host, the PIDs are from your host, although that's not quite the case if using Cygwin. Regardless, you will need to bash or what-have-you back into your container and use commands like ps aux and kill while in the container to find and manage the different PIDs for the same processes there.
i was looking for something like this, but i couldn't find and then i did this:
[root#notebook ~]# docker exec -it tadeu_debian ps aux | grep ping |
awk '{ print $2 }' | xargs -I{} docker exec -i tadeu_debian kill -9
It was two "execs" from Docker e one xargs.
Well, i hope this helps someone!
when you build Docker, use this command :
RUN apt-get install lsof
then in py file you can use:
os.system("lsof /dev/nvidia* | awk '{print $2}' | xargs -I {} kill {}")
REMEMBER: this command kill all process on GPU

Manage RabbitMQ consumers

I am planning to write a log processing application using RabbitMQ, Symfony2 and the RabbitMqBundle.
The tool I am working on has to be highly available and must process millions of entries per day, so it's important that the consumers are always up and running (short breaks are fine), otherwise my queue might overflow after a while.
Are there best practices on how to manage the consumers (written in PHP), start/restart them in case of an error etc?
Thanks
I use this bash script to make sure that there are all required consumers running on imagepush.to:
#!/bin/bash
NB_TASKS=1
SYMFONY_ENV="prod"
TEXT[0]="app/console rabbitmq:consumer primary"
TEXT[1]="app/console rabbitmq:consumer secondary"
for text in "${TEXT[#]}"
do
NB_LAUNCHED=$(ps ax | grep "$text" | grep -v grep | wc -l)
TASK="/usr/bin/env php ${text} --env=${SYMFONY_ENV}"
for (( i=${NB_LAUNCHED}; i<${NB_TASKS}; i++ ))
do
echo "$(date +%c) - Launching a new consumer"
nohup $TASK &
done
done
If I remember correctly I took base from KnpBundles code.
Stop consumer
To stop your consumer with name my_consumer use
kill `ps aux | less | grep 'rabbitmq:consumer my_consumer' | grep -v grep | awk '{print $2}'`
ps aux | less | grep 'rabbitmq:consumer my_consumer' - will find all running processes of the consumer
grep -v grep - will exclude your own search process
awk '{print $2}' - get only process id from the row
kill - will terminate all found processes
Start consumer
To start your consumer with name my_consumer use
nohup /usr/bin/env php app/console rabbitmq:consumer consumer --env=prod &
I have a lot of consumers in the project and it became hard to restart them after deploy. And I started using Capistrano + Symfony plugin to deploy my project. I wrote a few custom tasks to start/stop/restart the consumers based on the yaml config. Tasks are based on the commands from above.

Resources