Skip to content

Commit

Permalink
Use .ini to minimize startup options
Browse files Browse the repository at this point in the history
  • Loading branch information
rcarmo committed Apr 4, 2016
1 parent 5c25662 commit 9f0e050
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
3 changes: 3 additions & 0 deletions INSTALL.md
Expand Up @@ -173,6 +173,9 @@ sudo systemctl disable uwsgi
sudo cp /tmp/uwsgi-piku.service /etc/systemd/system/
sudo systemctl enable uwsgi-piku
sudo systemctl start uwsgi-piku

# check it's running
sudo systemctl status uwsgi-piku.service
```
**Important Note:** Make sure you run `piku.py setup` as outlined above before starting the service.
Expand Down
24 changes: 22 additions & 2 deletions piku.py
Expand Up @@ -4,6 +4,7 @@
from click import argument, command, group, option, secho as echo
from collections import defaultdict, deque
from glob import glob
from multiprocessing import cpu_count
from os.path import abspath, basename, dirname, exists, getmtime, join, realpath, splitext
from subprocess import call, check_output
from time import sleep
Expand All @@ -19,6 +20,7 @@
UWSGI_AVAILABLE = abspath(join(PIKU_ROOT, "uwsgi-available"))
UWSGI_ENABLED = abspath(join(PIKU_ROOT, "uwsgi-enabled"))
UWSGI_ROOT = abspath(join(PIKU_ROOT, "uwsgi"))
UWSGI_LOG_MAXSIZE = '1048576'


# === Utility functions ===
Expand Down Expand Up @@ -246,7 +248,7 @@ def spawn_worker(app, kind, command, env, ordinal=1):
('processes', '1'),
('procname-prefix', '%s:%s:' % (app, kind)),
('enable-threads', 'true'),
('log-maxsize', '1048576'),
('log-maxsize', UWSGI_LOG_MAXSIZE),
('logto', '%s.%d.log' % (join(LOG_ROOT, app, kind), ordinal)),
('log-backupname', '%s.%d.log.old' % (join(LOG_ROOT, app, kind), ordinal)),
]
Expand Down Expand Up @@ -578,12 +580,30 @@ def deploy_app(app, settings):

@piku.command("setup")
def init_paths():
"""Initialize paths"""
"""Initialize environment"""

# Create required paths
for p in [APP_ROOT, GIT_ROOT, ENV_ROOT, UWSGI_ROOT, UWSGI_AVAILABLE, UWSGI_ENABLED, LOG_ROOT]:
if not exists(p):
echo("Creating '%s'." % p, fg='green')
os.makedirs(p)

# Set up the uWSGI emperor config
settings = [
('chdir', UWSGI_ROOT),
('emperor', UWSGI_ENABLED),
('log-maxsize', UWSGI_LOG_MAXSIZE),
('logto', join(UWSGI_ROOT, 'uwsgi.log')),
('log-backupname', join(UWSGI_ROOT, 'uwsgi.old.log')),
('socket', join(UWSGI_ROOT, 'uwsgi.sock')),
('enable-threads', 'true'),
('threads', '%d' % (cpu_count() * 2)),
]
with open(join(UWSGI_ROOT,'uwsgi.ini'), 'w') as h:
h.write('[uwsgi]\n')
for k, v in settings:
h.write("%s = %s\n" % (k, v))

# mark this script as executable (in case we were invoked via interpreter)
if not(os.stat(realpath(__file__)).st_mode & stat.S_IXUSR):
echo("Setting '%s' as executable." % this_script, fg='yellow')
Expand Down
9 changes: 3 additions & 6 deletions uwsgi-piku.dist
Expand Up @@ -57,12 +57,9 @@ do_start()
local PIDFILE=$RUN/$VERSION.pid
set -o noglob
local START_OPTS=" \
--chdir $PIKU_ROOT \
--emperor $ENABLED_CONFIGS_DIR \
--pidfile $PIDFILE \
--daemonize $RUN/$VERSION-emperor.log \
--enable-threads
--threads $THREADS"
--ini $RUN/uwsgi.ini \
--daemonize $RUN/uwsgi.log \
--pidfile $PIDFILE"
if do_pid_check $PIDFILE; then
sudo -u $OWNER -i $VERSION $DAEMON_OPTS $START_OPTS
else
Expand Down
2 changes: 1 addition & 1 deletion uwsgi-piku.service
Expand Up @@ -3,7 +3,7 @@ Description=Piku uWSGI Emperor
After=syslog.target

[Service]
ExecStart=/usr/local/bin/uwsgi-piku --chdir /home/piku/.piku --emperor /home/piku/.piku/uwsgi-enabled --enable-threads --threads 4 --logto=/home/piku/.piku/uwsgi/uwsgi.log --socket=/home/piku/.piku/uwsgi/uwsgi.sock
ExecStart=/usr/local/bin/uwsgi-piku --ini /home/piku/.piku/uwsgi/uwsgi.ini
User=piku
Group=www-data
RuntimeDirectory=/home/piku/.piku/uwsgi
Expand Down

0 comments on commit 9f0e050

Please sign in to comment.