From e113db6571ca2f8ac953a1c554adbeaaa75cc4cc Mon Sep 17 00:00:00 2001 From: Daniel Rich Date: Fri, 26 Jan 2024 06:51:06 -0800 Subject: [PATCH 1/3] Add support for control of POE on UBNT EdgeMax switches Note from @garlick: this was submitted as pr #49 in 2021 but the author did not follow up with requested git machinations. Pulling it in anyway in case it's useful to someone. --- etc/Makefile.am | 1 + etc/devices/rancid-edgemax-poe.dev | 57 ++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 etc/devices/rancid-edgemax-poe.dev diff --git a/etc/Makefile.am b/etc/Makefile.am index 53c58fd5..4fbde859 100644 --- a/etc/Makefile.am +++ b/etc/Makefile.am @@ -69,6 +69,7 @@ pkgsysconf_DATA = \ devices/plmpower.dev \ devices/powerman.dev \ devices/rancid-cisco-poe.dev \ + devices/rancid-edgemax-poe.dev \ devices/raritan-px4316.dev \ devices/raritan-px5523.dev \ devices/sentry_cdu.dev \ diff --git a/etc/devices/rancid-edgemax-poe.dev b/etc/devices/rancid-edgemax-poe.dev new file mode 100644 index 00000000..d9bcf5ee --- /dev/null +++ b/etc/devices/rancid-edgemax-poe.dev @@ -0,0 +1,57 @@ +# +# Control POE on UniFi switches via rancid (http://www.shrubbery.net/rancid/) +# +# device "ubnt-switch" "rancid-ubnt-poe" "/usr/lib/rancid/bin/clogin -t600 myswitch |&" +# +# Plug names are the device interface name: +# node "mydevice" "ubnt-switch" "0/1" +# +# The user running the powerman must have a .cloginrc file in its home directory +# with an appropriate configuration to allow querying and setting power status +# +specification "rancid-ubnt-poe" { + timeout 10 + + script login { + expect ".*#" + } + script logout { + send "exit\n" + } + script status { + send "show poe status %s | section (Good|Circuit|Short|Low) \n" + expect "\r\n\r\n([^ ]+) +(Good|Open Circuit|Short|R Sig Too Low)" + setplugstate $1 $2 on="Good" off=".*" + expect ".*#" + } + script on { + send "configure\n" + expect ".*\\(Config\\)#" + send "interface %s\n" + expect ".*\\(Interface [0-9\/]+\\)#" + send "poe opmode auto\n" + expect ".*\\(Interface [0-9\/]+\\)#" + send "end\n" + expect ".*#" + } + script off { + send "configure\n" + expect ".*\\(Config\\)#" + send "interface %s\n" + expect ".*\\(Interface [0-9\/]+\\)#" + send "poe opmode shutdown\n" + expect ".*\\(Interface [0-9\/]+\\)#" + send "end\n" + expect ".*#" + } + script cycle { + send "configure\n" + expect ".*\\(Config\\)#" + send "interface %s\n" + expect ".*\\(Interface [0-9\/]+\\)#" + send "poe opmode shutdown poe opmode auto\n" + expect ".*\\(Interface [0-9\/]+\\)#" + send "end\n" + expect ".*#" + } +} From c2b5bd195c5c5d3d3c1934ac87b692c6152dfdf9 Mon Sep 17 00:00:00 2001 From: "Brian J. Murrell" Date: Fri, 26 Jan 2024 06:59:33 -0800 Subject: [PATCH 2/3] package: set SHELL in powerman's environment Powerman may need to run things to connect to power control devices, such as an ssh command. For ssh to operate properly it needs to have SHELL set to a valid shell in it's environment. Note from @garlick: this was submitted in 2017 as pr #24 but was left unmerged due to pending git machinations. Let's just pull it in. --- etc/powerman.service.in | 1 + 1 file changed, 1 insertion(+) diff --git a/etc/powerman.service.in b/etc/powerman.service.in index bbf1cb09..6ecc39b9 100644 --- a/etc/powerman.service.in +++ b/etc/powerman.service.in @@ -3,6 +3,7 @@ Description=PowerMan After=syslog.target network.target [Service] +Environment=SHELL=/bin/sh Type=forking PrivateTmp=yes User=daemon From 6e60023973504f7881baa99e3becf58f74e84458 Mon Sep 17 00:00:00 2001 From: John Jolly Date: Thu, 15 Jun 2017 19:31:50 -0600 Subject: [PATCH 3/3] Add --with-group= option to config.ac The powerman.service file has configuration options to run the daemon as a specific user and group. The current default for both is "daemon". Changing the user is possible through --with-user= configure option, but there is no option for changing the group. In order to allow the group value to be configured at build time, a configure option similar to the --with-user= option should be provided. This change creates the --with-group= option, setting the @RUN_AS_GROUP@ macro for autoconf files. Note from @garlick: this was submitted in 2017 as pr #26 and sat around due to maintainer inattention. Rebasing and reviving as it's a good patch! --- config/ac_runas.m4 | 17 +++++++++++++++++ configure.ac | 2 +- etc/powerman.service.in | 4 ++-- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/config/ac_runas.m4 b/config/ac_runas.m4 index f83680b3..0af89463 100644 --- a/config/ac_runas.m4 +++ b/config/ac_runas.m4 @@ -1,6 +1,7 @@ AC_DEFUN([AC_RUNAS], [ RUN_AS_USER="daemon" + RUN_AS_GROUP="daemon" AC_MSG_CHECKING(user to run as) AC_ARG_WITH(user, AS_HELP_STRING([--with-user=username], [user for powerman daemon (daemon)]), @@ -16,4 +17,20 @@ AC_DEFUN([AC_RUNAS], [Powerman daemon user]) AC_MSG_RESULT(${RUN_AS_USER}) AC_SUBST(RUN_AS_USER) + + AC_MSG_CHECKING(group to run as) + AC_ARG_WITH(group, + AC_HELP_STRING([--with-group=groupname], [group for powerman daemon (daemon)]), + [ case "${withval}" in + yes|no) + ;; + *) + RUN_AS_GROUP="${withval}" + ;; + esac], + ) + AC_DEFINE_UNQUOTED(RUN_AS_GROUP, "${RUN_AS_GROUP}", + [Powerman daemon group]) + AC_MSG_RESULT(${RUN_AS_GROUP}) + AC_SUBST(RUN_AS_GROUP) ]) diff --git a/configure.ac b/configure.ac index 54e36ade..0b048792 100644 --- a/configure.ac +++ b/configure.ac @@ -109,7 +109,7 @@ AC_DEFINE(WITH_LSD_NOMEM_ERROR_FUNC, 1, [Define lsd_fatal_error]) # whether to install pkg-config file for API AC_PKGCONFIG -# what user to run daemon as +# what user and group to run daemon as AC_RUNAS ## diff --git a/etc/powerman.service.in b/etc/powerman.service.in index 6ecc39b9..cf6952e2 100644 --- a/etc/powerman.service.in +++ b/etc/powerman.service.in @@ -6,8 +6,8 @@ After=syslog.target network.target Environment=SHELL=/bin/sh Type=forking PrivateTmp=yes -User=daemon -Group=daemon +User=@RUN_AS_USER@ +Group=@RUN_AS_GROUP@ ExecStart=@X_SBINDIR@/powermand PIDFile=@X_RUNSTATEDIR@/powerman/powermand.pid