Tiny Core Linux

Tiny Core Extensions => TCE Q&A Forum => Topic started by: orneh24 on August 21, 2025, 08:02:59 PM

Title: lldpd not available for 16.x
Post by: orneh24 on August 21, 2025, 08:02:59 PM
Hi,
I was hoping to add lldpd to a TCL install, but could only find it available for 14.x:
http://tinycorelinux.net/14.x/x86_64/tcz/src/lldpd/

Will the lldpd app be made available for 16.x builds? Or is it possible to simply install the 14.x version, on top of a 16.x build?
Title: Re: lldpd not available for 16.x
Post by: Rich on August 21, 2025, 08:30:16 PM
Hi orneh24
Welcome to the forum.

Try downloading:
http://tinycorelinux.net/14.x/x86_64/tcz/lldpd.tcz
http://tinycorelinux.net/14.x/x86_64/tcz/lldpd.tcz.dep

Then:
Code: [Select]
tce-load -w libcap readline libxml2
tce-load -i lldpd
and see if it works.

If not, download the files at:
http://tinycorelinux.net/14.x/x86_64/tcz/src/lldpd/
into their own directory. Then:
Code: [Select]
chmod 775 lldpd.build
./lldpd.build
The first command makes  lldpd.build  executable.
The second command runs  lldpd.build.
When  lldpd.build  completes, you should have a complete set of
files for the  lldpd  extension.
Title: Re: lldpd not available for 16.x
Post by: orneh24 on August 21, 2025, 09:01:33 PM
Thanks Rich  :)
Will give it a go right away.
Quick follow-up; would the same process be applicable for the net-snmp package from 15.x?
http://tinycorelinux.net/15.x/x86_64/tcz/src/net-snmp/
Title: Re: lldpd not available for 16.x
Post by: Rich on August 21, 2025, 09:15:43 PM
Hi orneh24
net-snmp  is available in TC16 x86_64:
http://tinycorelinux.net/15.x/x86_64/tcz/net-snmp.tcz.info
Title: Re: lldpd not available for 16.x
Post by: orneh24 on August 21, 2025, 09:53:28 PM
Then:
Code: [Select]
tce-load -w libcap readline libxml2
tce-load -i lldpd
and see if it works.
Looks like it's almost there;

Code: [Select]
tc@box:/tmp$ tce-load -w libcap readline libxml2
libcap.tcz.dep OK
Downloading: attr.tcz
readline.tcz.dep OK
Connecting to repo.tinycorelinux.net (128.127.66.77:80)
saving to 'attr.tcz'
attr.tcz             100% |*******************************************************************************************************************************************************************************************| 24576  0:00:00 ETA
'attr.tcz' saved
attr.tcz: OK
Downloading: libcap.tcz
libxml2.tcz.dep OK
Connecting to repo.tinycorelinux.net (128.127.66.77:80)
saving to 'libcap.tcz'
libcap.tcz           100% |*******************************************************************************************************************************************************************************************| 24576  0:00:00 ETA
'libcap.tcz' saved
libcap.tcz: OK
Downloading: readline.tcz
Connecting to repo.tinycorelinux.net (128.127.66.77:80)
saving to 'readline.tcz'
readline.tcz         100% |*******************************************************************************************************************************************************************************************|  144k  0:00:00 ETA
'readline.tcz' saved
readline.tcz: OK
Downloading: libxml2.tcz
Connecting to repo.tinycorelinux.net (128.127.66.77:80)
saving to 'libxml2.tcz'
libxml2.tcz          100% |*******************************************************************************************************************************************************************************************|  568k  0:00:00 ETA
'libxml2.tcz' saved
libxml2.tcz: OK

Code: [Select]
tc@box:/tmp$ tce-load -i lldpd
libxml2.tcz not found!

On a whim, I tried the following:
Code: [Select]
tc@box:/tmp$ tce-load -w libcap readline libxml2
libcap is already downloaded.
readline is already downloaded.
libxml2 is already downloaded.
tc@box:/tmp$ tce-load -i lldpd
libxml2.tcz not found!
tc@box:/tmp$ tce-load -wi libcap readline libxml2
libcap is already downloaded.
readline is already downloaded.
libxml2 is already downloaded.
attr.tcz: OK
libcap.tcz: OK
readline.tcz: OK
libxml2.tcz: OK
tc@box:/tmp$ tce-load -i lldpd
lldpd.tcz: OK

tc@box:/usr/bin$ lldpcli show neighbors
/usr/local/sbin/lldpcli: line 1: can't create *@@€^@8: Permission denied
/usr/local/sbin/lldpcli: line 1: A1+V]F$
                                        : not found
/usr/local/sbin/lldpcli: line 1: syntax error: unexpected word (expecting ")")

tc@box:/usr/bin$ sudo lldpcli show neighbors
/usr/local/sbin/lldpcli: line 1: can't open 8: no such file
/usr/local/sbin/lldpcli: line 1: A1+V]F$
                                        : not found
/usr/local/sbin/lldpcli: line 1: syntax error: unexpected word (expecting ")")

Will take a look at the build method, to see if that works (although let me know if you spot anything incorrect in what I did above)
Title: Re: lldpd not available for 16.x
Post by: Rich on August 21, 2025, 11:35:09 PM
Hi orneh24
I've never used lldpd, but it appears like you may need to run it as root:
Code: [Select]
sudo su
lldpcli show neighbors
Title: Re: lldpd not available for 16.x
Post by: orneh24 on August 22, 2025, 01:33:41 AM
Running as root returned the same errors - so I tried the build method instead (should note, I've never compiled anything myself before, so this is somewhat uncharted territory for me)

The build script seems to have completed successfully:
Code: [Select]
tc@lldpdboxtest:~/ll$ ls -l
total 8548
drwxr-sr-x 2 tc staff     480 Aug 22 05:18 i686/
drwxr-sr-x 9 tc staff     720 Aug 22 05:18 lldpd-1.0.18/
-rw-r--r-- 1 tc staff 1988753 Aug 22 05:17 lldpd-1.0.18.tar.gz
-rw-rw-r-- 1 tc staff  688128 Aug 22 05:18 lldpd-dev.tcz
-rw-r--r-- 1 tc staff      10 Aug 22 05:18 lldpd-dev.tcz.dep
-rw-r--r-- 1 tc staff     882 Aug 22 05:18 lldpd-dev.tcz.info
-rw-r--r-- 1 tc staff     125 Aug 22 05:18 lldpd-dev.tcz.list
-rw-r--r-- 1 tc staff      48 Aug 22 05:18 lldpd-dev.tcz.md5.txt
-rw-r--r-- 1 tc staff    2211 Aug 22 05:18 lldpd-dev.tcz.zsync
-rw-rw-r-- 1 tc staff   20480 Aug 22 05:18 lldpd-doc.tcz
-rw-r--r-- 1 tc staff     881 Aug 22 05:18 lldpd-doc.tcz.info
-rw-r--r-- 1 tc staff     106 Aug 22 05:18 lldpd-doc.tcz.list
-rw-r--r-- 1 tc staff      48 Aug 22 05:18 lldpd-doc.tcz.md5.txt
-rw-r--r-- 1 tc staff     244 Aug 22 05:18 lldpd-doc.tcz.zsync
-rw-r--r-- 1 tc staff 2887974 Aug 22 05:18 lldpd-i686.tar.gz.bfe
-rw-r--r-- 1 tc staff 1991705 Aug 22 05:18 lldpd-source-v1.0.18.tar.gz
-rwxrwxr-x 1 tc staff    9301 Aug 22 05:17 lldpd.build
-rw-r--r-- 1 tc staff  893303 Aug 22 05:18 lldpd.tar.gz
-rw-rw-r-- 1 tc staff  188416 Aug 22 05:18 lldpd.tcz
-rw-r--r-- 1 tc staff      36 Aug 22 05:18 lldpd.tcz.dep
-rw-r--r-- 1 tc staff     878 Aug 22 05:18 lldpd.tcz.info
-rw-r--r-- 1 tc staff     480 Aug 22 05:18 lldpd.tcz.list
-rw-r--r-- 1 tc staff      44 Aug 22 05:18 lldpd.tcz.md5.txt
-rw-r--r-- 1 tc staff     739 Aug 22 05:18 lldpd.tcz.zsync
drwxr-xr-x 3 tc staff      60 Aug 22 05:18 lldpd_all/
drwxr-sr-x 3 tc staff      60 Aug 22 05:18 lldpd_dev/
drwxr-sr-x 3 tc staff      60 Aug 22 05:18 lldpd_doc/
drwxr-sr-x 3 tc staff      60 Aug 22 05:18 lldpd_ext/
-rw-r--r-- 1 tc staff    8435 Aug 22 05:18 submitqc.txt

But seems to be a problem with either creating the socket or a _lldpd user;
Code: [Select]
tc@lldpdboxtest:~/ll$ lldpcli
2025-08-22T05:26:53 [WARN/control] unable to connect to socket /var/run/lldpd.socket: No such file or directory

tc@lldpdboxtest:~/ll$ sudo lldpd -dddd
2025-08-22T05:31:13 [ DBG/main] lldpd 1.0.18 starting...
2025-08-22T05:31:13 [CRIT/main] no _lldpd user for privilege separation, please create it

Will try to dig a bit further and see if I can make it work
Title: Re: lldpd not available for 16.x
Post by: Rich on August 22, 2025, 02:40:06 PM
Hi orneh24
It looks like you need to create an _lldpd  user and group.
Try this:
Code: [Select]
sudo su
addgroup _lldpd
adduser -H -S -s /bin/sh -G _lldpd -D _lldpd
echo -e "_lldpd\tALL=NOPASSWD: ALL" >> /etc/sudoers
exit

Then see if this command behaves any better:
Code: [Select]
sudo lldpd -dddd
If it does, then:
Code: [Select]
echo "etc/group" >> /opt/.filetool.lst
echo "etc/gshadow" >> /opt/.filetool.lst
echo "etc/passwd" >> /opt/.filetool.lst
echo "etc/shadow" >> /opt/.filetool.lst
echo "etc/sudoers" >> /opt/.filetool.lst
filetool.sh -b
Title: Re: lldpd not available for 16.x
Post by: orneh24 on August 22, 2025, 03:36:21 PM
Thanks Rich, appreciate the help.
Will try out the commands later tonight.
Title: Re: lldpd not available for 16.x
Post by: orneh24 on August 22, 2025, 06:28:41 PM
Allright, so after adding the group and user, lldpd successfully starts  :)

Code: [Select]
tc@nginxsnmptcl:/home$ sudo lldpd -dddd
2025-08-22T22:04:27 [ DBG/main] lldpd 1.0.18 starting...
2025-08-22T22:04:27 [ DBG/main] creating control socket
2025-08-22T22:04:27 [ DBG/control] create control socket /var/run/lldpd.socket
2025-08-22T22:04:27 [ DBG/control] listen to control socket /var/run/lldpd.socket
2025-08-22T22:04:27 [ DBG/main] invoking lldpcli for default configuration locations
2025-08-22T22:04:27 [ DBG/main] invoke /usr/local/sbin/lldpcli -sddd
2025-08-22T22:04:27 [ DBG/main] get OS/LSB release information
2025-08-22T22:04:27 [ DBG/localchassis] grab OS release
2025-08-22T22:04:27 [ DBG/main] initialize privilege separation
2025-08-22T22:04:27 [ DBG/privsep] getting CAP_NET_RAW/ADMIN and CAP_DAC_OVERRIDE privilege
2025-08-22T22:04:27 [ DBG/privsep] dropping privileges
2025-08-22T22:04:27 [ DBG/privsep] dropping extra capabilities
2025-08-22T22:04:27 [ DBG/main] invoke /usr/local/sbin/lldpcli -sddd
2025-08-22T22:04:27 [ DBG/lldpctl] cannot find configuration file/directory /usr/local/etc/lldpd.conf
2025-08-22T22:04:27 [ DBG/privsep] dropping privileges
2025-08-22T22:04:27 [ DBG/privsep] received command 0
2025-08-22T22:04:27 [ DBG/privsep] monitor ready
... rest of debug output omitted

Socket is succesfully created:
Code: [Select]
tc@nginxsnmptcl:/$ ll /var/run
total 20
drwxr-xr-x    2 root     root            40 Aug 22 22:02 lldpd/
-rw-r--r--    1 root     root             5 Aug 22 22:07 lldpd.pid
srwxrwx---    1 _lldpd   _lldpd           0 Aug 22 22:07 lldpd.socket
-rwxrwx---    1 _lldpd   _lldpd           0 Aug 22 22:07 lldpd.socket.lock
-rw-r--r--    1 root     root             5 Aug 22 21:59 nginx.pid
-rw-r--r--    1 root     root             5 Aug 22 21:59 sshd.pid
-rw-rw-r--    1 root     staff          768 Aug 22 21:59 utmp
dr-xr-xr-x    3 root     root          4096 Aug 22 22:11 vmblock-fuse/
-rw-r--r--    1 root     root             5 Aug 22 21:59 vmtoolsd.pid
tc@nginxsnmptcl:/$

And lldpcli/lldpctl output is correct:
Code: [Select]
tc@nginxsnmptcl:/home$ sudo lldpcli show neighbors
-------------------------------------------------------------------------------
LLDP neighbors:
-------------------------------------------------------------------------------
Interface:    eth0, via: LLDP, RID: 1, Time: 0 day, 00:01:35
  Chassis:     
    ChassisID:    mac 1c:e8:5d:d5:39:00
    SysName:      C3560G
    SysDescr:     Cisco IOS Software, C3560C Software (C3560c405ex-UNIVERSALK9-M), Version 15.2(2)E4, RELEASE SOFTWARE (fc2)
                  Technical Support: http://www.cisco.com/techsupport
                  Copyright (c) 1986-2016 by Cisco Systems, Inc.
                  Compiled Sat 13-Feb-16 02:28 by prod_rel_team
    MgmtIP:       192.168.2.2
    Capability:   Bridge, on
    Capability:   Router, on
  Port:       
    PortID:       ifname Gi0/7
    PortDescr:    ESXi01_vmnic1_dvswitch
    TTL:          120

I believe the only thing missing now, is the init.d/lldpd and making the lldpd package installation persistent (or rather, what would be the correct way, of making it persistent after building it locally)?
Title: Re: lldpd not available for 16.x
Post by: Rich on August 22, 2025, 08:16:32 PM
Hi orneh24
... I believe the only thing missing now, is the init.d/lldpd ...
I'll look into that.

Quote
... and making the lldpd package installation persistent (or rather, what would be the correct way, of making it persistent after building it locally)?
I'm assuming you used the build script, so copy lldpd.tcz, lldpd.tcz.dep, and lldpd.tcz.md5.txt
to your  tce/optional directory.

Make sure  lldpd.tcz  is listed in  onboot.lst.

If you followed these instructions:
...
Code: [Select]
echo "etc/group" >> /opt/.filetool.lst
echo "etc/gshadow" >> /opt/.filetool.lst
echo "etc/passwd" >> /opt/.filetool.lst
echo "etc/shadow" >> /opt/.filetool.lst
echo "etc/sudoers" >> /opt/.filetool.lst
filetool.sh -b
then the added  _lldpd  user and group will survive a reboot.
Title: Re: lldpd not available for 16.x
Post by: orneh24 on August 22, 2025, 08:17:03 PM
ref. persistency - copied lldpd.tcz, .tcz.dep and .tcz.md5.txt to /mnt/sda1/tce/optional and added lldpd to onboot.lst.

Currently trying to understand how TCL handles init.d - are the files in /usr/local/etc/init.d/ just symlinks to /tmp/tcloop/ ? I tried taking a look at the Wiki, but couldn't quite find the info.
Code: [Select]
tc@nginxsnmptcl:/usr/local/etc/init.d$ ll
total 0
lrwxrwxrwx    1 root     root            42 Aug 23 00:09 fuse -> /tmp/tcloop/fuse/usr/local/etc/init.d/fuse
lrwxrwxrwx    1 root     root            44 Aug 23 00:09 nginx -> /tmp/tcloop/nginx/usr/local/etc/init.d/nginx
lrwxrwxrwx    1 root     root            60 Aug 23 00:09 open-vm-tools -> /tmp/tcloop/open-vm-tools/usr/local/etc/init.d/open-vm-tools
lrwxrwxrwx    1 root     root            48 Aug 23 00:09 openssh -> /tmp/tcloop/openssh/usr/local/etc/init.d/openssh

Edit; sorry Rich, didn't see your reply before posting this one. Yes, I did indeed also add the group, gshadow, passwd, shadow and sudoers file to .filetool.lst.
Title: Re: lldpd not available for 16.x
Post by: Rich on August 22, 2025, 08:22:35 PM
Hi orneh24
... are the files in /usr/local/etc/init.d/ just symlinks to /tmp/tcloop/ ? ...
Yes, they are.

Extensions are read-only file systems that get mounted under /tmp/tcloop/.
Their contents then get symlinked into the system directories.
Title: Re: lldpd not available for 16.x
Post by: patrikg on August 23, 2025, 02:51:47 AM
Hi @orneh24.
If you want, you can also make a script that will add the user and group when the user installing the extension.
Se this wiki page how to do it.
https://wiki.tinycorelinux.net/doku.php?id=wiki:creating_extensions#adding_custom_startup_scripts (https://wiki.tinycorelinux.net/doku.php?id=wiki:creating_extensions#adding_custom_startup_scripts)
Title: Re: lldpd not available for 16.x
Post by: Rich on August 23, 2025, 09:07:56 PM
Hi orneh24
Sorry for the delay. I started by trying to modify an existing
init.d/lldpd  script from another distro. It proved to be too
complicated, so I adapted our  init.d/dbus  script:
Code: [Select]
#!/bin/sh

NAME=lldpd
DAEMON="/usr/local/sbin/$NAME"
DAEMON_ARGS=""


start()
{
start-stop-daemon -S -x "$DAEMON" -- "$DAEMON_ARGS"
}

stop()
{
start-stop-daemon -K -x "$DAEMON" 2>/dev/null
rm -rf /var/run/"$NAME"*
}



status()
{
if [ -e /var/run/"$NAME".pid ]; then
echo -e "\n$NAME is running.\n"
exit 0
else
echo -e "\n$NAME is not running.\n"
exit 1
fi
}

case $1 in
start) start
;;
stop) stop
;;
status) status
;;
restart) stop; start
;;
*) echo -e "\n$0 [start|stop|restart|status]\n"
;;
esac

Under  stop() , I've included a command to remove all lldpd
files and directories in case lldpd does not clean up after
itself when stopped:
Code: [Select]
drwxr-xr-x    2 root     root            40 Aug 22 22:02 lldpd/
-rw-r--r--    1 root     root             5 Aug 22 22:07 lldpd.pid
srwxrwx---    1 _lldpd   _lldpd           0 Aug 22 22:07 lldpd.socket
-rwxrwx---    1 _lldpd   _lldpd           0 Aug 22 22:07 lldpd.socket.lock

Attachment deleted. See next post.
Title: Re: lldpd not available for 16.x
Post by: Rich on August 24, 2025, 10:37:24 AM
Hi orneh24
I realized there were a couple of items that needed fixing, so
I made some updates:
Code: [Select]
#!/bin/sh

if [ `/usr/bin/id -u` -ne 0 ]
then
echo -e "\nNeed to run as root or using sudo.\n"
exit 1
fi

NAME="lldpd"
DAEMON="/usr/local/sbin/$NAME"
DAEMON_ARGS=""

RUNNING=$(ps aux | grep -v "grep" | grep "$DAEMON")

start()
{
[ -n "$RUNNING" ] && echo -e "\n$NAME is already running.\n" && exit 2
start-stop-daemon -S -x "$DAEMON" -- "$DAEMON_ARGS"
}

stop()
{
start-stop-daemon -K -x "$DAEMON" 2>/dev/null
rm -rf /var/run/"$NAME"*
}



status()
{
[ -n "$RUNNING" ] && echo -e "\n$NAME is running.\n" && exit 0
echo -e "\n$NAME is not running.\n"
exit 1
}

case $1 in
start) start
;;
stop) stop
;;
status) status
;;
restart) stop; start
;;
*) echo -e "\n$0 [start|stop|restart|status]\n"
;;
esac

Added test for root.
Added test for running in start().
Simplified status().

I've attached the updated version here.

Download the attached file and make it executable:
Code: [Select]
chmod 774 lldpd
Copy it to  /usr/local/etc/init.d/  and test it out.
Like most (all?) init.d scripts, run it using sudo.
Please test it and let me know if there are any problems or changes required.
Title: Re: lldpd not available for 16.x
Post by: orneh24 on August 24, 2025, 11:07:03 PM
Awesome, thanks again Rich  :D
Start/Stop/Status all works flawlessly, although Restart seems to fail;

Code: [Select]
tc@box:~$ sudo /usr/local/etc/init.d/lldpd start
tc@box:~$ sudo /usr/local/etc/init.d/lldpd status

lldpd is running.

tc@box:~$
tc@box:~$ sudo /usr/local/etc/init.d/lldpd restart
stopped /usr/local/sbin/lldpd (pid 1901 1899)

lldpd is already running.

tc@box:~$
tc@box:~$ sudo /usr/local/etc/init.d/lldpd status

lldpd is not running.

Title: Re: lldpd not available for 16.x
Post by: Rich on August 25, 2025, 12:21:10 AM
Hi orneh24
... although Restart seems to fail; ...
I think see the issue. The  RUNNING  variable was not updated in stop():
Code: [Select]
#!/bin/sh

if [ `/usr/bin/id -u` -ne 0 ]
then
echo -e "\nNeed to run as root or using sudo.\n"
exit 1
fi

NAME="lldpd"
DAEMON="/usr/local/sbin/$NAME"
DAEMON_ARGS=""

RUNNING=$(ps aux | grep -v "grep" | grep "$DAEMON")

start()
{
[ -n "$RUNNING" ] && echo -e "\n$NAME is already running.\n" && exit 2
start-stop-daemon -S -x "$DAEMON" -- "$DAEMON_ARGS"
}

stop()
{
start-stop-daemon -K -x "$DAEMON" 2>/dev/null
RUNNING=$(ps aux | grep -v "grep" | grep "$DAEMON")
[ -n "$RUNNING" ] && echo -e "\n$NAME was not stopped.\n" && exit 3
rm -rf /var/run/"$NAME"*
}



status()
{
[ -n "$RUNNING" ] && echo -e "\n$NAME is running.\n" && exit 0
echo -e "\n$NAME is not running.\n"
exit 1
}

case $1 in
start) start
;;
stop) stop
;;
status) status
;;
restart) stop; start
;;
*) echo -e "\n$0 [start|stop|restart|status]\n"
;;
esac

Please see if the attached works any better.
Title: Re: lldpd not available for 16.x
Post by: orneh24 on August 25, 2025, 06:29:22 PM
Testing with the updated script;

When daemon is currently running, and restart is initiated:
Code: [Select]
root@box:/# ./usr/local/etc/init.d/lldpd status

lldpd is running.

root@box:/# ./usr/local/etc/init.d/lldpd restart
stopped /usr/local/sbin/lldpd (pid 1791 1789)

lldpd was not stopped.

root@box:/# ps -C lldpd
  PID TTY          TIME CMD
root@box:/#

So it looks like the variable is still not updated correctly.

If the daemon is currently stopped, and restart is initiated:
Code: [Select]
root@box:/# ./usr/local/etc/init.d/lldpd status

lldpd is not running.

root@box:/# ./usr/local/etc/init.d/lldpd restart
no /usr/local/sbin/lldpd found; none killed
root@box:/# ./usr/local/etc/init.d/lldpd status

lldpd is running.

root@box:/# ps -C lldpd
  PID TTY          TIME CMD
 1853 ?        00:00:00 lldpd
 1855 ?        00:00:00 lldpd
root@box:/#
Title: Re: lldpd not available for 16.x
Post by: Rich on August 25, 2025, 09:03:55 PM
Hi orneh24
OK, I installed lldpd on one of my machines and tracked down the problem.
When  start-stop-daemon  stops a process, it sends it a terminate signal and
then returns control to whatever called it. Meanwhile, the process still needs
to receive that signal and act upon it. So we had a race condition. I added a
loop that will wait up to 3 seconds for the process to terminate. On my machine
the delay loop dropped out after 0.6 seconds:
Code: [Select]
#!/bin/sh

if [ `/usr/bin/id -u` -ne 0 ]
then
echo -e "\nNeed to run as root or using sudo.\n"
exit 1
fi

NAME="lldpd"
DAEMON="/usr/local/sbin/$NAME"
DAEMON_ARGS=""

RUNNING=$(ps aux | grep -v "grep" | grep "$DAEMON")

start()
{
[ -n "$RUNNING" ] && echo -e "\n$NAME is already running.\n" && exit 2
start-stop-daemon -S -x "$DAEMON" -- "$DAEMON_ARGS"
}

stop()
{
start-stop-daemon -q -K -x "$DAEMON" 2>/dev/null
for DELAY in $(seq 1 30)
do
RUNNING=$(ps aux | grep -v "grep" | grep "$DAEMON")
[ -z "$RUNNING" ] && break
done
[ -n "$RUNNING" ] && echo -e "\n$NAME was not stopped.\n" && exit 3
rm -rf /var/run/"$NAME"*
}



status()
{
[ -n "$RUNNING" ] && echo -e "\n$NAME is running.\n" && exit 0
echo -e "\n$NAME is not running.\n"
exit 1
}

case $1 in
start) start
;;
stop) stop
;;
status) status
;;
restart) stop; start
;;
*) echo -e "\n$0 [start|stop|restart|status]\n"
;;
esac

Please check if I finally got it right.
Title: Re: lldpd not available for 16.x
Post by: orneh24 on August 25, 2025, 11:07:25 PM
Hey Rich,

..Please check if I finally got it right..
.. You did  :)

Code: [Select]
root@box:/home/tc# ps -C lldpd
  PID TTY          TIME CMD
 1639 ?        00:00:00 lldpd
 1641 ?        00:00:00 lldpd
root@box:/home/tc# /usr/local/etc/init.d/lldpd status

lldpd is running.

root@box:/home/tc# /usr/local/etc/init.d/lldpd restart
root@box:/home/tc#
root@box:/home/tc# /usr/local/etc/init.d/lldpd status

lldpd is running.

root@box:/home/tc# ps -C lldpd
  PID TTY          TIME CMD
 1747 ?        00:00:00 lldpd
 1749 ?        00:00:00 lldpd
root@box:/home/tc#

    [Edit]: Replaced quote tags with code tags.  Rich
Title: Re: lldpd not available for 16.x
Post by: patrikg on August 26, 2025, 01:42:05 AM
Why not like another deamons SysV-init-skript rc files make a pid file with the pid number, and kill that number.
Something like this:
Code: [Select]
#!/bin/sh
#
# Simple init script to start/stop a daemon with a PID file

DAEMON="/usr/local/bin/mydaemon"   # executable
PIDFILE="/var/run/mydaemon.pid"    # pid file
NAME="mydaemon"

start() {
    if [ -f "$PIDFILE" ] && kill -0 $(cat "$PIDFILE") 2>/dev/null; then
        echo "$NAME is already running"
        return 0
    fi
    echo "Starting $NAME..."
    $DAEMON &
    echo $! > "$PIDFILE"
    echo "$NAME started with PID $(cat $PIDFILE)"
}

stop() {
    if [ -f "$PIDFILE" ]; then
        PID=$(cat "$PIDFILE")
        if kill -0 "$PID" 2>/dev/null; then
            echo "Stopping $NAME..."
            kill "$PID"
            rm -f "$PIDFILE"
            echo "$NAME stopped"
        else
            echo "Process not running, removing stale PID file"
            rm -f "$PIDFILE"
        fi
    else
        echo "$NAME is not running"
    fi
}

status() {
    if [ -f "$PIDFILE" ] && kill -0 $(cat "$PIDFILE") 2>/dev/null; then
        echo "$NAME is running with PID $(cat $PIDFILE)"
        return 0
    else
        echo "$NAME is not running"
        return 1
    fi
}

restart() {
    stop
    sleep 1
    start
}

case "$1" in
    start) start ;;
    stop) stop ;;
    restart) restart ;;
    status) status ;;
    *)
        echo "Usage: $0 {start|stop|restart|status}"
        exit 1
        ;;
esac

exit 0
Title: Re: lldpd not available for 16.x
Post by: Rich on August 26, 2025, 02:28:18 PM
Hi patrikg
Why not like another deamons SysV-init-skript rc files make a pid file with the pid number, ...
Here's what happens when you background lldpd:
Code: [Select]
tc@box:~/lldpd$
tc@box:~/lldpd$
tc@box:~/lldpd$
tc@box:~/lldpd$ sudo /usr/local/sbin/lldpd &
tc@box:~/lldpd$
[1]+  Done                       sudo /usr/local/sbin/lldpd
tc@box:~/lldpd$ echo $!
5186
tc@box:~/lldpd$ ps aux | grep -v "grep" | grep /usr/local/sbin/lldpd
 5187 _lldpd   /usr/local/sbin/lldpd
 5189 _lldpd   /usr/local/sbin/lldpd
tc@box:~/lldpd$
It launches 2 instances of itself and exits. The PID you get back is
for the original instance you launched, which already exited.

Also, lldpd creates its own PID file:
Code: [Select]
tc@box:~/lldpd$ cat /var/run/lldpd.pid
5187
tc@box:~/lldpd$

Quote
... and kill that number. ...
start-stop-daemon stop  sends kill signals to all copies of lldpd, regardless
of how many copies are currently running.
Title: Re: lldpd not available for 16.x
Post by: patrikg on August 26, 2025, 03:24:45 PM
Ohh it's forking it self to two, didn't see that, sorry.

But if it's making it's own pid file it's should be the one you need, or am wrong ?
Should it be two pid numbers in that file ?

Or can you just kill the main process to kill the child.(sorry for this type of language)
Title: Re: lldpd not available for 16.x
Post by: Rich on August 26, 2025, 04:10:46 PM
Hi patrikg
... Or can you just kill the main process to kill the child.(sorry for this type of language)
In a perfect world, yes. But if something goes wrong, it's probably
safer to send kill signals to all instances.
Title: Re: lldpd not available for 16.x
Post by: Rich on August 29, 2025, 09:51:21 AM
Hi orneh24
I created a couple of scripts to make using lldpd easier.

lldpdAddUser  adds  _lldpd  to users and groups if not already present:
Code: [Select]
#!/bin/sh
# lldpd needs to be added to users and groups to run.

# If group  _lldpd  does not exist, create it.
if ! sudo grep -q "_lldpd" /etc/group; then sudo addgroup _lldpd; fi

# If user  _lldpd  does not exist, create it.
if ! sudo grep -q "_lldpd" /etc/passwd; then sudo adduser -H -S -s /bin/sh -G _lldpd -D _lldpd; fi

# If  _lldpd  is not in sudoers, add it.
if ! sudo grep -q "_lldpd" /etc/sudoers
then
echo -e "_lldpd\tALL=NOPASSWD: ALL" | sudo tee -a /etc/sudoers > /dev/null
fi

lldpdBackupUser  adds the updated user/group files to  .filetool.lst  if
they are not already present:
Code: [Select]
#!/bin/sh
# Updates /opt/.filetool.lst.

FILETOOL_LST="/opt/.filetool.lst"

# List of files to add to  .filetool.lst.
FILES="etc/passwd etc/shadow etc/sudoers etc/group etc/gshadow"

# Go through the list of FILES one by one.
for FILE in $FILES
do
# See if FILE is already in  .filetool.lst.
if ! grep -q $FILE $FILETOOL_LST 2> /dev/null
then
# If not, then add it.
echo $FILE >> $FILETOOL_LST
fi
done

echo "Run filetool.sh -b to backup updated files"
I leave running the actual backup to the end user but provide a reminder
that it needs to be done.

I plan on adding them to the build package for inclusion with the extension.

I've attached copies of the scripts to this post.