Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Monit README section by providing a working setup example #58

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 105 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,79 @@ And the best thing about ereb: it really works and made already thousands task r

# How to install

`pip3 install ereb`
Under `root`:
```
pip3 install ereb
```

This will install `ereb` to `/usr/local/bin/ereb`.

## For Debian/Ubuntu users

If you want to properly install ereb so that it starts on system start, make use of systemd.

1. Create a proper init script: `vim /etc/init.d/ereb`:
```
#!/bin/bash
### BEGIN INIT INFO
# Provides: ereb
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start ereb at boot time
# Description: Ereb is a cool crontab with web interface.
### END INIT INFO

PIDFILE=/var/run/ereb.pid

case $1 in
start)
# as a detached process
/usr/local/bin/ereb >> /var/log/ereb.log 2>&1 &
# Get its PID and store it
echo $! > ${PIDFILE}
;;
stop)
kill `cat ${PIDFILE}`
# Now that it's killed, don't forget to remove the PID file
rm ${PIDFILE}
;;
*)
echo "usage: ereb {start|stop}" ;;
esac
exit 0
```
2. Create a systemd unit: `vim /lib/systemd/system/ereb.service`:
```
[Unit]
SourcePath=/etc/init.d/ereb
Description=Easy installable cron with web interface

[Service]
Type=forking
PIDFile=/var/run/ereb.pid
Restart=always
TimeoutSec=5min
IgnoreSIGPIPE=no
KillMode=process
GuessMainPID=no
RemainAfterExit=yes
ExecStart=/etc/init.d/ereb start
ExecStop=/etc/init.d/ereb stop
```
3. Place the unit under `multi-user` target:
```
ln -s /lib/systemd/system/ereb.service /etc/systemd/system/multi-user.target.wants/ereb.service
```
4. Enable the service so that it starts on boot:
```
systemctl enable ereb.service
```

Now you can try to `reboot` your server and make sure that `ps aux | grep ereb | grep -v grep` shows up running ereb instance.

Read more on <https://www.digitalocean.com/community/tutorials/systemd-essentials-working-with-services-units-and-the-journal>

# JSON api

Expand Down Expand Up @@ -110,11 +182,40 @@ rm -rf var/
Example monit config (for ereb installed via pip)

```
check process ereb pidfile /PATH/TO/EREB/tmp/ereb.pid
start program = "ereb & echo $! > /PATH/TO/EREB/tmp/ereb.pid"
stop program = "/bin/bash -c '/bin/kill `cat /PATH/TO/EREB/tmp/ereb.pid`'" with timeout 65 seconds
check process ereb pidfile /var/run/ereb/ereb.pid
start program = "/etc/init.d/ereb start"
stop program = "/etc/init.d/ereb stop"
group system
```
Don't forget to create `/etc/init.d/ereb`:
```
#!/bin/bash

PIDFILE=/var/run/ereb/ereb.pid

case $1 in
start)
# as a detached process
/usr/local/bin/ereb >> /var/log/ereb/ereb.log 2>&1 &
# Get its PID and store it
echo $! > ${PIDFILE}
;;
stop)
kill `cat ${PIDFILE}`
# Now that it's killed, don't forget to remove the PID file
rm ${PIDFILE}
;;
*)
echo "usage: ereb {start|stop}" ;;
esac
exit 0
```
And ofcourse, don't forget to
```
mkdir /var/run/ereb
mkdir /var/log/ereb
```
*Note: Now you can see `ereb` log in `/var/log/ereb/ereb.log`.*

## Troubleshooting

Expand Down