Nagios 4: Can’t open /etc/rc.d/init.d/functions - startup

I just upgrade my Nagios server to the latest version (4.0.1) on my Debian 7 system. When i start the daemon, i have the following error:
# /etc/init.d/nagios start
/etc/init.d/nagios: 20: .: Can't open /etc/rc.d/init.d/functions
The /etc/rc.d/init.d/functions did not exist on my Debian system (and also on my Ubuntu 12.04 workstation).
What can i do to solve this issue ?
===
Update:
Just hack the startup script with the following command line:
sudo apt-get install daemon
sudo sed -i 's/^\.\ \/etc\/rc.d\/init.d\/functions$/\.\ \/lib\/lsb\/init-functions/g' /etc/init.d/nagios
sudo sed -i 's/status\ /status_of_proc\ /g' /etc/init.d/nagios
sudo sed -i 's/daemon\ --user=\$user\ \$exec\ -ud\ \$config/daemon\ --user=\$user\ --\ \$exec\ -d\ \$config/g' /etc/init.d/nagios
sudo sed -i 's/\/var\/lock\/subsys\/\$prog/\/var\/lock\/\$prog/g' /etc/init.d/nagios
sudo service nagios start
Works fine on my Debian server.

You can simply write your own init script. Copy /etc/init.d/skeleton to /etc/init.d/nagios and fill in the values in that file:
DESC="Nagios"
NAME=nagios
DAEMON=/usr/local/nagios/bin/$NAME
DAEMON_ARGS="-d /usr/local/nagios/etc/nagios.cfg"
PIDFILE=/usr/local/nagios/var/$NAME.lock
I also commented these lines:
#[ -r /etc/default/$NAME ] && . /etc/default/$NAME
and
#start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
# || return 1
Don't forget to chmod +x /etc/init.d/nagios.
Have fun.

Little add for ubuntu 12.04 [desktop] :
'runuser' program doesn't exist for debianLike, but 'su' instead,
'service' program is not located in /sbin but in /usr/sbin
Then Nicolargo's mods + some of mine :
sudo apt-get install daemon
sudo sed -i 's/^\.\ \/etc\/rc.d\/init.d\/functions$/\.\ \/lib\/lsb\/init-functions/g' /etc/init.d/nagios
sudo sed -i 's/status\ /status_of_proc\ /g' /etc/init.d/nagios
sudo sed -i 's/daemon\ --user=\$user\ \$exec\ -ud\ \$config/daemon\ --user=\$user\ --\ \$exec\ -d\ \$config/g' /etc/init.d/nagios
sudo sed -i 's/\/var\/lock\/subsys\/\$prog/\/var\/lock\/\$prog/g' /etc/init.d/nagios
sudo sed -i 's/\/sbin\/service\ /\/usr\/sbin\/service\ /g' /etc/init.d/nagios
sudo sed -i 's/runuser/su/g' /etc/init.d/nagios
sudo service nagios start
I also removed the '-d 10' option applied on killproc in the stop sequence (around line 94) to avoid error message on 'service nagios stop' call.
$Stopping nagios: Illegal option -d
/sbin/start-stop-daemon: signal value must be numeric or name of signal (KILL, INT, ...)
Try '/sbin/start-stop-daemon --help' for more information.
'joy!

You've probably found a solution, but to answer the question:
One possible solution is installing Nagios 3.x from your package manager and then updating to 4 by compiling it from source. The new init script seems to be messed up, but the older one still works.
Source(german): http://www.monitoring-portal.org/wbb/index.php?page=Thread&threadID=29431&pageNo=2

Related

Docker syntax error end of file unexpected

Hello im new in docker and im having problem to build this:
MySQL install well
PhpMyadmin instal wel...
but in apache i have this error
error:
: not foundbin/pete_install.sh: 2:
/usr/local/bin/pete_install.sh: 110: Syntax error: end of file unexpected (expecting "then")
pete_install.sh
Line 1 to 10
#!/bin/bash
FILE=/var/www/html/.installed
if [ ! -f "$FILE" ]; then
echo "#######################################"
echo "Starting WordPress Pete installation..."
echo "#######################################"
rm -rf /var/www/html/Pete4
Linea 99 to 110
FILE=/var/www/.ssh/id_rsa.pub
if [ ! -f "$FILE" ]; then
ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa
fi
chmod 600 -R /var/www/.ssh/id_rsa
chmod 600 -R /var/www/.ssh/id_rsa.pub
apachectl -DFOREGROUND
#systemctl start
#/etc/init.d/apache2 reload
echo "Loading apache..."
full file https://pastebin.com/1f5a3pJY
Most of time, the error causes because you write your script on windows, the line break on windows is \r\n, while on linux it's \n.
You should install some tools to change format, e.g.:
$ sudo apt-get update
$ sudo apt-get install -y dos2unix
$ dos2unix /usr/local/bin/pete_install.sh

Host key verification failed in Jenkins

I have the following shell script, which is to install puppet agent in a remote machine. It worked perfectly if I run from my local ubuntu by cmd line as such: sh install_puppet_agent.sh
me#me:~$ cat install_puppet_agent.sh
#!/bin/bash
echo "Installing ..."
ssh -t me#puppet-agent << 'INSTALL_PUPPET_AGENT'
wget https://apt.puppetlabs.com/puppet6-release-bionic.deb
echo "mepassword" | sudo -S dpkg -i puppet6-release-bionic.deb
sudo apt-get update
sudo apt install -y puppet-agent
sudo touch /etc/puppetlabs/puppet/puppet.conf
sudo chmod 777 /etc/puppetlabs/puppet/puppet.conf
echo "[main]" | sudo tee -a /etc/puppetlabs/puppet/puppet.conf
echo "certname = puppetagent" | sudo tee -a /etc/puppetlabs/puppet/puppet.conf
echo "server = puppet" | sudo tee -a /etc/puppetlabs/puppet/puppet.conf
echo "environment = production" | sudo tee -a /etc/puppetlabs/puppet/puppet.conf
echo "runinterval = 5m" | sudo tee -a /etc/puppetlabs/puppet/puppet.conf
sudo /opt/puppetlabs/bin/puppet resource service puppet ensure=running enable=true
INSTALL_PUPPET_AGENT
echo "done"
me#me:~$
The I created a simple execute shell job in jenkins by copying the content of install_puppet_agent.sh to the Build -> Execute shell area, then I clicked save/build now, I got this:
Installing ...
Host key verification failed.
done
I have googled a while, unable to figure it out. I need to confess I am new to Jenkins & Puppet. Thanks
Assuming this is not a security problem that you are facing, you should be ok with updating the content of ~/.ssh/known_hosts file on the Jenkins node the job executes on.
Examples how to do that:
https://www.thegeekdiary.com/how-to-fix-the-error-host-key-verification-failed/
I got around this issue simply by configure the jenkins job as such:
/home/me/install_puppet_agent.sh

CentOS 6 Docker build using livemedia-creator is failing

I am trying to build an Docker base image using livemedia-creator on CentOS 7.5 with latest patches installed is failing. Below is the error I am getting.
# livemedia-creator --make-tar --no-virt --iso=CentOS-6.10-x86_64-netinstall.iso --ks=centos-6.ks --image-name=centos-root.tar.xz
Starting package installation process
The installation was stopped due to incomplete spokes detected while running in non-interactive cmdline mode. Since there cannot be any questions in cmdline mode, edit your kickstart file and retry installation.
The exact error message is:
CmdlineError: Missing package: firewalld.
The installer will now terminate.
The kickstart file which I am using is as below
url --url="http://mirrors.kernel.org/centos/6.9/os/x86_64/"
install
keyboard us
lang en_US.UTF-8
rootpw --lock --iscrypted locked
authconfig --enableshadow --passalgo=sha512
timezone --isUtc Etc/UTC
selinux --enforcing
#firewall --disabled
firewall --disable
network --bootproto=dhcp --device=eth0 --activate --onboot=on
reboot
bootloader --location=none
# Repositories to use
repo --name="CentOS" --baseurl=http://mirror.centos.org/centos/6.9/os/x86_64/ --cost=100
repo --name="Updates" --baseurl=http://mirror.centos.org/centos/6.9/updates/x86_64/ --cost=100
# Disk setup
zerombr
clearpart --all
part / --size 3000 --fstype ext4
%packages --excludedocs --nobase --nocore
vim-minimal
yum
bash
bind-utils
centos-release
shadow-utils
findutils
iputils
iproute
grub
-*-firmware
passwd
rootfiles
util-linux-ng
yum-plugin-ovl
%end
%post --log=/tmp/anaconda-post.log
# Post configure tasks for Docker
# remove stuff we don't need that anaconda insists on
# kernel needs to be removed by rpm, because of grubby
rpm -e kernel
yum -y remove dhclient dhcp-libs dracut grubby kmod grub2 centos-logos \
hwdata os-prober gettext* bind-license freetype kmod-libs dracut
yum -y remove dbus-glib dbus-python ebtables \
gobject-introspection libselinux-python pygobject3-base \
python-decorator python-slip python-slip-dbus kpartx kernel-firmware \
device-mapper* e2fsprogs-libs sysvinit-tools kbd-misc libss upstart
#clean up unused directories
rm -rf /boot
rm -rf /etc/firewalld
# Randomize root's password and lock
dd if=/dev/urandom count=50 | md5sum | passwd --stdin root
passwd -l root
#LANG="en_US"
#echo "%_install_lang $LANG" > /etc/rpm/macros.image-language-conf
awk '(NF==0&&!done){print "override_install_langs='$LANG'\ntsflags=nodocs";done=1}{print}' \
< /etc/yum.conf > /etc/yum.conf.new
mv /etc/yum.conf.new /etc/yum.conf
echo 'container' > /etc/yum/vars/infra
rm -f /usr/lib/locale/locale-archive
#Setup locale properly
localedef -v -c -i en_US -f UTF-8 en_US.UTF-8
#disable services
for serv in `/sbin/chkconfig|cut -f1`; do /sbin/chkconfig "$serv" off; done;
mv /etc/rc1.d/S26udev-post /etc/rc1.d/K26udev-post
rm -rf /var/cache/yum/*
rm -f /tmp/ks-script*
rm -rf /etc/sysconfig/network-scripts/ifcfg-*
#Generate installtime file record
/bin/date +%Y%m%d_%H%M > /etc/BUILDTIME
%end
I am not able to figure out from where firewalld is being picked. Any thought how to fix this issue.

Vagrant - Rails Not Installed

I recently had to destroy and recreate my Vagrant instance. Now I can't run any rails command as it says Rails is not installed. When I did
Vagrant Up
I got the following error
default: /tmp/vagrant-shell: line 1: /home/vagrant/.rvm/scripts/rvm: No such file or directory
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!
My Provision.sh file contains the following:
echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main " | sudo tee -a /etc/apt/sources.list.d/pgdg.list
sudo wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get remove postgresql-client-9.1 postgresql-client-common postgresql-client postgresql-common -y
sudo apt-get install postgresql-9.3 postgresql-client-9.3 libpq-dev curl git build-essential libxslt-dev libxml2-dev -y
wget -qO- https://toolbelt.heroku.com/install-ubuntu.sh | sh
curl -sSL https://get.rvm.io | bash -s stable --ruby
cat << EOF | sudo tee -a /home/vagrant/.bashrc
cd /vagrant
EOF
echo '# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust' | sudo tee /etc/postgresql/9.3/main/pg_hba.conf
echo 'machine api.heroku.com
login *****
password ****
machine code.heroku.com
login *****
password *****
' | tee /home/vagrant/.netrc
echo 'ssh-rsa ***** vagrant#precise32
' | tee /home/vagrant/.ssh/id_*****.pub
chmod 0600 /home/vagrant/.netrc
sudo -u postgres psql -c "create user ***** createdb createuser password '*****';"
sudo /etc/init.d/postgresql restart
I have seen some answers (not specific to Vagrant) suggesting that I must have installed rvm using sudo or as root and need to remove it and then get rvm again. I have tried to do that butI'm not sure how it applies to a vagrant box and at any rate I must have done it wrong as it hasn't worked.
Is there something I need to correct/add to my provision.sh file or to my Vagrantfile?
Vagrant runs the provisioning file as root, so you would have indeed installed rvm as root unless you specified otherwise*. This was quite confusing for me as well (also a newbie), I would install things during provisioning and they would "disappear". In fact, they were all being installed / set as root.
*Or, you manually installed rvm when ssh'd into the machine, which I'll touch on more below.
You can switch your user using su -c "source /home/vagrant/myapp/vagrant/user-config.sh" vagrant
What goes in the "" is any command you want to execute. In this case, we're switching to a separate shell file user-config.sh that contains all the commands that should not be run as root, such as installing RVM.
I also sense somewhat of a conceptual misunderstanding. Each time you do vagrant destroy your entire virtual machine is destroyed, hard drives and all. The next time you do vagrant up, everything is rebuilt from scratch. If you had ssh'd in and installed things, they'll no longer be there.
This means that all of your install and config goes into the provisioning file, and you shouldn't be installing things manually after the fact. You should be able to vagrant destroy any time you want.
Take a read through https://coderwall.com/p/uzkokw/configure-the-vagrant-login-user-during-provisioning-using-the-shell-provider once more, I'm hoping it makes more sense this time around.
May be this link helps you to install rvm using Vagrant.
RVM_Vagrant

implement yum functions from kickstar (ks.cfg) file for rh/centos install

I've got the following kickstart file (ks.cfg) for a raw centos installation. I'm trying to implement a "%post" process that will allow the installation to be modified, using you functions (install, groupremove, etc). The whole ks file is at the end of the issue.
I'm not sure why, but the following kickstart is not running the yum install mysql, yum install mysql-server in the post process.
After the install, entering "service mysql start" results in the err msg saying mysql is not found. I am, however, able to run the yum install cmds after installation, and mysql gets installed.
I know I'm missing something subtle, but not sure what it is.
%post
yum install mysql -y <<<<<<<<<<<<<<NOT WORKING!!!!!
yum install mysql-server -y <<<<<<<<<<<<<<NOT WORKING!!!!!
%end
Thanks
ks.cfg
[root#localhost ~]# cat /root/anaconda-ks.cfg
# Kickstart file automatically generated by anaconda.
#version=DEVEL
install
cdrom
lang en_US.UTF-8
keyboard us
network --onboot yes --device eth0 --bootproto dhcp
rootpw --iscrypted $1$JCZKA/by$sVSHffsPr3ZDUp6m7c5gt1
# Reboot after installation
reboot
firewall --service=ssh
authconfig --useshadow --enablemd5
selinux --enforcing
timezone --utc America/Los_Angeles
bootloader --location=mbr --driveorder=sda --append=" rhgb crashkernel=auto quiet"
# The following is the partition information you requested
# Note that any partitions you deleted are not expressed
# here so unless you clear all partitions first, this is
# not guaranteed to work
#clearpart --all --initlabel
#part /boot --fstype=ext4 --size=200
#part / --fstype=ext4 --grow --size=3000
#part swap --grow --maxsize=4064 --size=2032
repo --name="CentOS" --baseurl=cdrom:sr1 --cost=100
%packages
#Base
#Core
#Desktop
#Fonts
#General Purpose Desktop
#Internet Browser
#X Window System
binutils
gcc
kernel-devel
make
patch
python
%end
%post
cp /boot/grub/menu.lst /boot/grub/grub.conf.bak
sed -i 's/ rhgb//' /boot/grub/grub.conf
cp /etc/rc.d/rc.local /etc/rc.local.backup
cat >>/etc/rc.d/rc.local <<EOF
echo
echo "Installing VMware Tools, please wait..."
if [ -x /usr/sbin/getenforce ]; then oldenforce=\$(/usr/sbin/getenforce); /usr/sbin/setenforce permissive || true; fi
mkdir -p /tmp/vmware-toolsmnt0
for i in hda sr0 scd0; do mount -t iso9660 /dev/\$i /tmp/vmware-toolsmnt0 && break; done
cp -a /tmp/vmware-toolsmnt0 /opt/vmware-tools-installer
chmod 755 /opt/vmware-tools-installer
cd /opt/vmware-tools-installer
mv upgra32 vmware-tools-upgrader-32
mv upgra64 vmware-tools-upgrader-64
mv upgrade.sh run_upgrader.sh
chmod +x /opt/vmware-tools-installer/*upgr*
umount /tmp/vmware-toolsmnt0
rmdir /tmp/vmware-toolsmnt0
if [ -x /usr/bin/rhgb-client ]; then /usr/bin/rhgb-client --quit; fi
cd /opt/vmware-tools-installer
./run_upgrader.sh
mv /etc/rc.local.backup /etc/rc.d/rc.local
rm -rf /opt/vmware-tools-installer
sed -i 's/3:initdefault/5:initdefault/' /etc/inittab
mv /boot/grub/grub.conf.bak /boot/grub/grub.conf
if [ -x /usr/sbin/getenforce ]; then /usr/sbin/setenforce \$oldenforce || true; fi
if [ -x /bin/systemd ]; then systemctl restart prefdm.service; else telinit 5; fi
EOF
/usr/sbin/adduser test
/usr/sbin/usermod -p '$1$QcRcMih7$VG3upQam.lF4BFzVtaYU5.' test
/usr/sbin/adduser test1
/usr/sbin/usermod -p '$1$LMyHixbC$4.aATdKUb2eH8cCXtgFNM0' test1
/usr/bin/chfn -f 'ruser' root
%end
%post
yum install mysql -y <<<<<<<<<<<<<<NOT WORKING!!!!!
yum install mysql-server -y <<<<<<<<<<<<<<NOT WORKING!!!!!
%end
It was caused by line-ending when I faced same problem as you. Try to check line-ending of ks.cfg. It should be LF not CR+LF or CR.
It will be help you if you;
Try system-config-kickstart tool.
Find generated /root/anaconda-ks.cfg though there may be no %post section.
Cheers.
You should just put mysql and mysql-server into the %packages section, no need to do this in %post.

Resources