nginx mac invalid pid? - macos

I just installed nginx. I am trying to stop it now using the pid file in the logs folder but it's telling me that it's illegal process id: cat /usr/local/logs/nginx.pid
The command that i run is: sudo kill 'cat /usr/local/logs/nginx.pid'
The pid is 15597 but in Activity Monitor i don't see a process with that ID either. When I type: ps ax | grep nginx i get:
15597 ?? Ss 0:00.00 nginx: master process nginx
15883 ?? S 0:00.00 nginx: worker process
15898 s000 R+ 0:00.00 grep nginx
Thanks

Try to kill the process directly:
kill 15597
or you can try the nginx start script in usr/local/etc/nginx:
nginx -s quit
You will probably have to adjust the path according to your installation.

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)

Script done, file is typescript in bash while creating a service

I have a script file as below.
#!/bin/bash
set -x
set -e
#VBoxManage startvm "cuckoo-window" --type gui
python ~/Downloads/cuckoo-modified-master/utils/api.py --host 0.0.0.0 --port 8090
#cd ~/Downloads/cuckoo-modified-master/web/
# python manage.py runserver 0.0.0.0:8008
# python ~/Downloads/cuckoo-modified-master/cuckoo.py
My service script /etc/init/miscservices.conf
start on runlevel
script
cd ~/Downloads/cuckoo-modified-master
./miscservices.sh
end script
I have also created a symlink in /etc/init.d/miscservices and added in startup
sudo update-rc.d miscservices defaults
sudo service miscservices start
miscservices stop/waiting
No script started. When I start as below, them move to root mode but still no service start. But when I exit it start 2 instances of the service.Please explain this behavior.
sudo /etc/init.d/miscservices start
start: Unknown job: on
Script started, file is typescript
root#abc:~# sudo netstat -ntlp | grep 8090
root#abc:~# ps -aux | grep misc
root 2929 0.0 0.0 81976 2260 pts/6 S+ 13:42 0:00 sudo /etc/init.d/miscservices start
root 2930 0.0 0.0 4440 652 pts/6 S+ 13:42 0:00 sh /etc/init.d/miscservices start
root 2962 0.0 0.0 16192 936 pts/15 S+ 13:43 0:00 grep --color=auto misc
root#abc:~#
root#abc:~#
root#abc:~# exit
exit
Script done, file is typescript
+ set -e
+ python /home/aserg/Downloads/cuckoo-modified-master/utils/api.py --host 0.0.0.0 --port 8090
Bottle v0.12.0 server starting up (using WSGIRefServer())...
Listening on http://0.0.0.0:8090/
Hit Ctrl-C to quit.
I think the problem may be in ~/Downloads/cuckoo-modified-master/miscservices.sh script (and btw use ~ in upstart script not best idea because it will probably execute as root and there can be some problems with determitate where is ~). By default upstart doesn't spawn processes. That mean if you have your configuration like that:
start on runlevel
script
cd ~/Downloads/cuckoo-modified-master
./miscservices.sh
end script
upstart will only start your process once and then do nothing. And if you start it once and there was some error in script it just stoped with no information to you. You can check log file. By default it must be in /etc/log/upstart/miscservices.log (for Ubuntu 14.04 LTS). If no you can check where is default upstart logs in your OS or write it manually just by echo some informtaion in certain place. For example:
env logf="/home/someuser/miscservices.log"
script
echo "Script it starting..." >> $logf
/home/someuser/Downloads/cuckoo-modified-master/miscservices.conf >> $logf
echo "Script is ended." >> $logf
end scipt
And if you want to respawn script processes you may add to the beggining of the script:
respawn
respawn limit unlimited
or just make unlimited loop in script file.
ps. You can modify your upstart script /etc/init/miscservices.conf by more clear code. From start on runlevel to:
start on filesystem
stop on shutdown
This mean that script will start after filesystem starts and will shutdown on shutdown.
pps. You dont need symlink in /etc/init.d/miscservices. If you use upstart then just use it! You dont need anything else. Just put your end scipt in /etc/init and it will start automatically. It can be something like that:
start on filesystem
stop on shutdown
env logf="/home/someuser/miscservices.log"
script
echo "Script it starting..." >> $logf
/home/someuser/Downloads/cuckoo-modified-master/miscservices.conf >> $logf
echo "Script is ended." >> $logf
end scipt
Hope i can help!

Restarting the mosquito broker

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.

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.

How to use sudo in build script for gitlab ci?

When I would like to do something that requiers sudo privelegies, the build process stucks and when ps aux for that command, it hanging in the list but doing nothing.
E.g.:
in the buildscript:
# stop nginx
echo "INFO: stopping nginx. pid [$(cat /opt/nginx/logs/nginx.pid)]"
sudo kill $(cat /opt/nginx/logs/nginx.pid)
in the gitlab ci output console:
INFO: stopping nginx. pid [2741]
kill $(cat /opt/nginx/logs/nginx.pid) # with a spinning wheel
in the bash:
> ps aux | grep nginx
root 6698 0.0 0.1 37628 1264 ? Ss 19:25 0:00 nginx: master process /opt/nginx/sbin/nginx
nobody 6700 0.3 0.3 41776 3832 ? S 19:25 0:00 nginx: worker process
kai 7015 0.0 0.0 4176 580 pts/0 S+ 19:27 0:00 sh -c sudo kill $(cat /opt/nginx/logs/nginx.pid)
kai 7039 0.0 0.0 7828 844 pts/2 S+ 19:27 0:00 grep nginx
So:
not the sudo kill $(cat /opt/nginx/logs/nginx.pid) is going to execute, but sh -c sudo kill $(cat /opt/nginx/logs/nginx.pid)
it is hanging up, without response (sounds for me like it asks for a password interactively)
There are a couple of ways to resolve this.
Grant sudo permissions
You can grant sudo permissions to the gitlab-runner user as this is who is executing the build script.
$ sudo usermod -a -G sudo gitlab-runner
You now have to remove the password restriction for sudo for the gitlab-runner user.
Start the sudo editor with
$ sudo visudo
Now add the following to the bottom of the file
gitlab-runner ALL=(ALL) NOPASSWD: ALL
Do not do this for gitlab runners that can be executed by untrusted users.
SSH Runner
You can configure the gitlab-ci-runner to connect to a remote host using SSH. You configure this to use a user remotely that has sudo permissions, and perform the build using that user. The remote host can be the same machine that the gitlab runner is executing on, or it can be another host.
This build user account will still need to have sudo and passwordless permissions. Follow the instruction below, except replace gitlab-runner with the build user.
It worked for me as written by Reactgular.
But one little clarification. You must include a % sign before
gitlab-runner ALL = (ALL) NOPASSWD: ALL.
I could not understand for a long time why it doesn’t help me. Then I put the percentage icon and it worked.

Resources