This Rs232 shutdown button software can be used to shutdown your server
when there is no keyboard connected and the power button is not configured
to do a clean shutdown.

This software reads the state of a push button to and controls 1 LED
connected the serial line.

It works as follows:
--------------------
The LED will blink when the pushbutton is active.
To shut down the server you press the pushbutton for 2 seconds.

When you press the pushbutton then the green LED will go off indicating
the shutdown is in progress.  The command "/sbin/shutdown -h now"
is now executing.  

You need the following parts to build this shutdown button with LEDs.

   * 1 green LED 
   * 1 resistors 1K Ohm
   * 1 small push button
   * 1 female RS232 serial line connector and a USB to rs232 adapter

The RS 232 9 PIN D-SUB MALE connector at the Computer (usb adapter side).
 9 PIN-connector25 PIN-connector Name  Dir       Description
 1              8                CD   input  Carrier Detect
 2              3                RXD  input  Receive Data
 3              2                TXD  output Transmit Data
 4              20               DTR  output Data Terminal Ready
 5              7                GND  --     System Ground
 6              6                DSR  input  Data Set Ready
 7              4                RTS  output Request to Send
 8              5                CTS  input  Clear to Send
 9              22               RI   input  Ring Indicator

The parts are connected together as shown 
in the diagram called pictures/circuit.png

Installation
------------
This is designed to work for a linux system using systemd.
The shutdown-button-rs232.service file expects the usb to rs232 adapter
to show up as /dev/ttyUSB0. You can print the command dmesg after you plug 
the usb to rs232 into your pc. You should see something like this:

[  531.589537] ch341 6-1.1:1.0: ch341-uart converter detected
[  531.594821] usb 6-1.1: ch341-uart converter now attached to ttyUSB0

   or

[    2.953801] pl2303 2-1.4:1.0: pl2303 converter detected
[    2.956287] usb 2-1.4: pl2303 converter now attached to ttyUSB0

Commands to install the software for systemd on ubuntu 18.04:

As root:
1) compile (type make):
# make
gcc  -Wall -O2 -c shutdown-button-rs232.c 
gcc  -o shutdown-button-rs232 shutdown-button-rs232.o 

2) install:
cp shutdown-button-rs232.service /lib/systemd/system/shutdown-button-rs232.service 
cp shutdown-button-rs232 /usr/bin/

systemctl enable shutdown-button-rs232.service
systemctl start shutdown-button-rs232.service
systemctl status shutdown-button-rs232.service

That's it.
-------------------------------
Versions:
2019-04-08: version 0.1, based on the 2001 version of sled-0.3
2025-12-08: version 0.2, update readme file

Written by Guido Socher guidosocher@fastmail.fm

Copyright: GPL, see http://www.gnu.org/copyleft/ for details
