Akkadius / glass-isc-dhcp

Glass - ISC DHCP Server Interface
MIT License
696 stars 144 forks source link

Support for CentOS/RHEL starter services #6

Closed computergeek125 closed 6 years ago

computergeek125 commented 6 years ago

Hello!

First of all, great work! I was able to get this running in under a day. However, I had to make a minor change to the start/stop code that allows this application to control the CentOS/RHEL-based ISC DHCPD service.

On these distros, the service is in systemd as dhcpd.service instead of isc-dhcp-server.service as it is in Debian-based distros.

It's a pretty simple fix:

diff --git a/routes/dhcp_start_stop_restart.js b/routes/dhcp_start_stop_restart.js
index 77acbb9..90d5e67 100644
--- a/routes/dhcp_start_stop_restart.js
+++ b/routes/dhcp_start_stop_restart.js
@@ -49,15 +49,15 @@ router.post('/', authorize.auth, function(req, res, next) {

        switch (request.action) {
                case "stop":
-                       dhcp_exec = execSync('/usr/sbin/service isc-dhcp-server stop && /bin/sleep 1');
+                       dhcp_exec = execSync('/usr/sbin/service dhcpd stop && /bin/sleep 1');
                        res.send("<script type='text/javascript'>notification('DHCP Server Stopped');ignore_cache = 1;do_pjax_request
                        break;
                case "start":
-                       dhcp_exec = execSync('/usr/sbin/service isc-dhcp-server start');
+                       dhcp_exec = execSync('/usr/sbin/service dhcpd start');
                        res.send("<script type='text/javascript'>notification('DHCP Server Started');ignore_cache = 1;do_pjax_request
                        break;
                case "restart":
-                       dhcp_exec = execSync('/usr/sbin/service isc-dhcp-server restart && /bin/sleep 1');
+                       dhcp_exec = execSync('/usr/sbin/service dhcpd restart && /bin/sleep 1');
                        res.send("<script type='text/javascript'>notification('DHCP Server Restarted " + dhcp_exec + "');ignore_cache
                        break;
                default:

Since the service command redirects to systemctl (at least for now), everything's all fine and happy.

Additionally, I have created a systemd starter service for this Node app and an rsyslog conf snippet that picks up the node output and dumps it into its own log file so it's not in /var/log/messages or /var/log/syslog if you want one or both of those as well. With the starter service, systemd can intelligently detect when the process needs to be started/stopped, and you can use it to make sure that this starts after dhcpd. Note that due to the service naming difference between CentOS/RHEL and Debian, a minor modification would be needed to get it working on a Debian-based system.

Akkadius commented 6 years ago

Sorry for the really late response on this issue - I've recently switched jobs so my attention has been fully somewhere else lately

In the next few weeks I will be working on making all of these commands work universally across major distributions

Thanks for the report!

Akkadius commented 6 years ago

@computergeek125 thank you for this again, I've made these modifications based on Redhat derivatives CentOS / Fedora / Redhat

https://github.com/Akkadius/glass-isc-dhcp/commit/3d30b00e9616f0baab3476be2789eb962954d9f8

Let me know if you have any questions, also curious to hear your feedback on using Glass, are you an operator?