scragg0x / realms-wiki

Git based wiki inspired by Gollum
http://realms.io
GNU General Public License v2.0
833 stars 91 forks source link

realms systemd #187

Closed nzuhdi closed 7 years ago

nzuhdi commented 7 years ago

okay guys. how do you set up realms to work with systemd so that it will load after reboot? please share your realms systemd config.

ctappy commented 7 years ago

[Unit] Description=Realms

[Service] ExecStart=/usr/local/bin/realms-wiki start Restart=always TasksMax=infinity

StartLimitInterval=0

[Install] WantedBy=multi-user.target

ctappy commented 7 years ago

add this, or similar to your systemd service directory

dereks commented 7 years ago

Here is another systemd example. This example is based on the Upstart script that Realms-wiki will create if you run sudo realms-wiki setup_upstart. (Ubuntu switched from upstart to systemd with release 15.04.)

[Unit]
Description=Realms Wiki

[Service]
User=ubuntu
Group=ssl-cert
Type=forking

ExecStart=/home/ubuntu/realms-wiki/.venv/bin/python /home/ubuntu/realms-wiki/.venv/bin/gunicorn \
--certfile=/etc/ssl/certs/ssl-cert-snakeoil.pem   \
--keyfile=/etc/ssl/private/ssl-cert-snakeoil.key  \
--name realms-wiki     \
--access-logfile -     \
--error-logfile -      \
--worker-class gevent  \
--workers 5            \
--bind 0.0.0.0:5000    \
--user ubuntu          \
--group ssl-cert       \
--chdir /home/ubuntu/realms-wiki/.venv  \
'realms:create_app()'

Restart=on-failure
LimitNOFILE=65335
WorkingDirectory=/home/ubuntu/realms-wiki/.venv
Environment=PATH=/home/ubuntu/realms-wiki/.venv/bin:/usr/local/bin:/usr/bin:/bin:$PATH
Environment=LC_ALL=en_US.UTF-8
Environment=GEVENT_RESOLVER=ares

[Install]
WantedBy=multi-user.target

Unlike ctapert's example, this will run Realms-wiki using gunicorn as a multi-threaded web server.

This example is different from the provided Upstart script because it also uses SSL encryption.

It references the self-signed certificate that gets created if you run sudo apt-get install ssl-cert. The private key is only visible to the group ssl-cert, so I modified the Upstart example to run gunicorn with group ssl-cert.

Finally, the path /home/ubuntu/realms-wiki/ is where I installed it on my LXC container. It will need to be edited for your environment.

nzuhdi commented 7 years ago

Cool. I have tested both ways. And both are working great! With @dereks method I've tested without the SSL. @ctaperts @dereks Thanks!

One small problem, how can I load my own .git repo? Running the command realms-wiki start manually will successfully load my own data (/root/data/wiki/). While running with systemctl start realms.service will load the git repo at /tmp/wiki/.

(.venv)root@chimera:~/realms-wiki# find / -name "home.md"
/tmp/wiki/home.md
/root/data/wiki/home.md
ctappy commented 7 years ago

It is looking for the realms-wiki.json file, I haven't tested this but if you add it to the /etc/realms-wiki directory it should work

https://github.com/scragg0x/realms-wiki/blob/master/realms/config/__init__.py#L217

dereks commented 7 years ago

Check the README for the command realms-wiki setup. That will ask you some questions and then generate a new file realms-wiki.json, which looks like this:

{
    "ALLOW_ANON": false,
    "BASE_URL": "http://localhost",
    "CACHE_TYPE": "simple",
    "DB_URI": "sqlite:////home/ubuntu/wiki.db",
    "PORT": 5000,
    "REGISTRATION_ENABLED": true,
    "SEARCH_TYPE": "simple",
    "SECRET_KEY": "YjSZEmaZ...ABBAcY",
    "SITE_TITLE": "My Wiki",
    "WIKI_PATH": "/home/ubuntu/wiki"
}

This file must be in the current directory you launch Realms-wiki from, or else globally under /etc/ as per the docs.

If it can't find this file, it will use the defaults defined in __init__.py, which (by default) will create a new wiki under /tmp/wiki/.

nzuhdi commented 7 years ago

it totally works! thank you again for your insights @ctaperts @dereks