Restarting the mosquito broker - macos

I have installed mosquito broker on my mac using brew install mosquitto.
Normally I don't give any commands to start the mosquitto server. It is started automatically when I switch on my mac.
I have verified that it is running by using the command ps -ef | grep mosquitto, which gives the following output
501 209 153 0 2:20PM ?? 0:06.93/usr/local/opt/mosquitto/sbin/mosquitto -c /usr/local/etc/mosquitto/mosquitto.conf
501 2559 1007 0 10:36AM ttys001 0:00.00 grep mosquitto
501 865 815 0 2:32PM ttys003 0:00.86 mosquitto_sub -h 127.0.0.1 -t esb.test2
Then I stopped the server by killing the mosquitto process using kill -9 above-pid.
Now I would like to know how can I restart the server again from command line, but without restarting my mac.

If you've installed mosquitto from homebrew, you can use launchctl to control the service, e.g.
$ launchctl load /usr/local/Cellar/mosquitto/1.4.2/homebrew.mxcl.mosquitto.plist
$ launchctl unload /usr/local/Cellar/mosquitto/1.4.2/homebrew.mxcl.mosquitto.plist
$ launchctl start homebrew.mxcl.mosquitto
$ launchctl stop homebrew.mxcl.mosquitto

You could kill the mosquitto process using the steps detailed in the answer here, then restart it in the same way you did originally.
To summarise the answer
killall mosquitto
Should do the job to stop the existing process.

Related

installed apache with brew but will not start - getting httpd (pid 89) already running

Apache with brew worked before, but it has stoped now, no idea why.
$ sudo apachectl start
httpd (pid 89) already running
But its not running, http://localhost gives me: "This site can’t be reached"
when I do:
$ ps aux | grep httpd
it shows nothing
when I do:
$ lsof -i TCP:80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
Google 308 darko 106u IPv4 0x98978f46d14516f9 0t0 TCP 192.168.1.5:50046->ec2-54-204-11-64.compute-1.amazonaws.com:http (ESTABLISHED)

Unable to kill CassandraDaemon

I am using source installation of cassandra. After installation I ran it like this:
$ pwd
/var/users/ec2-user/apache-cassandra-3.10
$ bin/cassandra -f
After this I am getting error:
ERROR [main] 2017-04-04 14:40:34,195 CassandraDaemon.java:752 - Port already in use: 7199; nested exception is:
java.net.BindException: Address already in use (Bind failed)
java.net.BindException: Address already in use (Bind failed)
Then I grep for 7199
$ ps aux | grep 7199
-javaagent:/home/ec2-user/apache-cassandra-3 .10/bin/../lib/jamm-0.3.0.jar -Dcassandra.jmx.local.port=7199
....
org.apache.cassandra.service.CassandraDaemon
Now I am unable to kill CassandraDaemon
kill -9 <process_id_of_CassandraDaemon>
or
pkill -f CassandraDaemon
This is not working. I get 7199 still running .
Please help.
Try one of this at a time:
Try to run these commands with sudo.
sudo service cassandra stop (if you are running on ubuntu).
Restart server :)
7199 is not the process id. It actually a port.
execute this command and find which program already acquired this port.
> netstat -antp | grep 7199
Then use kill command to terminate that program. After then try running cassandra again.
I found the answer by self.
my cassandra was running under supervisord so I had to stop supervisord by running following command
sudo /etc/init.d/supervisord stop
Then I can kill cassandra process.

Xt error: Can't open display, if using default DISPLAY

Overview
I'm attempting to get XQuartz to work on OSX so I can do X11 forwarding via Docker. I'm following the instructions here. I believe my question may be answered by just the first part, but just in case (to avoid the XY problem), I've provided the second part as well.
Installation
I've installed it via homebrew, via brew cask install xquartz. Then I open -a XQuartz to start it.
Local xterms
Testing it out, if I try to open an xterm, it does not work:
MacBook-Pro:opencv-gui csaftoiu$ xterm
xterm: Xt error: Can't open display: /private/tmp/com.apple.launchd.3wncZULdXC/org.macosforge.xquartz:0
The pseudo-file exists, though:
MacBook-Pro:opencv-gui csaftoiu$ echo $DISPLAY
/private/tmp/com.apple.launchd.3wncZULdXC/org.macosforge.xquartz:0
MacBook-Pro:opencv-gui csaftoiu$ ls -alh $DISPLAY
srw-rw-rw- 1 csaftoiu wheel 0B May 6 21:12 /private/tmp/com.apple.launchd.3wncZULdXC/org.macosforge.xquartz:0
I can open an xterm via XQuartz. Then:
bash-3.2$ echo $DISPLAY
:0
This value works from a regular OSX too:
$ DISPLAY=:0 xterm
# opens xterm, waits for it to finish
$
The following do not work though, not sure why based on the answer here:
xterm: Xt error: Can't open display: localhost:0
MacBook-Pro:opencv-gui csaftoiu$ DISPLAY=127.0.0.1:0 xterm
xterm: Xt error: Can't open display: 127.0.0.1:0
MacBook-Pro:opencv-gui csaftoiu$ DISPLAY=`ipconfig getifaddr en0`:0 xterm
xterm: Xt error: Can't open display: 192.168.1.15:0
Note that xinit does work for some reason:
$ xinit
xinit: XFree86_VT property unexpectedly has 0 items instead of 1
# opens xterm, waits for it to finish
xinit: connection to X server lost
waiting for X server to shut down
Question 1: What is XQuartz actually listening on?
Docker Forwarding with socat
In any case, moving on, this socat command does not work:
MacBook-Pro:opencv-gui csaftoiu$ socat TCP-LISTEN:6000,reuseaddr,fork UNIX-CLIENT:\"$DISPLAY\"
Running that, from another window I do:
MacBook-Pro:opencv-gui csaftoiu$ docker run --rm -it -e DISPLAY=`ipconfig getifaddr en0`:0 ubuntu:14.04 bash
root#912eec31b8cb:/# apt-get update && apt-get install xterm
... such install, wow ...
root#912eec31b8cb:/# xterm
Warning: This program is an suid-root program or is being run by the root user.
The full text of the error or warning message cannot be safely formatted
in this environment. You may get a more descriptive message by running the
program as a non-root user or by removing the suid bit on the executable.
xterm: Xt error: Can't open display: %s
root#912eec31b8cb:/# echo $DISPLAY
192.168.1.15:0
From the socat window I get:
2016/06/14 21:08:15 socat[24289] E connect(5, LEN=68 AF=1 "/private/tmp/com.apple.launchd.3wncZULdXC/org.macosforge.xquartz:0", 68): Connection refused
I can't use the DISPLAY variable that works, either:
MacBook-Pro:opencv-gui csaftoiu$ socat TCP-LISTEN:6000,reuseaddr,fork UNIX-CLIENT:\":0\"
2016/06/14 21:09:43 socat[24309] E connect(5, LEN=4 AF=1 ":0", 4): No such file or directory
Now, this is not a UNIX-CLIENT IP. But, I don't know what DISPLAY=:0 is connecting to. It's certainly not port 6000 since that's the port it used to be listening on. If I change it to 6005, to forward to 6000, and make the Docker container DISPLAY be $(ipconfig getifaddr en0):5 instead, then the connection is of course refused:
$ socat TCP-LISTEN:6005,reuseaddr,fork TCP:localhost:6000
2016/06/14 21:20:32 socat[25379] E connect(8, LEN=16 AF=2 127.0.0.1:6000, 16): Connection refused
Question 2: How to proceed from here?
I hadn't restarted after re-installing XQuartz. I restarted, and now it works. :).
Dockerized UI Apps in Docker for Desktop MacOS 2018+. Updated in in 2021.
Went through all the pain to get the simplest version possible that does not depend on checking port, ip, etc... Here it is.
Running version XQuartz 2.7.11 (xorg-server 1.18.4)
Docker version docker version 18.06.1-ce
Make sure to install XQuartz (Updated with 2021 change)
$ brew install socat
$ brew install --cask xquartz
Don't forget to close logout and log back in.
ATTENTION: At this point, make sure to reboot your host (MacOS for instance). The following error is related to when you don't: E connect(5, LEN=2 AF=1 "<anon>", 2): Invalid argument
$ socat TCP-LISTEN:6000,reuseaddr,fork UNIX-CLIENT:\"$DISPLAY\"
2021/04/04 17:28:58 socat[40606] E connect(5, LEN=2 AF=1 "<anon>", 2): Invalid argument
Instructions
You will need at 2 terminals open: one for the socat with the display and the other for running the UI container.
1. Close any 6000
On a new terminal, verify if there's anything running on port 6000
$ lsof -i TCP:6000
$
If there is anything, just kill the process
2. Close any 6000
Open a socket on that port and keep the terminal open
$ socat TCP-LISTEN:6000,reuseaddr,fork UNIX-CLIENT:\"$DISPLAY\"
3. Verify 6000 is open
In a new terminal, verify if it is opened
$ lsof -i TCP:6000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
socat 29298 marcellodesales 5u IPv4 0xe21e43ca9d99bf1d 0t0 TCP *:6000 (LISTEN)
4. Build and Run simple UI App
$ cat Dockerfile.eyes
FROM debian:latest
RUN apt-get update && apt-get install -y x11-apps
RUN rm -rf /tmp/* /usr/share/doc/* /usr/share/info/* /var/tmp/*
RUN useradd -ms /bin/bash user
ENV DISPLAY :0
USER user
ENTRYPOINT ["/bin/sh", "-c", "$0 \"$#\"", "xeyes"]
$ docker build -t eyes -f Dockerfile.eyes .
The magic happens using the variables from Docker. Just using the -e DISPLAY=docker.for.mac.host.internal:0 did the trick, as it it will point to the internal IP address and provide that to the docker image. The port forward will do its magic.
$ docker run -ti --rm -e DISPLAY=docker.for.mac.host.internal:0 eyes
I noticed that at this point XQuartz is opened on it own to the same port
$ lsof -i TCP:6000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
socat 29298 marcellodesales 5u IPv4 0xe21e43ca9d99bf1d 0t0 TCP *:6000 (LISTEN)
X11.bin 29462 marcellodesales 8u IPv6 0xe21e43ca7cdb1135 0t0 TCP *:6000 (LISTEN)
5. Profit and run more apps
$ docker run -e DISPLAY=docker.for.mac.host.internal:0 jess/tor-browser
$ docker run -e DISPLAY=docker.for.mac.host.internal:0 batmat/docker-eclipse
I needed to quit Terminal and then relaunch it in order to get it to work.
For OS X 10.6.3 and later, per XQuartz 2.7.11 instructions:
If this is your first time installing XQuartz, you may wish to logout and log back in. This will update your DISPLAY environment variable to point to XQuartz.app rather than X11.app. If you would prefer to keep using X11.app as your default server (you can still launch XQuartz.app manually), you’ll want to disable /Library/LaunchAgents/org.macosforge.xquartz.startx.plist using launchctl(1).
After installing XQuartz 2.7.11 on my macOS High Sierra, logging out of my Mac and logging in again was enough for this to work via my MacOS Terminal. However, you may avoid having to logout and log in by opening the XQuartz Terminal application (XQuartz > Applications > Terminal), and running your X application from there. For example:
and then
bash-3.2$ xclock &
This answer is possibly limited to MacOS/Monterey.
After running XQuartz and setting the Preferences/Security/"Allow connections from network clients" option, you must restart XQuartz. (It may be the case that after install, you must logoff/logon again, but I found that merely restarting XQuartz was sufficient.) Afterwards, when XQuartz is running again, you should see it listening on port 6000:
lsof -i TCP:6000
Before this restart step, only DISPLAY=:0 or the default file-based socket worked for me. After this step, I could then do
export DISPLAY=localhost:0
and xterm, xhost, etc worked fine.
To use with docker, I used:
xhost +localhost
DISPLAY=docker.for.mac.host.internal:0
docker run -e DISPLAY=$DISPLAY -v /tmp/X11-unix:/tmp/.X11-unix
I used this code will help you in macos Big sur
https://apple.stackexchange.com/questions/411619/how-to-make-dia-which-uses-x11-xquartz-work
export DISPLAY=:0 # Fixes the "cannot open display".
export LANG="en_US.UTF-8" # Fixes the annoying Xterm window opening.
exec "$CWD/dia-bin" --integrated

lighthttp, dbus, and myapp, without X11

I am running on a system without X11, 'myapp', which register a dbus server,
a php app which supposed to send a message over dbus to the server.
Everything worked smother on the development machine, (with gnome, X11)
but when I deployed on a server without X11, I ran on every dbus call into:
# process status
ps ax | grep dbus
2033 ? Ss 0:00 /usr/bin/dbus-daemon --system
2383 pts/0 S+ 0:00 grep --color=auto dbus
# listing names
dbus-send --session --print-reply --dest="org.freedesktop.DBus" /org/freedesktop/DBus org.freedesktop.DBus.ListNames
Failed to open connection to "session" message bus: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
# from php running with system("<above command> 2>&1"); I get same response
./myapp
terminate called after throwing an instance of 'DBus::Error'
what(): Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
Aborted
# same when calling into DBus::Connection bus = DBus::Connection::SessionBus();
If I am adding to ./.bashrc the following script
if test -z "$DBUS_SESSION_BUS_ADDRESS" ; then
## if not found, launch a new one
eval `dbus-launch --sh-syntax --exit-with-session`
echo "D-BUS per-session daemon address is: $DBUS_SESSION_BUS_ADDRESS"
fi
#reboot
ps ax |grep dbus
2023 ? Ss 0:00 /usr/bin/dbus-daemon --system
2389 pts/0 S 0:00 dbus-launch --sh-syntax --exit-with-session
2390 ? Ss 0:00 /usr/bin/dbus-daemon --fork --print-pid 4 --print-address 6 --session
2392 pts/0 S+ 0:00 grep --color=auto dbus
then, from same shell
dbus-send --session --print-reply --dest="org.freedesktop.DBus" /org/freedesktop/DBus org.freedesktop.DBus.ListNames
prints my server name, but from php
system("above command"); same error, and
system ("echo system("eval 'dbus-launch --auto-syntax' dbus-send --session --print-reply --dest=\"org.freedesktop.DBus\" /org/freedesktop/DBus org.freedesktop.DBus.ListNames 2>&1");
does not list the names.
The question is, how do join from lighthttpd the existent dbus session, or any other variants.
Thx
you have compiled dbus with x11 support. So dbus-launch will create problems.
Try
$ export DISPLAY=:0
and see if you are able to use dbus-launch
or directly launch the daemon
$ dbus-daemon --session --print-address
export the address to DBUS_SESSION_BUS_ADDRESS
Thx,
The DISPLAY=:0 did not quite resolved the problem.
I did not recompiled dbus without X11, but I am using
system bus and is OK. I have to use system bus
because the lighttp server talks to a service via dbus.actualy
I enabled rights in dbus config files and is just OK.

Postgres is failing with 'could not open relation mapping file "global/pg_filenode.map" '

I'm having an issue with my install of postgres in my development environment and I need some help diagnosing it. I haven't yet had any luck in tracking down a solution.
I have postgres 9.0.4 installed with homebrew
I am running on OS X 10.6.8 (Snow Leopard)
I can start and stop the server
$ pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
server starting
If I try to stop though
$ pg_ctl -D /usr/local/var/postgres stop -s -m fast
pg_ctl: PID file "/usr/local/var/postgres/postmaster.pid" does not exist
Is server running?
Ok this is missing
$ ls -l /usr/local/var/postgres/ | grep postmaster
$
But it is definitely running
$ ps aux | grep postgres
pschmitz 303 0.9 0.0 2445860 1428 ?? Ss 3:12PM 0:02.46 postgres: autovacuum launcher process
pschmitz 304 0.9 0.0 2441760 428 ?? Ss 3:12PM 0:02.57 postgres: stats collector process
pschmitz 302 0.0 0.0 2445728 508 ?? Ss 3:12PM 0:00.56 postgres: wal writer process
pschmitz 301 0.0 0.0 2445728 560 ?? Ss 3:12PM 0:00.78 postgres: writer process
pschmitz 227 0.0 0.1 2445728 2432 ?? S 3:11PM 0:00.42 /usr/local/Cellar/postgresql/9.0.3/bin/postgres -D /usr/local/var/postgres -r /usr/local/var/postgres/server.log
And if I try to access or use it I get this.
$psql
psql: FATAL: could not open relation mapping file "global/pg_filenode.map": No such file or directory
But global/pg_filenode.map definitely exists in
$ls -l /usr/local/var/postgres/
...
-rw------- 1 pschmitz staff 8192 Sep 16 15:48 pg_control
-rw------- 1 pschmitz staff 512 Sep 16 15:48 pg_filenode.map
-rw------- 1 pschmitz staff 12092 Sep 16 15:48 pg_internal.init
I have attempted to uninstall and reinstall to no effect. Any ideas on how I can solve this?
It has pretty much prevented me from getting anything done today.
I am not sure what the source of my original problem was with 9.0.3 because I was getting this problem:
psql: FATAL: could not open relation mapping file "global/pg_filenode.map": No such file or directory
However as stated above it turns out that the running process was for my previous postgres install of 9.0.3
I believe I had an old version org.postgresql.postgres.plist in ~/Library/LaunchAgents/
I had to:
Remove and re-add the launch agent
Kill the processes for 9.0.3
Initialize the db initdb /usr/local/var/postgres
Restart my computer
and now I have it up and working.
Encountered this problem using mdillon/postgis:9.6 Docker image. Simple sudo docker restart <container id> solved the problem.
That may be a permission issue, check the owner and group of configuration files in /var/lib/pgsql/9.3/data/
chown -R postgres:postgres /var/lib/pgsql/9.3/data/
I just encountered this problem. Solved it by setting the owner of the postgres data directory to the unprivileged postgres user.
ps aux | grep postgres revealed I had another instance of postgres running on a temp data directory from a previous test run. Killing this process fixed the problem.
My step-by-step solution in fedora:
/bin/systemctl stop postgresql.service (Stop the service)
rm -rf /var/lib/pgsql/data (Remove the "data" direcotry)
postgresql-setup initdb (Recreate the "data" directory)
/bin/systemctl start postgresql.service (Start the service)
It is also useful to check the permissions of the "data" directory:
chown -R postgres:postgres <path_to_data_dir>
(Kudos to #LuizFernandodaSilva & #user4640867)
I had an old value of PGDATA confusing things.
This (https://gist.github.com/olivierlacan/e1bf5c34bc9f82e06bc0) solved my problem! I first had to:
Delete Postgres.app from my Applications
Delete /usr/local/var/postgres directory
initdb /usr/local/var/postgres/
Then I was able to start/stop Postgres with these 2 commands:
Start:
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
Stop:
pg_ctl -D /usr/local/var/postgres stop -s -m fast
My solution to this problem:
I am running postgresql-9.3
My plist file is in the following directory:/Library/LaunchDaemons/com.edb.launchd.postgresql-9.3.plist
Step 1 will stop postgres
1. $ sudo launchctl stop com.edb.launchd.postgresql-9.3
Start postgres using the following command (can find this location using $ brew info postgres)
2. $ postgres -D /usr/local/var/postgres
I agree about all of the above solutions. I was running Postgres on a server, and the problem was that I was using a PORT number that was used by some other OLDER version of Postgres.
I only needed to change the port.
I had the same error psql: FATAL: could not open relation mapping file "global/pg_filenode.map": No such file or directory.
Thanks for note #2 above: 'Kill the processes for 9.0.3'
I previously configured and compiled PostgreSQL. I then decided to reconfigure, gmake, gmake install with different file paths. The newly compiled program wasn't finding 'pg_filenode.map' in the expected filepath. Killing the running postgres process, emptying pgsql/data, and doing initdb again allowed creation of a new database.
Make sure to turn off you antivirus.
In my case when i turn off the antivirus(kaspersky) it worked fine
Ref : https://github.com/PostgresApp/PostgresApp/issues/610

Resources