Skip to content

Commit

Permalink
Merge pull request #96 from garlick/old_prs
Browse files Browse the repository at this point in the history
systemd: allow group to be configured and set SHELL in env; add UBNT edge device
  • Loading branch information
mergify[bot] committed Jan 26, 2024
2 parents b5ee5b4 + 6e60023 commit 2754c00
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 3 deletions.
17 changes: 17 additions & 0 deletions config/ac_runas.m4
Original file line number Diff line number Diff line change
@@ -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)]),
Expand All @@ -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)
])
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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

##
Expand Down
1 change: 1 addition & 0 deletions etc/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
57 changes: 57 additions & 0 deletions etc/devices/rancid-edgemax-poe.dev
Original file line number Diff line number Diff line change
@@ -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 ".*#"
}
}
5 changes: 3 additions & 2 deletions etc/powerman.service.in
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 2754c00

Please sign in to comment.