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

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.

Related

How to automigrate when needed in loopback 3?

I created an automigrate script under /bin in my loopback app and added its path in the package.json file so that I can run this script to automigrate whenever I want from the terminal.
I also have a boot script "createUsers.js" which creates some default users in a model. The problem is, whenever I run this script it calls the boot script and it tries to create the users while automigration is still not finished, resulting in a failed automigration. I don't understand why the boot scripts are called when I only run automigrate script specifically. I could call automigrate in the boot scripts and wrap the createUsers.js code in its callback (as shown here), but that would automigrate every time the app is started which is undesirable since the data is lost on automigration. Where should I call automigrate() so that it can be called whenever required? Any help is greatly appreciated.
What I normally do, is create a script called util.js inside boot
util.js
class util{
static _automigrate(){
//Whatever you need to do
}
}
module.exports = function (server) {
global.util = util;
};
This way your script is available across the entire application. And you can call it whenever you need to.
You could call it with
util._automigrate();
I normally use this pattern to store all my input validations etc since I might need those across different models.

jenkins: setting root url via Groovy API

I'm trying to update Jenkins' root URL via the Groovy API, so I can script the deployment of a Jenkins master without manual input (aside: why is a tool as popular with the build/devops/automation community as Jenkins so resistant to automation?)
Based on this documentation, I believe I should be able to update the URL using the following script in the Script Console.
import jenkins.model.JenkinsLocationConfiguration
jlc = new jenkins.model.JenkinsLocationConfiguration()
jlc.setUrl("http://jenkins.my-org.com:8080/")
println(jlc.getUrl())
Briefly, this instantiates a JenkinsLocationConfiguration object; calls the setter setUrl with the desired value, http://jenkins.my-org.com:8080/; and prints out the new URL to confirm that it has changed.
The println statement prints what I expect it to, but following this, the value visible through the web interface at "Manage Jenkins" -> "Configure System" -> "Jenkins URL" has not updated as I expected.
I'm concerned that the value hasn't been update properly by Jenkins, which might lead to problems when communicating with external APIs.
Is this a valid way to fix the Jenkins root URL? If not, what is? Otherwise, why isn't the change being reflected in the config page?
You are creating a new JenkinsLocationConfiguration object, and updating the new one, not the existing one being used
use
jlc = JenkinsLocationConfiguration.get()
// ...
jlc.save()
to get the one from the global jenkins configuration, update it and save the config descriptor back.
see : https://github.com/jenkinsci/jenkins/blob/master/core/src/main/java/jenkins/model/JenkinsLocationConfiguration.java

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!

How to listen to svn commit event on working directory on developer/client machine?

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
}

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