]>
Commit | Line | Data |
---|---|---|
ff28b140 TL |
1 | #! /bin/sh |
2 | # | |
3 | # smartmontools initd file for Cygwin smartd | |
4 | # | |
5 | # Home page of code is: http://www.smartmontools.org | |
6 | # | |
7 | # Copyright (C) 2004-17 Christian Franke | |
8 | # | |
9 | # SPDX-License-Identifier: GPL-2.0-or-later | |
10 | # | |
11 | # $Id: smartd.cygwin.initd.in 4760 2018-08-19 18:45:53Z chrfranke $ | |
12 | # | |
13 | ||
14 | SMARTD_BIN=/usr/local/sbin/smartd | |
15 | ||
16 | # The following settings may be changed by the configuration file below | |
17 | # Service Name (must be unique) | |
18 | smartd_svcname=smartd | |
19 | # Service display name | |
20 | smartd_svcdisp="CYGWIN smartd" | |
21 | # Service description | |
22 | smartd_svcdesc="\ | |
23 | Controls and monitors storage devices using the Self-Monitoring, \ | |
24 | Analysis and Reporting Technology System (SMART) built into \ | |
25 | ATA/SATA and SCSI/SAS hard drives and solid-state drives. \ | |
26 | www.smartmontools.org" | |
27 | ||
28 | # Source configuration file. | |
29 | [ -r /etc/sysconfig/smartmontools ] && . /etc/sysconfig/smartmontools | |
30 | ||
31 | PID_FILE=/var/run/smartd.pid | |
32 | RETVAL=0 | |
33 | ||
34 | # Note: "[ -r $PID_FILE ]" is not used here. On Cygwin, this command may | |
35 | # return success even if the file is present but cannot be read by current user. | |
36 | # If smartd is running as service, smartd.pid is owned by local system account | |
37 | # which is different from any user ever executing this script. | |
38 | ||
39 | case "$1" in | |
40 | start) | |
41 | if cygrunsrv -L 2>/dev/null | grep "^${smartd_svcname}$" >/dev/null 2>&1; then | |
42 | echo -n "Starting service $smartd_svcname: " | |
43 | cygrunsrv -S "$smartd_svcname" | |
44 | else | |
45 | echo -n "Starting smartd as daemon: " | |
46 | $SMARTD_BIN -p $PID_FILE $smartd_opts | |
47 | fi | |
48 | RETVAL=$? | |
49 | ;; | |
50 | stop) | |
51 | echo -n "Shutting down smartd: " | |
52 | pid="`cat $PID_FILE 2>/dev/null`" && kill "$pid" | |
53 | RETVAL=$? | |
54 | ;; | |
55 | reload) | |
56 | echo -n "Reloading smartd configuration: " | |
57 | pid="`cat $PID_FILE 2>/dev/null`" && kill -HUP "$pid" | |
58 | RETVAL=$? | |
59 | ;; | |
60 | report) | |
61 | echo -n "Checking SMART devices now: " | |
62 | pid="`cat $PID_FILE 2>/dev/null`" && kill -USR1 "$pid" | |
63 | RETVAL=$? | |
64 | ;; | |
65 | restart) | |
66 | $0 stop | |
67 | sleep 1 | |
68 | $0 start | |
69 | exit $? | |
70 | ;; | |
71 | install) | |
72 | shift | |
73 | [ $# -eq 0 ] || smartd_opts="$*" | |
74 | dep=; dep2= | |
75 | if cygrunsrv -L 2>/dev/null | grep "^syslogd$" >/dev/null 2>&1; then | |
76 | dep="syslogd" | |
77 | fi | |
78 | if cygrunsrv -L 2>/dev/null | grep "^syslog-ng" >/dev/null 2>&1; then | |
79 | dep2="syslog-ng" | |
80 | fi | |
81 | if [ -z "$dep" ]; then | |
82 | if [ -z "$dep2" ]; then | |
83 | echo "Warning: no syslog service installed, smartd will write to windows event log."; | |
84 | else | |
85 | dep="$dep2" | |
86 | fi | |
87 | else | |
88 | if [ -z "$dep2" ]; then | |
89 | : | |
90 | else | |
91 | dep= | |
92 | echo "Warning: both syslogd and syslog-ng installed, dependency not set." | |
93 | fi | |
94 | fi | |
95 | echo "Installing service ${smartd_svcname}${dep:+ (depending on '$dep')}${smartd_opts:+ with options '$smartd_opts'}:" | |
96 | cygrunsrv -I "$smartd_svcname" -d "$smartd_svcdisp" -f "$smartd_svcdesc" ${dep:+-y} $dep \ | |
97 | -e CYGWIN="$CYGWIN" -p $SMARTD_BIN -a "-n -p ${PID_FILE}${smartd_opts:+ }$smartd_opts" | |
98 | RETVAL=$? | |
99 | ;; | |
100 | remove) | |
101 | echo "Removing service $smartd_svcname:" | |
102 | cygrunsrv -R "$smartd_svcname" | |
103 | RETVAL=$? | |
104 | ;; | |
105 | status) | |
106 | echo -n "Checking smartd status: " | |
107 | if cygrunsrv -L 2>/dev/null | grep "^${smartd_svcname}$" >/dev/null 2>&1; then | |
108 | if cygrunsrv -Q "$smartd_svcname" 2>/dev/null | grep "State *: Running" >/dev/null 2>&1; then | |
109 | echo "running as service '$smartd_svcname'." | |
110 | elif ps -e 2>/dev/null | grep " ${SMARTD_BIN}$" >/dev/null 2>&1; then | |
111 | echo "installed as service '$smartd_svcname' but running as daemon." | |
112 | else | |
113 | echo "installed as service '$smartd_svcname' but not running." | |
114 | RETVAL=1 | |
115 | fi | |
116 | elif ps -e 2>/dev/null | grep " ${SMARTD_BIN}$" >/dev/null 2>&1; then | |
117 | echo "running as daemon." | |
118 | else | |
119 | echo "not running." | |
120 | RETVAL=1 | |
121 | fi | |
122 | exit $RETVAL | |
123 | ;; | |
124 | *) | |
125 | echo "Usage: $0 {start|stop|restart|reload|report|status}" | |
126 | echo " $0 {install [options]|remove}" | |
127 | exit 1 | |
128 | esac | |
129 | ||
130 | if [ "$RETVAL" -eq 0 ]; then echo "done"; else echo "ERROR"; fi | |
131 | exit $RETVAL |