Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic Win32 support #64

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions README.windows.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Installation for Windows
- Install git and Unix tools. You need sh.exe to start the scripts.
- Edit the config.json and add "ps_monitor_cmd" key to get process status:
```
"ps_monitor_cmd": "cscript.exe bin\\win_ps.wsf //nologo"
```
- Edit setup.json and change the "common" to copy instead of symbolic link.
```
"common": [
[ "copyCompress", "node_modules/jquery/dist/jquery.min.js", "htdocs/js/external/" ],
[ "copyCompress", "node_modules/jquery/dist/jquery.min.map", "htdocs/js/external/" ],
[ "copyCompress", "node_modules/zxcvbn/dist/zxcvbn.js", "htdocs/js/external/" ],
[ "copyCompress", "node_modules/zxcvbn/dist/zxcvbn.js.map", "htdocs/js/external/" ],
[ "copyCompress", "node_modules/chart.js/dist/Chart.min.js", "htdocs/js/external/" ],

[ "copyCompress", "node_modules/font-awesome/css/font-awesome.min.css", "htdocs/css/" ],
[ "copyCompress", "node_modules/font-awesome/css/font-awesome.css.map", "htdocs/css/" ],
[ "copyFiles", "node_modules/font-awesome/fonts/*", "htdocs/fonts/" ],

[ "copyCompress", "node_modules/mdi/css/materialdesignicons.min.css", "htdocs/css/" ],
[ "copyCompress", "node_modules/mdi/css/materialdesignicons.min.css.map", "htdocs/css/" ],
[ "copyFiles", "node_modules/mdi/fonts/*", "htdocs/fonts/" ],

[ "copyCompress", "node_modules/moment/min/moment.min.js", "htdocs/js/external/" ],
[ "copyCompress", "node_modules/moment-timezone/builds/moment-timezone-with-data.min.js", "htdocs/js/external/" ],
[ "copyCompress", "node_modules/jstimezonedetect/dist/jstz.min.js", "htdocs/js/external/" ],

[ "copyFiles", "node_modules/pixl-webapp/js/*", "htdocs/js/common" ],
[ "copyFile", "node_modules/pixl-webapp/css/base.css", "htdocs/css/" ],
[ "copyFiles", "node_modules/pixl-webapp/fonts/*", "htdocs/fonts/" ],

[ "chmodFiles", "755", "bin/*" ]
]
```
- Create the npm installation by going to command line of source files:

```
cd /d my_cronicle_dir
npm install
node bin/build.js dist
sh bin/control.sh setup
sh bin/control.sh start
```

## Gotchas
- I've tested windows changes for simple events. If you have user switching or detached tasks, they probably will not work.
- The gid and uid returned from Process is hard-coded as windows doesn't support this.
3 changes: 3 additions & 0 deletions bin/control.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ NAME="Cronicle Daemon"
#
# home directory
SCRIPT=`perl -MCwd -le 'print Cwd::abs_path(shift)' "$0"`
if [ $? -ne 0 ]; then
SCRIPT=$(cd "$(dirname "$0")"; pwd)
fi
DIR=`dirname $SCRIPT`
HOMEDIR=`dirname $DIR`
cd $HOMEDIR
Expand Down
3 changes: 3 additions & 0 deletions bin/debug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
# Add --master to force instant master on startup

SCRIPT=`perl -MCwd -le 'print Cwd::abs_path(shift)' "$0"`
if [ $? -ne 0 ]; then
SCRIPT=$(cd "$(dirname "$0")"; pwd)
fi
DIR=`dirname $SCRIPT`
HOMEDIR=`dirname $DIR`

Expand Down
9 changes: 7 additions & 2 deletions bin/shell-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@ process.stdout.setEncoding('utf8');
var stream = new JSONStream( process.stdin, process.stdout );
stream.on('json', function(job) {
// got job from parent
var script_file = path.join( os.tmpdir(), 'cronicle-script-temp-' + job.id + '.sh' );
var iswin = process.platform === "win32";
var script_file = path.join( os.tmpdir(), 'cronicle-script-temp-' + job.id + (iswin ? '.bat' : '.sh') );
fs.writeFileSync( script_file, job.params.script, { mode: "775" } );

var child = cp.spawn( script_file, [], {
var child = null;
if(!iswin) child = cp.spawn( script_file, [], {
stdio: ['pipe', 'pipe', 'pipe']
} );
else child = cp.spawn( "cmd.exe", ["/c", script_file], {
stdio: ['pipe', 'pipe', 'pipe']
} );

Expand Down
24 changes: 24 additions & 0 deletions bin/win_ps.wsf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<job>
<script language="JScript">
var strComputer = ".";
var wmi = GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\" + strComputer + "\\root\\cimv2");
var items = wmi.ExecQuery("SELECT ParentProcessId,ProcessId,WorkingSetSize FROM Win32_Process");
var permItems = wmi.ExecQuery("SELECT IDProcess,PercentProcessorTime FROM win32_perfformatteddata_perfproc_process");

var pct = {};
for (var e=new Enumerator(permItems); !e.atEnd(); e.moveNext()) {
pct[e.item().IDProcess] = {PercentProcessorTime: e.item().PercentProcessorTime};
}
permItems = null;

WScript.Echo("PPID\tPID\t%CPU\tRSS");
for (var e=new Enumerator(items); !e.atEnd(); e.moveNext()) {
var s = e.item();
//WorkingSetSize = Amount of memory in bytes that a process needs to execute efficiently—for an operating system that uses page-based memory management
//PrivateBytes = Current value, in bytes, that this process has allocated that cannot be shared with other processes.
var perf = pct[s.ProcessId] || {}
WScript.Echo(s.ParentProcessId + "\t" + s.ProcessId + "\t" + perf["PercentProcessorTime"] + "\t" + parseInt(s.WorkingSetSize/1000));
}
items = null;
</script>
</job>
5 changes: 4 additions & 1 deletion lib/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,10 @@ module.exports = Class.create({

// spawn child
try {
child = cp.spawn( child_cmd, child_args, child_opts );
//Do not pass child_opts to spawn in windows, you will get
//error: "Operation not supported on socket (spawn ENOTSUP)"
child = process.platform === "win32" ? cp.spawn( "node.exe", [child_cmd.concat(child_args)], {stdio: child_opts.stdio} )
: cp.spawn( child_cmd, child_args, child_opts );
}
catch (err) {
if (worker.log_fd) { fs.closeSync(worker.log_fd); worker.log_fd = null; }
Expand Down
4 changes: 4 additions & 0 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@ var server = new PixlServer({
server.startup( function() {
// server startup complete
process.title = server.__name + ' Server';

//Windows support
if(!process.getgid) process.getgid = function() { return 100;};
if(!process.getuid) process.getuid = function() { return -1; }
} );