How to listen to svn commit event on working directory on developer/client machine? - node.js

I need to write a node.js program that will somehow get triggered anytime a developer checks in code into svn. This will update a file in the working directory. The developers work on Mac OS X and Windows. The program needs to run on both machines.
Is there a way I can somehow listen to svn client's commit?
Are there any sdk for svn that allows plugin/extension?
Will watching .svn hidden directory (that svn creates for its own use) for changes do it? if so, how can I know by looking at this directory that a file was committed?
At first I thought hooks might be the way to go but hooks are run on the machine that host's svn and they are mostly for admin tasks such as sending email alerts or kicking off builds

First you need to understand that there is no way to know whether an update has occurred on the server without connecting to the server. Hence you cannot do it simply by looking at the local folders because that is not how svn works.
A workaround to achieve what you want would be the following. On the server, write a "post-commit" hook that takes a counter from a text file, increments it, and writes it back. Deposit this text file somewhere where your clients can download it. I'm going to assume this will be on "http://www.example.com/commit-id.txt". Then, on the clients, use a shell script that monitors this text file for changes and executes the desired action. Using windows powershell, for instance, this could work as follows. For Mac you need to use a different shell but I'm sure this script could be easily ported.
function get-current-commit-id {
trap [Exception] {
# Make sure the script doesn't freak out when server is down or connection
$commitid
return
}
# The rand.next() ensures by brute force that the text file is not cached
[int] $clnt.DownloadString("http://www.example.com/commit-id.txt?q="+$rand.next())
}
$clnt = new-object System.Net.WebClient
$commitid = get-current-commit-id
while( 1 ){
$commitidnew = get-current-commit-id
if( $commitidnew -ne $rsid ){
Write-Output "Commit occured on server"
### execute desired action here
### perhaps you'll also want to run "svn up"
$commitid = $rsidnew
}
### check for new update every 10 seconds
sleep 10
}

Related

How do you restart a service after you submit an openwrt page?

I'm trying to write a page in openwrt that changes the configuration of an application I wrote and then restarts a service. For now, I'm using a simple "service" that writes to a log to see that once I click "save and apply" on the page, it writes the time to this text file. However, I think I'm missing something. I added a section to the /etc/config/ucitrack like this
config app
option init gps
although, to be honest, I just did that because all the other service apps in there did this. My service init script looks like this
#!/bin/sh /etc/rc.common
START=10
start() {
echo Start
echo 'date' > ~/test.txt
}
stop(){
echo Stop
}
reload_service() {
echo "Restarting"
stop
start
}
The page that I wrote (using cbi) already reads the configuration file and then applies the changes. I'm guessing this will also call the init portion of the /etc/config/ucitrack, but I could be wrong. What am I missing here exactly?
So it turns out I was doing this right, except for the path of the file. I shouldn't have used the home "~" shortcut, since I suppose you can't really be sure what user the system will run the script as. When I changed the path to the full one "/root/test.txt", it works just fine.

fabric -- cant run commands after user is switched

I have been recently introduced to fabric and trying to approach the following:
access remote host
su root
perform a command, for example change password for multiple users
done!
Please note that I cant use sudo, nor connect directly to the remote host using root. The commands I need to perform can only be performed if I explicitly change user to root.
I was able to approach the main concept of getting to the remote host and play with some commands, using fabric, but the problem im having is that once I switch to root "su root" I cant perform the rest of the commands unless I exit.
example of what im trying to approach:
def mytask():
with settings(user="root"):
run('whoami')
run('echo "TEST using root user"')
run('echo "ITS WORKING!!!"')
or something like this
def mytask():
run ('su root')
run ('passwd testUser')
In both cases once I enter the root password nothing would get executed, I would get the remote command line back, unless I exit back to the original user. I have seen few suggestions about using "fexpect" for prompts but not sure if that would make a difference.
I'm developing on a Linux environment.
You have to use fexpect and fexpect run command
from ilogue import fexpect
prompt = ['Password', 'mypassword'] # ('prompt', 'answer') Case sensitive
def test():
with fexpect.expecting(prompt):
fexpect.local("su -")

no such repository on migrating to a new cvs server

I am moving from cvsserv1 to cvsserv2. I am running cvs1.11 on current server on RHEL. I am moving to cvsserv2 which is running ubuntu 12. This is my procedure to port cvs:
zip entire repository on cvsserv1
move zip to cvsserv2
extract zip to /home/users on cvsserv2.
setup cvs service on cvsserve2 in pserver mode.
initialize repository on /home/users/cvsroot by using "cvs -d /home/users/cvsroot init"
connect to cvsserv2 from eclipse using anonymous access to do a test checkout.
I am failing on step6 with the error message "no such repository". What am I doing wrong?
UPDATE
I tried to change the above method, by adopting this http://mazanatti.info/archives/67/ and I was partially successful.
At step 3 (as in that link), after initializing repo on cvsserv2, I copied my repository to /var/lib/cvsd/project1, overwriting CVSROOT folder. Now, after finishing all steps, I was able to connect successfully. However, when I try to check out, I don't see any branches. When I tried to Refresh Tags, I receive the following error:
What is going wrong?
Ok. I figured this one out. For those who might encounter this issue again, here's how I managed to identify and fix it:
Eclipse's cvs client sucks - it doesn't give you much information. (I could be wrong, may be it writes some debug info to eclipse log file - still, I think that error message should have been more descriptive). Anyway, I obtained TortoiseCVS and attempted a checkout and it failed with an error message on the lines of -"failed to obtain dir lock in repository `/home/cvsroot/foo'. This is not the exact message, but it was something like that.
So, all I had to do, was go into my cvs dump from cvsserv1, look for references to that directory (which is a valid path on cvsserv1 but not cvsserv2). I found a reference to it in config file under CVSROOT folder. It was assigned to a property called LockDir. This property was referring to a /home/cvsroot/foo on the older server as a lock directory. All I had to do was comment out this property and restart cvsd. Everything started working just fine after this!

Temporary File Download

Is there a service that creates basically a one-time download of a file, preferably something I can use from NodeJS?
I've done some research on FilePicker, and haven't found anything about regenerating the link it gives you for a file. There may be a way to do this with NodeJS, but I'm using Meteor at the same time so many Node things probably will conflict.
You could build it with meteor. Using meteor-router with meteorite & use server side routing to deliver the files.
You need a collection to keep track of downloaded files:
Server JS
var downloads = new Meteor.Collection("downloads");
//create a link
downloads.insert({url:"/mydownload.zip",downloaded:false})
Meteor.Router.add('/file/:id', 'GET', function(id) {
download = downloads.findOne(id);
if( download) {
if(dowload.downloaded) {
this.response.send("You've already downloaded me")
}
else
{
//I guess you could just redirect or stream the file for an extra layer of surety
this.response.redirect(download.url);
}
}
});
On the client you can use /files/{{_id}} with _id of the file from downloads the person has as the link
My recommendation would also be to add custom server-side logic to count # of uploads (or just flag a file as downloaded/not downloaded) and respond accordingly. The closest you could do with Filepicker.io would be using the security policies to restrict downloading the file to a specific time interval.
in addition to using the router package
in Meteor.startup you can add
var require = __meteor_bootstrap__.require;
fs = require( 'fs' );
the fs variable should be declared on the server only. the fs package is used by Meteor and does not need to be added separately.
once you have done this, you can create files with Meteor.uuid() as their name which makes them unique and very difficult to guess. It is also possible to delete the file after a certain amount of time by using Meteor.setTimeout
the question is: where do the files to be downloaded come from?
Solution using Heroku Cloud and NodeJS Meteor Hooks
Heroku in particular is actually great for temporary file download links: they offer a "temporary scratchpad" filesystem that is reset every time the program restarts, and each running Node server cannot see the files other instances have created.
Each dyno gets its own ephemeral filesystem, with a fresh copy of the
most recently deployed code. During the dyno’s lifetime its running
processes can use the filesystem as a temporary scratchpad, but no
files that are written are visible to processes in any other dyno and
any files written will be discarded the moment the dyno is stopped or
restarted.
Taken from the Heroku documentation: https://devcenter.heroku.com/articles/dynos#ephemeral-filesystem
Thus, any files written to the "filesystem" will be temporary.
This allows for a very easy solution to this problem: you can simply use NodeJS filesystem manipulation to create temporary files on the server, serve them once (or for a limited time), and then remove them so they cannot be downloaded again.
This in combination with something like $.download() will make a seamless experience which in turn prevents unauthorized downloads.

Update deployment via linux script in weblogic

What is the script to update deployment ( from GUI, we can do this update by unlock & save changes ) in linux. Is it possible to do this ? If not what is script to redeploy ?
As Kevin pointed out, WLST is the way to go. You should probably craft a script (named wlDeploy.py, for instance), with content like follows (import clauses were omitted for the sake of simplicity):
current_app_name = '[your current deployed app name]'
new_app_name = '[your new app name]'
target_name = '[WL managed server name (or AdminServer)]'
connect([username],[pwd],'t3://[admin server hostname/IP address]:[PORT]')
stopApplication(current_app_name)
undeploy(current_app_name, timeout=60000);
war_path = '[path to war file]'
deploy(appName=new_app_name, path=war_path, targets=target_name);
And call it via something like:
./wlst.sh wlDeploy.py
Of course you can add parameters to your script, and a lot of logic which is relevant to your deployment. This is entirely up to you. The example above, though, should help you getting started.
In WebLogic you can use wlst to perform administrative tasks like managing deployments. If you google weblogic wlst, you will receive tons of information. wlst runs on the python language.
Assuming you are using weblogic 10 you can also "Record" your actions. This will save the actions into a python script which you can "replay" (execute) later.

Resources