Last active
September 11, 2019 02:56
-
-
Save j1cs/c27bbb4c73e16086c7f6a0c8743f8110 to your computer and use it in GitHub Desktop.
mailpile init with screen(pretty dirty)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
### BEGIN INIT INFO | |
# Provides: mailpile | |
# Required-Start: $local_fs $remote_fs $network $syslog | |
# Required-Stop: $local_fs $remote_fs $network $syslog | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: Start/stop mailpile daemon | |
### END INIT INFO | |
# —————————————————————————— | |
# /etc/init.d/mailpile | |
# | |
# This script is an init script to run mailpile in the background, using a | |
# screen. The script was designed and tested for Debian systems, but may work on | |
# other systems. On Debian, enable it by moving the script to | |
# "/etc/init.d/mailpile" and issuing the command | |
# "update-rc.d mailpile defaults 99″ | |
# —————————————————————————— | |
## Username to run mailpile under | |
USER="glats" | |
## Absolute path to the mailpile binary. | |
MAILPILE="/home/glats/programs/Mailpile/mp" | |
## Absolute path to the screen binary. | |
SCREEN="/usr/bin/screen" | |
## Name of the screen session, you can then "screen -r mailpile" to get it back | |
## to the forground and work with it on your shell. | |
SCREEN_NAME="mailpile" | |
## Absolute path to mailpile’s PID file. | |
PIDFILE="/var/run/mailpile.pid" | |
# Include functions | |
. /lib/lsb/init-functions | |
case "$1" in | |
## Start mailpile in the background. | |
start) | |
log_daemon_msg "Starting mailpile" | |
start-stop-daemon --start --background --oknodo \ | |
--pidfile "$PIDFILE" --make-pidfile \ | |
--chuid $USER \ | |
--exec $SCREEN -- -DmUS $SCREEN_NAME $MAILPILE | |
if [[ $? -ne 0 ]]; then | |
log_end_msg 1 | |
fi | |
log_end_msg 0 | |
;; | |
## Stop mailpile. | |
stop) | |
log_daemon_msg "Stopping mailpile" | |
start-stop-daemon --stop --oknodo --pidfile "$PIDFILE" | |
if [[ $? -ne 0 ]]; then | |
log_end_msg 1 | |
fi | |
log_end_msg 0 | |
;; | |
## Restart mailpile. | |
restart) | |
"$0" stop | |
sleep 1 | |
"$0" start || exit 1 | |
;; | |
## Print usage information if the user gives an invalid option. | |
*) | |
echo "Usage: $0 [start|stop|restart]" | |
exit 1 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment