Add init scripts

This commit is contained in:
Florian Roméo 2017-04-11 19:30:07 +02:00 committed by GitHub
parent eebeee2b76
commit e9b4f585bd
1 changed files with 111 additions and 0 deletions

View File

@ -236,6 +236,117 @@ WantedBy=multi-user.target
```
This allows you to `sudo systemctl enable /etc/systemd/system/mastodon-*.service` and `sudo systemctl start mastodon-web.service mastodon-sidekiq.service mastodon-streaming.service` to get things going.
## Init scripts
Example init script for the web workers, to be placed in `/etc/init.d/mastodon-web`:
```
#!/sbin/openrc-run
name="Mastodon Web Service"
root="/home/mastodon/live"
pidfile="${root}/web.pid"
depend() {
use net
}
start() {
ebegin "Starting Mastodon web workers"
cd $root
start-stop-daemon --start \
--chdir "${root}" \
--user="mastodon" \
--pidfile="${pidfile}" \
--exec /usr/bin/env -- RAILS_ENV=production PORT=3000 bundle exec puma -C config/puma.rb -d --pidfile ${pidfile}
eend $?
}
stop() {
ebegin "Stopping Mastodon web workers"
start-stop-daemon --stop \
--pidfile=${pidfile} \
eend $?
}
```
Example init script for the background workers, to be placed in `/etc/init.d/mastodon-sidekiq`:
```
#!/sbin/openrc-run
name="Mastodon background workers Service"
root="/home/mastodon/live"
pidfile="${root}/worker.pid"
logfile="${root}/sidekiq.conf"
depend() {
use net
need redis
}
start() {
ebegin "Starting Mastodon background workers"
cd $root
start-stop-daemon --start \
--chdir "${root}" \
--user="mastodon" \
--pidfile="${pidfile}" \
--exec /usr/bin/env -- RAILS_ENV=production DB_POOL=5 bundle exec sidekiq -d -P ${pidfile} -L ${logfile} -c 5 -q default -q mailers -q pull -q push
eend $?
}
stop() {
ebegin "Stopping Mastodon background workers"
start-stop-daemon --stop \
--pidfile=${pidfile} \
eend $?
}
```
Example init script file for the streaming API, to be placed in `/etc/init.d/mastodon-streaming`:
```
#!/sbin/openrc-run
name="Mastodon streaming API service"
root="/home/mastodon/live"
depend() {
use net
}
start() {
ebegin "Starting Mastodon streaming API"
cd $root
start-stop-daemon --start \
--background --quiet \
--chdir "${root}" \
--user="mastodon" \
--make-pidfile --pidfile=${root}/streaming.pid \
--exec /usr/bin/env -- NODE_ENV=production PORT=4000 /usr/bin/npm run start
eend $?
}
stop() {
ebegin "Stopping Mastodon streaming API"
start-stop-daemon --stop \
--pidfile=${root}/streaming.pid \
eend $?
}
```
This allows you to `rc-update add mastodon-web && rc-update add mastodon-sidekiq && rc-update add mastodon-streaming` and `service mastodon-web start && service mastodon-sidekiq start && service mastodon-streaming start` to get things going.
## Cronjobs