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/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 ".*#" + } +} diff --git a/etc/powerman.service.in b/etc/powerman.service.in index bbf1cb09..cf6952e2 100644 --- a/etc/powerman.service.in +++ b/etc/powerman.service.in @@ -3,10 +3,11 @@ Description=PowerMan After=syslog.target network.target [Service] +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