-1

I'm working on a SaaS application where each customer runs its own version of the application. All the application instances currently run on a single server. This works quite well for us (we need less resources in total). The application doesn't use a lot of resources, so even a small VPS would be overkill (and more expensive).

Adding a new customer is currently quite a bit of work:

  • Create a user that is allowed to ssh
  • Create a new MySQL database and user
  • Create a virtual host for the application
  • Log in with the new user, do a git checkout of the application (in the right location)
  • Create tables in the new database, and add some init data
  • Add some cron jobs
  • Create a first user that can log in
  • Add this new instance to capistrano

What would be the best way to automate these tasks? Are the applications that can (given proper configuration) do this? Ideally this should be usable for a sales-person (so something web-based).

I could write a (bash) script that does most of these tasks, and then maybe add a small web-based wrapper where someone could provider the domain/default user information. Of course, this would also require a delete-script, since some customers will eventually leave, which means that you need a list of all existing customers/instances.

Intru
  • 101
  • 2

2 Answers2

2

This is, in fact, your job as a system administrator. Script all the things that are repetitive so that you can work on other things that need to be done or fixed.

If you're not confident in your scripting skills yet, you should have a test environment similar to your production where you can test out your scripts in an environment that won't cost you money and customers if you break it.

Magellan
  • 4,451
  • 3
  • 30
  • 53
0

My answer would depend on how many new customers you are expecting. If "every once in a while" you add a new customer - I would create a checklist for all of your above procedures and follow it carefully each time a new customer was added. If adding new customers is going to be done several times per day - or on many servers, then I would automate it.

My rule of thumb for systems administration: It is difficult to be too anal retentive, so make backups of every file you touch while adding a customer...

1.) Script something using useradd and command line parameters to make the user - being sure to make "600 root:root" copies of /etc/passwd and /etc/shadow (if local users) before issuing the useradd command. 2.) mkdir /etc/ssh.date +%Y%m%d 3.) cp /etc/ssh/* /etc/ssh.date +%Y%m%d 4.) awk, sed, sshkeygen (or whatever) to make the ssh keys and add the user 5.) bash script that takes command line parameters to create the SQL shots to create a database. ...blah blah blah

You get my reasoning...final step - create a "super script" that ties all of the steps together.

Hmm...the "web" aspect...unless you have some pretty good firewalls and security up and running....I would not create a web page to add the customer. I am sure you have thought of this...and how you proceed is up to you, but my thinking is that you are saying you want a web page that can execute scripts as root on a box. You have to be root to add the user. Maybe you can do it, but I would not trust myself to create a page that some user could willy nilly enter data into forms and have it execute something as root. I can sanitize OK...and I can follow sanitizing recipes OK...but, I do not trust my skills at "hacking" enough to test my own app that has root level commands...sorry, I am a wimp I guess :-)