How to shutdown or restart a server using node red


You can import the code below;


[
    {
        "id": "d9e15954.1730b8",
        "type": "exec",
        "z": "fe1c6c2b.68e79",
        "command": "",
        "addpay": true,
        "append": "",
        "useSpawn": "true",
        "timer": "",
        "oldrc": false,
        "name": "System Command",
        "x": 770,
        "y": 100,
        "wires": [
            [],
            [],
            []
        ]
    },
    {
        "id": "f632c378.a9b95",
        "type": "inject",
        "z": "fe1c6c2b.68e79",
        "name": "Restart Computer",
        "topic": "",
        "payload": "C:\\Users\\akirankaya\\Desktop\\nr\\restart-node-red",
        "payloadType": "str",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 330,
        "y": 100,
        "wires": [
            [
                "829d155b.1a9428"
            ]
        ]
    },
    {
        "id": "829d155b.1a9428",
        "type": "function",
        "z": "fe1c6c2b.68e79",
        "name": "Restart",
        "func": "msg.payload=\"shutdown /r\";\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 560,
        "y": 100,
        "wires": [
            [
                "d9e15954.1730b8"
            ]
        ]
    },
    {
        "id": "f5703503.ca4268",
        "type": "http in",
        "z": "fe1c6c2b.68e79",
        "name": "",
        "url": "restart",
        "method": "get",
        "upload": false,
        "swaggerDoc": "",
        "x": 310,
        "y": 180,
        "wires": [
            [
                "8a7104ee.96cf78",
                "829d155b.1a9428"
            ]
        ]
    },
    {
        "id": "9bc75e50.18d2f",
        "type": "http in",
        "z": "fe1c6c2b.68e79",
        "name": "",
        "url": "shutdown",
        "method": "get",
        "upload": false,
        "swaggerDoc": "",
        "x": 310,
        "y": 440,
        "wires": [
            [
                "715f87e0.e9b308"
            ]
        ]
    },
    {
        "id": "7bb61aa.8c1b3e4",
        "type": "debug",
        "z": "fe1c6c2b.68e79",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "x": 820,
        "y": 180,
        "wires": []
    },
    {
        "id": "6e2210af.3b294",
        "type": "debug",
        "z": "fe1c6c2b.68e79",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "x": 830,
        "y": 440,
        "wires": []
    },
    {
        "id": "8a7104ee.96cf78",
        "type": "function",
        "z": "fe1c6c2b.68e79",
        "name": "set payload as restart",
        "func": "msg.payload=\"restart\";\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 570,
        "y": 180,
        "wires": [
            [
                "7bb61aa.8c1b3e4"
            ]
        ]
    },
    {
        "id": "715f87e0.e9b308",
        "type": "function",
        "z": "fe1c6c2b.68e79",
        "name": "set payload as shutdown",
        "func": "msg.payload=\"shutdown\";\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 570,
        "y": 440,
        "wires": [
            [
                "6e2210af.3b294"
            ]
        ]
    },
    {
        "id": "f623b461.c9afa8",
        "type": "exec",
        "z": "fe1c6c2b.68e79",
        "command": "",
        "addpay": true,
        "append": "",
        "useSpawn": "true",
        "timer": "",
        "oldrc": false,
        "name": "System Command",
        "x": 750,
        "y": 360,
        "wires": [
            [],
            [],
            []
        ]
    },
    {
        "id": "7b9babbd.6a09a4",
        "type": "inject",
        "z": "fe1c6c2b.68e79",
        "name": "Shutdown Computer",
        "topic": "",
        "payload": "C:\\Users\\akirankaya\\Desktop\\nr\\restart-node-red",
        "payloadType": "str",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 320,
        "y": 360,
        "wires": [
            [
                "c4ddd093.06354"
            ]
        ]
    },
    {
        "id": "c4ddd093.06354",
        "type": "function",
        "z": "fe1c6c2b.68e79",
        "name": "Shutdown",
        "func": "msg.payload=\"shutdown /s\";\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 520,
        "y": 360,
        "wires": [
            [
                "f623b461.c9afa8"
            ]
        ]
    },
    {
        "id": "72fbc492.2373a8",
        "type": "inject",
        "z": "fe1c6c2b.68e79",
        "name": "",
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "repeat": "1",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 270,
        "y": 560,
        "wires": [
            [
                "14e548a9.1a73d3"
            ]
        ]
    },
    {
        "id": "14e548a9.1a73d3",
        "type": "debug",
        "z": "fe1c6c2b.68e79",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "x": 510,
        "y": 560,
        "wires": []
    },
    {
        "id": "b98d1e00.43df7",
        "type": "comment",
        "z": "fe1c6c2b.68e79",
        "name": "http://127.0.0.1:1880/restart",
        "info": "",
        "x": 320,
        "y": 260,
        "wires": []
    },
    {
        "id": "9d0096d4.52a2f8",
        "type": "comment",
        "z": "fe1c6c2b.68e79",
        "name": "http://127.0.0.1:1880/shutdown",
        "info": "",
        "x": 310,
        "y": 500,
        "wires": []
    }
]

Leave a Comment