@@ -17,6 +17,17 @@ if [ ! -d /var/sudobot ]; then
17
17
mkdir -p /var/sudobot
18
18
fi
19
19
20
+ # Create directories
21
+ if [ ! -d /var/log/sudobot ]; then
22
+ mkdir -p /var/log/sudobot
23
+ fi
24
+
25
+ touch /var/run/sudobot.pid
26
+
27
+ chown sudobot:sudobot /var/run/sudobot.pid
28
+ chmod 644 /var/run/sudobot.pid
29
+
30
+ chown -R sudobot:sudobot /var/log/sudobot
20
31
chown -R sudobot:sudobot /var/sudobot
21
32
chown -R sudobot:sudobot /usr/share/sudobot
22
33
chown -R sudobot:sudobot /etc/sudobot
@@ -57,9 +68,101 @@ su sudobot -c "PATH=\"$PATH\" BUN_INSTALL=/var/sudobot $pm install" -s /bin/sh |
57
68
}
58
69
59
70
# Enable systemd service
60
- if [ -f /lib/systemd/system/sudobot.service ]; then
71
+ if [ -f /lib/systemd/system/sudobot.service ] && command -v systemctl > /dev/null 2>&1 ; then
61
72
if command -v deb-systemd-helper > /dev/null 2>&1 ; then
62
73
deb-systemd-helper enable sudobot.service || true
63
74
fi
64
75
fi
65
76
77
+ # Create SystemV init script
78
+ if command -v update-rc.d > /dev/null 2>&1 ; then
79
+ cat << 'EOF ' > /etc/init.d/sudobot
80
+ #!/bin/sh
81
+ ### BEGIN INIT INFO
82
+ # Provides: sudobot
83
+ # Required-Start: $local_fs $network
84
+ # Required-Stop: $local_fs $network
85
+ # Default-Start: 2 3 4 5
86
+ # Default-Stop: 0 1 6
87
+ # Short-Description: Start sudobot daemon
88
+ # Description: Start the sudobot daemon
89
+ ### END INIT INFO
90
+
91
+ LOG_FILE="/var/log/sudobot/sudobot.log"
92
+ PID_FILE="/var/run/sudobot.pid"
93
+
94
+ start() {
95
+ nohup su -s /bin/sh -c "/usr/bin/sudobot" >> "$LOG_FILE" 2>&1 &
96
+
97
+ if [ ! -f "$PID_FILE" ]; then
98
+ touch "$PID_FILE"
99
+ chown sudobot:sudobot "$PID_FILE"
100
+ chmod 644 "$PID_FILE"
101
+ fi
102
+
103
+ echo $! > "$PID_FILE"
104
+ }
105
+
106
+ stop() {
107
+ if [ ! -f "$PID_FILE" ]; then
108
+ return 1
109
+ fi
110
+
111
+ PID="$(cat "$PID_FILE" 2>/dev/null)"
112
+
113
+ if [ -z "$PID" ]; then
114
+ rm -f "$PID_FILE"
115
+ return 1
116
+ fi
117
+
118
+ if kill -0 "$PID" >/dev/null 2>&1; then
119
+ kill "$PID"
120
+ rm -f "$PID_FILE"
121
+ else
122
+ rm -f "$PID_FILE"
123
+ return 1
124
+ fi
125
+ }
126
+
127
+ case "$1" in
128
+ start)
129
+ echo "Starting sudobot..."
130
+ start
131
+ ;;
132
+ stop)
133
+ echo "Stopping sudobot..."
134
+ stop
135
+
136
+ if [ $? -ne 0 ]; then
137
+ echo "sudobot is not running or could not be stopped."
138
+ exit $?
139
+ fi
140
+ ;;
141
+ restart)
142
+ echo "Restarting sudobot..."
143
+ stop
144
+ start
145
+ ;;
146
+ status)
147
+ if [ -f "$PID_FILE" ]; then
148
+ PID="$(cat "$PID_FILE" 2>/dev/null)"
149
+
150
+ if [ -n "$PID" ] && kill -0 "$PID" >/dev/null 2>&1; then
151
+ echo "sudobot is running with PID $PID."
152
+ else
153
+ echo "sudobot is not running."
154
+ fi
155
+ else
156
+ echo "sudobot is not running."
157
+ fi
158
+ ;;
159
+ *)
160
+ echo "Usage: $0 {start|stop|restart|status}"
161
+ exit 1
162
+ ;;
163
+ esac
164
+ exit 0
165
+ EOF
166
+
167
+ update-rc.d sudobot defaults || true
168
+ fi
0 commit comments